Pepper naoqi 2.5 onConsoleMessage null
Pepper naoqi 2.5 onConsoleMessage null
我正在尝试使用 onConsoleMessage 事件的回调在 python 中打印来自 Web 控制台的消息。 Pepper(编辑:版本 1.6)是 运行 naoqi 2.5.5.5。我修改了 executeJS 示例作为测试。问题是我一直在回调中为消息获取空值。是不是已经在新版naoqi中修复的bug了?我查看了发行说明,但没有找到任何内容。
这是我使用的代码:
#! /usr/bin/env python
# -*- encoding: UTF-8 -*-
"""Example: Use executeJS Method"""
import qi
import argparse
import sys
import time
import signal
def signal_handler(signal, frame):
print('Bye!')
sys.exit(0)
def main(session):
"""
This example uses the executeJS method.
To Test ALTabletService, you need to run the script ON the robot.
"""
# Get the service ALTabletService.
try:
tabletService = session.service("ALTabletService")
# Display a local web page located in boot-config/html folder
# The ip of the robot from the tablet is 198.18.0.1
tabletService.showWebview("http://198.18.0.1/apps/boot-config/preloading_dialog.html")
time.sleep(3)
# Javascript script for displaying a prompt
# ALTabletBinding is a javascript binding inject in the web page displayed on the tablet
script = """
console.log('A test message');
"""
# Don't forget to disconnect the signal at the end
signalID = 0
# function called when the signal onJSEvent is triggered
# by the javascript function ALTabletBinding.raiseEvent(name)
def callback(message):
print "[callback] received : ", message
# attach the callback function to onJSEvent signal
signalID = tabletService.onConsoleMessage.connect(callback)
# inject and execute the javascript in the current web page displayed
tabletService.executeJS(script)
print("Waiting for Ctrl+C to disconnect")
signal.pause()
except Exception, e:
print "Error was: ", e
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default="127.0.0.1",
help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
parser.add_argument("--port", type=int, default=9559,
help="Naoqi port number")
args = parser.parse_args()
session = qi.Session()
try:
session.connect("tcp://" + args.ip + ":" + str(args.port))
except RuntimeError:
print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
"Please check your script arguments. Run with -h option for help.")
sys.exit(1)
main(session)
输出:
python onConsoleMessage.py --ip=192.168.1.20
[W] 1515665783.618190 30615 qi.path.sdklayout: No Application was created, trying to deduce paths
Waiting for Ctrl+C to disconnect
[callback] received : null
有人遇到同样的问题吗?
谢谢
我有同样的问题。您可以通过在机器人上打开两个 ssh 控制台并在第一个执行
qicli watch ALTabletService.onConsoleMessage
第二次
qicli call ALTabletService.showWebview
qicli call ALTabletService.executeJS "console.log('hello')"
... 而不是 "hello",您将看到 "null" 出现在您的第一个控制台中。
但是 - 如果您的目标是有效地测试您的网页,我通常做的就是在我的计算机上打开该页面并使用 chrome 控制台(您可以将 chrome 设置为就好像页面是大小合适的平板电脑一样,1280x800);您可以在将页面连接到 Pepper 的同时执行此操作,就像在她的平板电脑上一样,using the method described here。这对于 99% 的情况已经足够了;剩下的 1% 是 Pepper 的平板电脑实际上与 Chrome.
不同的东西
我正在尝试使用 onConsoleMessage 事件的回调在 python 中打印来自 Web 控制台的消息。 Pepper(编辑:版本 1.6)是 运行 naoqi 2.5.5.5。我修改了 executeJS 示例作为测试。问题是我一直在回调中为消息获取空值。是不是已经在新版naoqi中修复的bug了?我查看了发行说明,但没有找到任何内容。
这是我使用的代码:
#! /usr/bin/env python
# -*- encoding: UTF-8 -*-
"""Example: Use executeJS Method"""
import qi
import argparse
import sys
import time
import signal
def signal_handler(signal, frame):
print('Bye!')
sys.exit(0)
def main(session):
"""
This example uses the executeJS method.
To Test ALTabletService, you need to run the script ON the robot.
"""
# Get the service ALTabletService.
try:
tabletService = session.service("ALTabletService")
# Display a local web page located in boot-config/html folder
# The ip of the robot from the tablet is 198.18.0.1
tabletService.showWebview("http://198.18.0.1/apps/boot-config/preloading_dialog.html")
time.sleep(3)
# Javascript script for displaying a prompt
# ALTabletBinding is a javascript binding inject in the web page displayed on the tablet
script = """
console.log('A test message');
"""
# Don't forget to disconnect the signal at the end
signalID = 0
# function called when the signal onJSEvent is triggered
# by the javascript function ALTabletBinding.raiseEvent(name)
def callback(message):
print "[callback] received : ", message
# attach the callback function to onJSEvent signal
signalID = tabletService.onConsoleMessage.connect(callback)
# inject and execute the javascript in the current web page displayed
tabletService.executeJS(script)
print("Waiting for Ctrl+C to disconnect")
signal.pause()
except Exception, e:
print "Error was: ", e
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default="127.0.0.1",
help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
parser.add_argument("--port", type=int, default=9559,
help="Naoqi port number")
args = parser.parse_args()
session = qi.Session()
try:
session.connect("tcp://" + args.ip + ":" + str(args.port))
except RuntimeError:
print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
"Please check your script arguments. Run with -h option for help.")
sys.exit(1)
main(session)
输出:
python onConsoleMessage.py --ip=192.168.1.20
[W] 1515665783.618190 30615 qi.path.sdklayout: No Application was created, trying to deduce paths
Waiting for Ctrl+C to disconnect
[callback] received : null
有人遇到同样的问题吗?
谢谢
我有同样的问题。您可以通过在机器人上打开两个 ssh 控制台并在第一个执行
qicli watch ALTabletService.onConsoleMessage
第二次
qicli call ALTabletService.showWebview
qicli call ALTabletService.executeJS "console.log('hello')"
... 而不是 "hello",您将看到 "null" 出现在您的第一个控制台中。
但是 - 如果您的目标是有效地测试您的网页,我通常做的就是在我的计算机上打开该页面并使用 chrome 控制台(您可以将 chrome 设置为就好像页面是大小合适的平板电脑一样,1280x800);您可以在将页面连接到 Pepper 的同时执行此操作,就像在她的平板电脑上一样,using the method described here。这对于 99% 的情况已经足够了;剩下的 1% 是 Pepper 的平板电脑实际上与 Chrome.
不同的东西