通过 QiMessaging 连接到虚拟机器人 JavaScript
Connect to virtual Robot via QiMessaging JavaScript
我想在本地测试我的 Javascript 应用程序。
因此我想在我的 JavaScript QiMessaging 应用程序与虚拟机器人之间建立连接。
以前有人做过吗?
这可能吗?
作为虚拟机器人,我在 windows 10 系统上尝试了 naoqi-bin.exe 和 opennao vm。
通过连接到虚拟机器人无法正常工作,它与真实机器人 (Pepper) 一起工作。
这是我的尝试:
qimessaging 1.0:
代码:
<!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>
结果:
浏览器控制台显示:
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:
代码:
<!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>
结果:
与 qimessaging 1.0 相同
机器人工具:
代码:
<!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>
结果:
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”.
所以我的解释是虚拟机器人没有提供所需的文件,或者我在这里遗漏了什么?
好的,我在 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).
[...]
我想在本地测试我的 Javascript 应用程序。
因此我想在我的 JavaScript QiMessaging 应用程序与虚拟机器人之间建立连接。
以前有人做过吗?
这可能吗?
作为虚拟机器人,我在 windows 10 系统上尝试了 naoqi-bin.exe 和 opennao vm。
通过连接到虚拟机器人无法正常工作,它与真实机器人 (Pepper) 一起工作。
这是我的尝试:
qimessaging 1.0:
代码:
<!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>
结果:
浏览器控制台显示:
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:
代码:
<!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>
结果:
与 qimessaging 1.0 相同
机器人工具:
代码:
<!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>
结果:
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”.
所以我的解释是虚拟机器人没有提供所需的文件,或者我在这里遗漏了什么?
好的,我在 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).
[...]