Node-RED,IOT Foundation Out 节点不发送命令
Node-RED, IOT Foundation Out Node Not Sending Commands
我有一个绑定到 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 输出节点,但是当我触发流程时,命令回调函数没有触发!
我认为尝试使用时间戳触发器触发命令或者我配置输出节点本身的方式可能有问题 - 任何建议或意见将不胜感激!
检查命令是否到达 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": []
}
]
它在工作区中会这样显示。
添加此流程后,您可以测试从同一工作空间发布的设备命令。
你能试试这个吗?由于您现在有 2 个调试节点,您应该能够两次看到相同的时间戳输出。我尝试了相同的流程,具有相同的细节(组织除外)并且工作正常。
感谢和问候
阿米特 M Mangalvedkar
我有一个绑定到 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 输出节点,但是当我触发流程时,命令回调函数没有触发!
我认为尝试使用时间戳触发器触发命令或者我配置输出节点本身的方式可能有问题 - 任何建议或意见将不胜感激!
检查命令是否到达 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": []
}
]
它在工作区中会这样显示。
添加此流程后,您可以测试从同一工作空间发布的设备命令。
你能试试这个吗?由于您现在有 2 个调试节点,您应该能够两次看到相同的时间戳输出。我尝试了相同的流程,具有相同的细节(组织除外)并且工作正常。
感谢和问候
阿米特 M Mangalvedkar