节点-红色,物联网基础输出节点未发送命令 [英] Node-RED, IOT Foundation Out Node Not Sending Commands

查看:98
本文介绍了节点-红色,物联网基础输出节点未发送命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到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个调试节点,因此您应该能够看到两次相同的时间戳输出.我尝试了相同的流程,使用相同的详细信息(组织除外),并且工作正常.

感谢和问候
阿米特·曼加维达(Amit M Mangalvedkar)

I have a Node-RED application that is bound to an IOT Foundation (iotf) service. I can receive events from devices and handle them appropriately.

However, I am now interested in sending commands back to my devices and am having some problems. Nothing is showing up at the device, but by creating an IOTF in node, I can confirm that the command is passing through iotf.

I can definitely get commands to pass through iotf using pure python, as the follow code works well:

Client code:

#!/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()

Application code:

#!/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

Whenever I run the application code, I see the following output:

root@raspberrypi ~ # ./app.py 
inside command callback
<ibmiotf.device.Command instance at 0x14e8490>

I have a Node-RED iotf output node configured as shown below, but when I trigger the flow, the command callback function doesn't trigger!

I'm thinking there maybe something wrong either with trying to use a timestamp trigger to fire the command, or with the way I've configured the output node itself -- any suggestions or advice would be appreciated!

解决方案

A simple test to check if the commands are reaching IBM IoT Foundation is - developing another flow having an IoT App In node which subscribes to the commands. I am attaching the Node-RED flow for the same here

[
{
    "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": []
}
]

It would appear this way in the workspace.

After you have added this flow, you can test the device command publishing from the same workspace.
Can you please try this? Since you would now have 2 debug nodes, you should be able to see the same timetamp output twice. I have tried the same flow, with the same details (except the organization) and it works fine.

Thanks and Regards
Amit M Mangalvedkar

这篇关于节点-红色,物联网基础输出节点未发送命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆