我有一个绑定到IOT Foundation(iotf)服务的Node-RED应用程序。我可以从设备接收事件并适当地处理它们。
但是,我现在有兴趣将命令发送回我的设备并遇到一些问题。设备上没有显示任何内容,但通过在节点中创建IOTF,我可以确认命令正在通过iotf。
我绝对可以使用纯python通过iotf获取命令,因为以下代码运行良好:
客户代码:
#!/usr/bin/python
import ibmiotf.device
from time import sleep
options = {
"org": "cgmncc",
"type": "table",
"id": "b827eb764b7a",
"auth-method": "token",
"auth-token": "redacted"
}
def myCommandCallback(cmd):
print('inside command callback')
print cmd
def main():
client = ibmiotf.device.Client(options)
client.connect()
client.commandCallback = myCommandCallback
while True:
sleep(1)
if __name__ == "__main__":
main()
申请代码:
#!/usr/bin/python
import ibmiotf.application
options = {
"org": "redacted",
"id": "python app",
"auth-method": "apikey",
"auth-key": "redacted",
"auth-token": "redacted"
}
try:
client = ibmiotf.application.Client(options)
client.connect()
client.publishCommand('table', 'b827eb764b7a', 'test')
client.disconnect()
except ibmiotf.ConnectionException as e:
print e
每当我运行应用程序代码时,我都会看到以下输出:
root@raspberrypi ~ # ./app.py
inside command callback
<ibmiotf.device.Command instance at 0x14e8490>
我有如下所示配置的Node-RED iotf输出节点,但是当我触发流时,命令回调函数不会触发!
我认为尝试使用时间戳触发器来触发命令或者我自己配置输出节点的方式可能有问题 - 任何建议或建议都会受到赞赏!
答案 0 :(得分:2)
检查命令是否到达IBM IoT Foundation的简单测试是 - 开发具有订阅命令的IoT App In节点的另一个流。我在这里附加了Node-RED流程
[
{
"id": "40560f8b.30693",
"type": "ibmiot in",
"authentication": "boundService",
"apiKey": "",
"inputType": "cmd",
"deviceId": "b827eb764b7a",
"applicationId": "",
"deviceType": "table",
"eventType": "",
"commandType": "test",
"format": "string",
"name": "IBM IoT App In",
"service": "registered",
"allDevices": false,
"allApplications": "",
"allDeviceTypes": false,
"allEvents": "",
"allCommands": false,
"allFormats": false,
"x": 268,
"y": 171,
"z": "6bd610b9.7b40a",
"wires": [
[
"2f9b9c00.8b7ba4"
]
]
},
{
"id": "2f9b9c00.8b7ba4",
"type": "debug",
"name": "",
"active": true,
"console": "false",
"complete": "false",
"x": 493,
"y": 195,
"z": "6bd610b9.7b40a",
"wires": []
}
]
&#13;
在工作区中会出现这种情况
添加此流后,您可以测试从同一工作区发布的设备命令 你能试试吗?由于您现在有2个调试节点,因此您应该能够看到两次相同的timetamp输出。我尝试了相同的流程,具有相同的细节(组织除外),它工作正常。
谢谢和问候 Amit M Mangalvedkar
答案 1 :(得分:1)
我尝试了以下代码
#!/usr/bin/python
import ibmiotf.device
from time import sleep
options = {
"org": "uguhsp",
"type": "iotsample-raspberry",
"id": "00aabbccde03",
"auth-method": "token",
"auth-token": "MASKED"
}
def myCommandCallback(cmd):
print('inside command callback')
print cmd
def main():
client = ibmiotf.device.Client(options)
client.connect()
client.commandCallback = myCommandCallback
while True:
sleep(1)
if __name__ == "__main__":
main()
与您的代码基本相似。
我可以发布命令来访问设备。
是否可以确认是否只有1个设备(或模拟设备)正在使用设备凭据,并且多个设备(物理设备或模拟设备)没有共享凭据?
谢谢和问候 Amit M Mangalvedkar