Watson IoT Platform - MQTT - Retainの確認
初めてWatson IoT Platformを使ってみよう、というかたのためのガイドです。
Watson IoT Platformを使ってみるでIoTアプリを準備しました。
MessageSightを動かすでMQTTブローカーとしてMessageSightを準備しました。
Node-REDをローカル環境で稼働させる
とWatson IoT Platform - MQTT - Node-REDからpub/subするでNode-REDからpub/subできるようにしました。
Retain機能の確認
- MQTTのRetain機能により、同一トピックの最新(最終)メッセージをブローカー内に保持することができます。
- Retainはパブリッシュする際にパブリッシャー(送信者)がメッセージ毎に指定可能です。
- サブスクライバー(受信者)は
- 接続されていればパブリッシュされた時にすぐ受信できます(当然)。
- あとからサブスクライブしても、ブローカー内にRETAIN(保持)されている最終版をサブスクライブした時に受信することができます。
- - Node-REDのフローをコピーする方法を参照して以下のフローをコピペし、MQTTノードのアドレスを自環境に合わせます。
Retainの確認
[{"id":"42b340e4.dc4bd","type":"mqtt-broker","z":"375326d0.fda38a","broker":"192.168.100.100","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"418d3097.c29d28","type":"mqtt out","z":"375326d0.fda38a","name":"","topic":"/abc/def/ghi","qos":"","retain":"true","broker":"42b340e4.dc4bd","x":250,"y":520,"wires":[]},{"id":"fec77fc6.405f2","type":"inject","z":"375326d0.fda38a","name":"","topic":"","payload":"こんにちは","payloadType":"str","repeat":"","crontab":"","once":false,"x":100,"y":520,"wires":[["418d3097.c29d28"]]},{"id":"796ea0f6.918108","type":"debug","z":"375326d0.fda38a","name":"","active":true,"console":"false","complete":"false","x":630,"y":520,"wires":[]},{"id":"9520efe5.348c9","type":"mqtt in","z":"375326d0.fda38a","name":"","topic":"/abc/def/ghi","broker":"42b340e4.dc4bd","x":450,"y":520,"wires":[["796ea0f6.918108"]]}]
- 接続されていればパブリッシュされた時にすぐ受信できます(当然)。
- あとからサブスクライブしても、ブローカー内にRETAIN(保持)されている最終版をサブスクライブした時に受信することができます。
Retainの確認
[{"id":"42b340e4.dc4bd","type":"mqtt-broker","z":"375326d0.fda38a","broker":"192.168.100.100","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"418d3097.c29d28","type":"mqtt out","z":"375326d0.fda38a","name":"","topic":"/abc/def/ghi","qos":"","retain":"true","broker":"42b340e4.dc4bd","x":250,"y":520,"wires":[]},{"id":"fec77fc6.405f2","type":"inject","z":"375326d0.fda38a","name":"","topic":"","payload":"こんにちは","payloadType":"str","repeat":"","crontab":"","once":false,"x":100,"y":520,"wires":[["418d3097.c29d28"]]},{"id":"796ea0f6.918108","type":"debug","z":"375326d0.fda38a","name":"","active":true,"console":"false","complete":"false","x":630,"y":520,"wires":[]},{"id":"9520efe5.348c9","type":"mqtt in","z":"375326d0.fda38a","name":"","topic":"/abc/def/ghi","broker":"42b340e4.dc4bd","x":450,"y":520,"wires":[["796ea0f6.918108"]]}]
Author And Source
この問題について(Watson IoT Platform - MQTT - Retainの確認), 我々は、より多くの情報をここで見つけました https://qiita.com/egplnt/items/2283b174e7d700a5d712著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .