Node -RED, IOT Foundation Out Node Commands not sending
I have a Node -RED application linked to an IOT Foundation (iotf) service. I can receive events from devices and handle them accordingly.
However, I am now interested in sending commands back to my devices and I have some problems. Nothing appears on the device, but by creating an IOTF in node I can confirm that the command is going through the iotf.
I can definitely get the commands to go through iotf using pure python, since the following 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 my 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 as shown below, but when I start the thread, the command callback function is not triggered!
I think there might be something wrong if you are trying to use a timestamp trigger to run a command, or with the way I configured the node output myself - any suggestions or advice would be appreciated!
source to share
A simple test to see if the IBM IoT Foundation teams have achieved is to develop another thread that has an IoT In node application that subscribes to the teams. I am attaching a Node -RED thread 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 will appear in the work area.
After you've added this stream, you can test publishing device commands from the same workspace.
Can you try this? Since you now have 2 debug nodes, you should see the same timetamp output twice. I tried the same thread, with the same details (apart from the organization) and it works great.
Thank you and
best regards Amit M Mangalvedkar
source to share
I have tried the following code
#!/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()
which is essentially similar to your code. And I can post the commands to access the device.
Can you confirm that only one device (or simulated device) is using the device credentials and that the credentials are not shared by multiple devices (physical or simulated device)?
Thank you and
best regards Amit M Mangalvedkar
source to share