2

For a Node-RED application, I am using MQTT to talk with the device. Do I need to use two "topics"?:

  • One topic for the device to publish information to be subscribed by the Node-Red application.
  • One topic for the Node-RED application to publish (and the device to subscribe to).

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:

  • The Device would be publishing temperatures.
  • The Node-RED application would be publishing "user request" information that would tell the device when to report temperatures.
4

1 に答える 1

2

2 つの異なるトピックを使用する必要があります。
IoT Foundation サービスに接続するアプリケーション (Node-RED など) は、コマンドをデバイスに発行し、デバイス イベントをサブスクライブします。

デバイスはコマンド トピックにサブスクライブし、アプリケーション (Node-RED) はイベント トピックにサブスクライブします。

デバイスは、温度などのイベントを発行します。そのため、デバイスはそのイベントを iot-2/evt/event_id/fmt/format_string の形式でトピックに発行する必要があり、Node-RED アプリケーションは別のトピックにコマンドを発行します。

たとえば...次のような温度を公開できます。

iot-2/evt/temperature/fmt/json{ d: { temp: 25 } } を実行し、次のようにコマンドをデバイスに発行します: iot-2/cmd/sendTemperature/fmt/json

デバイスはコマンド トピックにサブスクライブし、アプリケーション (Node-RED) はイベント トピックにサブスクライブします。具体的には、イベントをパブリッシュする場合、トピック iot-2/evt/event_id/fmt/format_string にパブリッシュし、デバイスはトピック iot-2/cmd/command_id/fmt/format_string にサブスクライブすることでコマンドにサブスクライブします

MQTT および IoTのオンラインドキュメントを参照してください。

于 2015-09-21T18:25:58.557 に答える