mqtt - Node-RED,IOT Foundation Out 节点不发送命令

标签 mqtt ibm-cloud iot node-red

我有一个绑定(bind)到 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 输出节点,但是当我触发流程时,命令回调函数没有触发!

enter image description here enter image description here

我认为尝试使用时间戳触发器来触发命令或者我配置输出节点本身的方式可能有问题 - 任何建议或意见将不胜感激!

最佳答案

检查命令是否到达 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": []
}
]

它会在工作区中以这种方式显示。
enter image description here

添加此流程后,您可以测试从同一工作区发布的设备命令。
你能试试这个吗?由于您现在有 2 个调试节点,您应该能够两次看到相同的时间戳输出。我尝试了相同的流程,具有相同的细节(组织除外)并且工作正常。

感谢和问候
阿米特 M Mangalvedkar

关于mqtt - Node-RED,IOT Foundation Out 节点不发送命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30878659/

相关文章:

dart - 在 Flutter 中实现 MQTT

rest - IBM 物联网基金会 : When to use MQTT and when to use REST for event submission?

java - Mqtt-Spring Boot 中的集成

api - Watson 语音转文本响应时间

java - SpeechToText IBM Watson ExceptionInInitializerError

amazon-web-services - 使用 BG96 和 MQTT 协议(protocol)将数据发布到 aws IoT 时出错

node.js - 将nodejs应用程序部署到bluemix时如何指定npm版本?

azure - 消息队列: Multiple Topics vs Generic Topics with Filters

c - 如何在 Azure Sphere Visual Studio 项目中添加库依赖项?

Android AWS IoT 示例未更新影子