Reputation: 1787
For a Node-RED application, I am using MQTT to talk with the device. Do I need to use two "topics"?:
Alternatively, can both the device and Node-RED application post different information (both publishing and subscribing) to the same topic?
For example: If the device is both publishing temperature data and also subscribing to the same topic to get information from Node-RED in Bluemix, will that cause issues? There are two types of data I want to exchange:
Upvotes: 2
Views: 360
Reputation: 2626
You should use two different topics.
Applications (such as Node-RED) that connect to the IoT Foundation service publish commands to devices and subscribe to device events.
The device would subscribe to the command topic, and the application (Node-RED) to the event topic.
Your device will be publishing events – such as temperature. So the device should publish that event to a topic in the format iot-2/evt/event_id/fmt/format_string and your Node-RED application will be publishing a command to a different topic.
For example... You could publish temperatures like this:
iot-2/evt/temperature/fmt/json { d: { temp: 25 } }
and publish commands to the device like this: iot-2/cmd/sendTemperature/fmt/json
The device would subscribe to the command topic, and the application (Node-RED) to the event topic. Specifically, when you are publishing events, you publish to topic iot-2/evt/event_id/fmt/format_string and devices subscribe to commands by subscribing to topic iot-2/cmd/command_id/fmt/format_string
See the online documentation for MQTT and IoT.
Upvotes: 2