Connect to virtual Robot via QiMessaging JavaScript

倖福魔咒の 提交于 2019-12-13 03:43:06

问题


I would like to test my Javascript application locally.

Therefore i would like to establish a connection between my JavaScript Application with QiMessaging to a virtual robot.

Has anybody done this before?

Is this even possible?

As virtual robot I tried naoqi-bin.exe and opennao vm on my windows 10 system.

It works fine with a real Robot (Pepper) by connecting to a virtual robot didnt work.

Here are my attempts:


qimessaging 1.0:

code:

<!DOCTYPE html>
<html>    
<head>
    <meta charset="utf-8"/>
</head>    
<body>
<script src="libs/qimessaging/1.0/qimessaging.js"></script>
<script type="text/javascript">

var robot_address = '127.0.0.1'    

  var session = new QiSession(robot_address);
    session.socket().on('connect', function () {
  console.log('QiSession connected!');
  // now you can start using your QiSession
}).on('disconnect', function () {
  console.log('QiSession disconnected!');
});        
</script>
</body>    
</html>

result:

Broweser Console shows:

404 Not Found http://127.0.0.1/libs/qimessaging/1.0/socket.io/1/?t=1557305266224

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1/libs/qimessaging/1.0/socket.io/1/?t=1557305266224 Reson: Reason: CORS header 'Access-Control-Allow-Origin' missing


qimessaging 2.0:

code:

<!DOCTYPE html>
<html>    
<head>
    <meta charset="utf-8"/>
</head>    
<body>
<script src="libs/qi/2/qi.js"></script>
<script type="text/javascript">

    var robot_address = '127.0.0.1'

    QiSession(function (session) {
      console.log("connected!");
      // you can now use your QiSession
    }, function () {
      console.log("disconnected");
    },
      robot_address);
</script>
</body>
</html>

result:

same as with qimessaging 1.0


robotutils:

code:

<!DOCTYPE html>
<html>   
<head>
  <meta charset="utf-8"/>
</head>    
<body>
  <script src="js/robotutils.js"></script>
  <script type="text/javascript">
    RobotUtils.robotIp = "127.0.0.1"

    RobotUtils.onService(function (ALDialog) {
      console.log("Connected the service.")         
    }, function () {
      console.log("Failed to get the service.")
    })
  </script>
</body>   
</html>

result:

GET http://127.0.0.1/libs/qimessaging/2/qimessaging.js 404 Not Found

The script from “http://127.0.0.1/libs/qimessaging/2/qimessaging.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.

Loading failed for the with source “http://127.0.0.1/libs/qimessaging/2/qimessaging.js”.


So my interpretationis that the virtual robot does not serve the required files or am i missing something here?


回答1:


Ok i found the answer in a the aldebaran forum

[...]

Sorry, but qimessaging javascript won't work with a virtual robot, only with a real robot (on a real robot there's a server listening to a certain port for qimessaging js communication, there's no such server running for a virtual robot).

[...]



来源:https://stackoverflow.com/questions/56037157/connect-to-virtual-robot-via-qimessaging-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!