Help with receiving command from function node

#1

Hi, I am testing to receive commands with an arduino board(MKR 1000) and I've already registered the device to the IoT platform. The device can receive commands if I use the inject node. I want to use a function node instead, I've set the code to send the same data within the inject node but the IoT node doesn't seem to receive the data correctly. I'm not seeing the command. I've used a test IoT node to monitor commands, I can only see them while using the inject node to insert the data. I've got the flow below with a picture from the inject node. Any help is appreciated

[{"id":"54ab2bb3.3aff74","type":"ibmiot in","z":"707e7b57.d964e4","authentication":"boundService","apiKey":"","inputType":"evt","logicalInterface":"","ruleId":"","deviceId":"a8610a31301e7813","applicationId":"","deviceType":"MKRWAN1000-1","eventType":"+","commandType":"","format":"json","name":"IBM IoT","service":"registered","allDevices":true,"allApplications":"","allDeviceTypes":true,"allLogicalInterfaces":"","allEvents":true,"allCommands":"","allFormats":true,"qos":0,"x":140.00004196166992,"y":310.9523639678955,"wires":[["4fcf1113.bcc44"]]},{"id":"b027746c.b8bce8","type":"debug","z":"707e7b57.d964e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":960.0000419616699,"y":346.6666622161865,"wires":[]},{"id":"5bd9ca04.46e0b4","type":"function","z":"707e7b57.d964e4","name":"filterData","func":"return {payload:msg.payload.Payload};","outputs":1,"noerr":0,"x":541.71435546875,"y":434.6666564941406,"wires":[["b793187b.667688","f721940c.fe4b38"]]},{"id":"195e0a5c.0e8836","type":"switch","z":"707e7b57.d964e4","name":"EUI filter","property":"payload.EUI","propertyType":"msg","rules":[{"t":"eq","v":"00-12-02-04-06-08-01-00","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":406.7857780456543,"y":363.09524869918823,"wires":[["b027746c.b8bce8","5303507d.5b171"]]},{"id":"857b1f90.7e278","type":"switch","z":"707e7b57.d964e4","name":"EUI filter","property":"payload.EUI","propertyType":"msg","rules":[{"t":"eq","v":"00-12-02-04-06-08-01-00","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370.0000419616699,"y":506.6666622161865,"wires":[["825879d1.bd8e18"]]},{"id":"825879d1.bd8e18","type":"function","z":"707e7b57.d964e4","name":"filterData","func":"return {payload:msg.payload.Payload};","outputs":1,"noerr":0,"x":510.0000419616699,"y":506.6666622161865,"wires":[["34d7a447.61258c","b027746c.b8bce8"]]},{"id":"f721940c.fe4b38","type":"switch","z":"707e7b57.d964e4","name":"Threshold detector","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":805.7143249511719,"y":446.6666679382324,"wires":[["b027746c.b8bce8"]]},{"id":"77ca3ffc.c88af","type":"debug","z":"707e7b57.d964e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1011.9047241210938,"y":184.19049835205078,"wires":[]},{"id":"b793187b.667688","type":"ui_chart","z":"707e7b57.d964e4","name":"","group":"393542a8.a8830e","order":0,"width":0,"height":0,"label":"temperature in Celsius","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"-20","ymax":"45","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":750.0000419616699,"y":506.6666622161865,"wires":[[],[]]},{"id":"34d7a447.61258c","type":"ui_chart","z":"707e7b57.d964e4","name":"","group":"393542a8.a8830e","order":0,"width":0,"height":0,"label":"Light","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":700.0000419616699,"y":606.6666622161865,"wires":[[],[]]},{"id":"4fcf1113.bcc44","type":"json","z":"707e7b57.d964e4","name":"","property":"payload","action":"","pretty":false,"x":276.4286136627197,"y":321.6666660308838,"wires":[["195e0a5c.0e8836"]]},{"id":"1990bf1e.0c7dd1","type":"inject","z":"707e7b57.d964e4","name":"","topic":"","payload":"On","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":349,"y":186,"wires":[["a6048894.0990f8","5303507d.5b171","61d91f7e.61c8"]]},{"id":"61d91f7e.61c8","type":"ibmiot out","z":"707e7b57.d964e4","authentication":"boundService","apiKey":"","outputType":"cmd","deviceId":"F8F005EA5D05","deviceType":"MKRWAN1000-1","eventCommandType":"on","format":"string","data":"\"On\"","qos":0,"name":"IBM IoT","service":"registered","x":845,"y":39,"wires":[]},{"id":"a6048894.0990f8","type":"debug","z":"707e7b57.d964e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":917,"y":107,"wires":[]},{"id":"5303507d.5b171","type":"function","z":"707e7b57.d964e4","name":"","func":"if(msg.payload.Payload>23)\n{\nmsg.payload=\"On\"; \nreturn msg;\n}\n","outputs":1,"noerr":0,"x":588,"y":281,"wires":[["77ca3ffc.c88af","61d91f7e.61c8"]]},{"id":"393542a8.a8830e","type":"ui_group","z":"707e7b57.d964e4","name":"Group 1","tab":"d2ed68d.cb04098","order":1,"disp":true,"width":"6","collapse":false},{"id":"d2ed68d.cb04098","type":"ui_tab","z":"707e7b57.d964e4","name":"Home","icon":"dashboard","order":1}]

inject%20node

0 Likes

#2

Does the On message come out of your function node?

0 Likes

#3

Also what type of nodes are the iot nodes (node-red-contrib-something)?

0 Likes

#4

yes, when the data from the source is over 23 the function node send "On" seen in the debug tab, but the iot command out node doesn't register it. They are from "node-red-contrib-scx-ibmiotapp". With the inject node it receives "On" no problem. I've showed the config of the IoT output node(only allowed one pic per post).
commandNode2 !

0 Likes

#5

Put the debug node showing the output of the function into Show Complete Message mode, then have a look at what other properties are on the message and see if any of them may be interpreted by the iot node. I can pretty much guarantee that if you send an identical message from a function or in inject node then they will have the same effect, therefore there must be a difference between the messages.

0 Likes

#7

I did indeed check the complete message(didn't know it before) and found some format was set by the sending sensor node. I fixed it thanks to a change node and removing unnecessary properties. Thanks

1 Like