0

In my Node-RED flow, I have wired an IBM IoT Input node to an IBM IoT Output node. I am using mosquitto_pub on command line to publish to WIoTP so that the Node-RED flow is started. Similarly, I am using mqtt sub (from mqttjs) to subscribe to the message from the Node-RED flow. However, I am not receiving payload on my subscription terminal window.

Publish

mosquitto_pub -h orgId.messaging.internetofthings.ibmcloud.com -p 8883 -i d:orgId:dType:default -u use-token-auth -P 'authToken' --cafile messaging.pem -t iot-2/evt/data/fmt/json -f payload.json

Subscribe

mqtt sub -h orgId.messaging.internetofthings.ibmcloud.com -p 443 -l wss -i a:orgId:default_mobile -u API-key -P 'API-token' --ca messaging.pem -t iot-2/type/mobile/id/default_mobile/evt/live/fmt/json

For subscription, I have created API keys and am using the same. What am I missing?

idan
  • 554
  • 6
  • 19
cogitoergosum
  • 2,309
  • 4
  • 38
  • 62

2 Answers2

0

the subscription topic seems to be incorrect. If your device is publishing in

iot-2/evt/data/fmt/json

then you should subscribe to

iot-2/type/mobile/id/default_mobile/evt/data/fmt/json

Note: mind data instead of live

idan
  • 554
  • 6
  • 19
  • The device publishes to `iot-2/evt/data/fmt/json` which is subscribed to by IBM IoT input node. The IBM IoT input node publishes to an Output node where event type is set to `live`. My aim is to subscribe to messages as published by the Output node _over wss_. – cogitoergosum Jul 20 '18 at 06:42
  • would it be possible to send the configuration of the node-red iot output node to have a look? – idan Jul 20 '18 at 09:58
  • When I tried pasting the JSON of the entire flow at pastebin.org, the spam detector stopped me! So, here is node alone. `[{"id":"d9d6d027.eb598","type":"ibmiot out","z":"4dd997f2.a81f","authentication":"boundService","apiKey":"","outputType":"evt","deviceId":"default_mobile","deviceType":"mobile","eventCommandType":"live","format":"json","data":"LiveStatus","qos":0,"name":"Application","service":"registered","x":290,"y":300,"wires":[]}]` Wire an IBM IoT input node to it. Publish to Input node via `mosquitto_pub` and try receiving data from IBM IoT output node through `mqtt sub`. – cogitoergosum Jul 20 '18 at 10:08
  • one question, do you see events coming from the IoT out node? You can wire a debug node and check. – idan Jul 20 '18 at 11:19
  • Where do I wire the Debug node to on an _out_ node? BTW, I realised that, if I wire the input node to output node directly then, the `msg.` attributes (in the input node) will override the ones set in the Output node. I am now using a function node in between to set the relevant `msg.` attributes. No luck, yet. – cogitoergosum Jul 20 '18 at 11:21
  • my mistake here, meant IoT in. I want to make sure you see events arriving in nodered from mosquitto_pub – idan Jul 20 '18 at 11:42
  • Yes; that is confirmed. Messages are received in Input node. – cogitoergosum Jul 20 '18 at 11:42
  • then node red side seems to be fine. Can you add v option to the mqtt client and see what is saying? – idan Jul 20 '18 at 12:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176414/discussion-between-cogitoergosum-and-idan). – cogitoergosum Jul 20 '18 at 12:28
0

Thanks to @idan this problem is now resolved!

  1. Devices (beginning with a d:) can subscribe to iot-2/cmd topic strings only.
  2. I had wired the input node to output node directly. Therefore, all the settings in the output node were being overridden with msg. attributes. So, I put in a function node that sets the msg. attributes. Alternatively (as suggested by @idan), the function node can have a single line as msg=msg.payload so that the attributes in the node are not overridden.
cogitoergosum
  • 2,309
  • 4
  • 38
  • 62