Connect to virtual Robot via QiMessaging JavaScrip

2019-08-29 03: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条回答
贪生不怕死
2楼-- · 2019-08-29 03:55

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).

[...]

查看更多
登录 后发表回答