Example usage of dynamic mqtt in node (digitaloak-mqtt-in)
MQTT input node
Based on core Node-RED "mqtt in" which uses "mqtt-broker" config node.
Features
- subscribe dynamically to topics
- unsubscribe automatically after first msg received
- unsubscribe dynamically specific node/nodes from topic
- pass messages through node when msg.topic not set
Description
- Subscribe to topics specyfing msg.topic
- Unsubscribe node from topic automatically after first msg received, via setting checkbox in config node: "Unsubscribe from topic after first msg received"
- Unsubscribe specific node from specific topic,via setting a string value in msg.payload in format "_unsubscribe:
<nodeName>
" ie. "_unsubscribe:waitingForResponse" - Pass msgs via node - don't set msg.topic
Support & Discussion
Please join: https://riot.digitaloak.it/#/room/#node-red-contrib-digitaloak-mqtt:digitaloak.it
[{"id":"dfc8744e.285418","type":"tab","label":"Example usage of dynamic mqtt node (digitaloak-mqtt-in)","disabled":false,"info":""},{"id":"6157c6d6.6d9798","type":"comment","z":"dfc8744e.285418","name":"Subscribe dynamically to topics","info":"","x":190,"y":40,"wires":[]},{"id":"77f1c335.c3cffc","type":"inject","z":"dfc8744e.285418","name":"Subscribe to carrots","topic":"carrots","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":100,"wires":[["97225001.241d8"]]},{"id":"30122e68.b592f2","type":"inject","z":"dfc8744e.285418","name":"Subscribe to potatoes","topic":"potatoes","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":140,"wires":[["97225001.241d8"]]},{"id":"2f1ec6ee.6d303a","type":"debug","z":"dfc8744e.285418","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":120,"wires":[]},{"id":"97225001.241d8","type":"digitaloak-mqtt-in","z":"dfc8744e.285418","name":"Grocery","qos":"2","datatype":"auto","unsubscribe-after-first-msg-recv":false,"broker":"311f12a4.3d2b9e","x":420,"y":120,"wires":[["2f1ec6ee.6d303a"]]},{"id":"1b170909.ae8687","type":"inject","z":"dfc8744e.285418","name":"Publish to carrots","topic":"carrots","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":200,"wires":[["273dc11f.91128e"]]},{"id":"671d79a2.99ddb8","type":"inject","z":"dfc8744e.285418","name":"Publish to potatoes","topic":"potatoes","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":240,"wires":[["273dc11f.91128e"]]},{"id":"273dc11f.91128e","type":"mqtt out","z":"dfc8744e.285418","name":"Grocery","topic":"","qos":"","retain":"","broker":"311f12a4.3d2b9e","x":400,"y":220,"wires":[]},{"id":"e5a2c557.d18548","type":"comment","z":"dfc8744e.285418","name":"Unsubscribe dynamically from topics","info":"","x":210,"y":420,"wires":[]},{"id":"4db77eb9.6475c","type":"inject","z":"dfc8744e.285418","name":"Unsubscribe from Carrots","topic":"carrots","payload":"_unsubscribe:Grocery","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":480,"wires":[["3f7f231.3605bdc"]]},{"id":"3f7f231.3605bdc","type":"mqtt out","z":"dfc8744e.285418","name":"Grocery","topic":"","qos":"","retain":"","broker":"311f12a4.3d2b9e","x":440,"y":480,"wires":[]},{"id":"77d7345b.abb9ec","type":"comment","z":"dfc8744e.285418","name":"Pass msgs through node when msg.topic not set","info":"","x":240,"y":300,"wires":[]},{"id":"26e481e8.64972e","type":"inject","z":"dfc8744e.285418","name":"Pass msg throug node","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":360,"wires":[["97225001.241d8"]]},{"id":"9e2ebecf.837cc","type":"comment","z":"dfc8744e.285418","name":"Unsubscribe from topic after first message received","info":"","x":250,"y":540,"wires":[]},{"id":"1732adbd.4f1c82","type":"digitaloak-mqtt-in","z":"dfc8744e.285418","name":"Grocery","qos":"2","datatype":"auto","unsubscribe-after-first-msg-recv":true,"broker":"311f12a4.3d2b9e","x":420,"y":600,"wires":[["8ebe9528.682628"]]},{"id":"a774460.57e40b8","type":"inject","z":"dfc8744e.285418","name":"Subscribe to tomatoes","topic":"tomatoes","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":600,"wires":[["1732adbd.4f1c82"]]},{"id":"8ebe9528.682628","type":"debug","z":"dfc8744e.285418","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":600,"wires":[]},{"id":"95039228.eb2e3","type":"inject","z":"dfc8744e.285418","name":"Publish to tomatoes","topic":"tomatoes","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":660,"wires":[["2c040cef.4ca0f4"]]},{"id":"2c040cef.4ca0f4","type":"mqtt out","z":"dfc8744e.285418","name":"Grocery","topic":"","qos":"","retain":"","broker":"311f12a4.3d2b9e","x":400,"y":660,"wires":[]},{"id":"311f12a4.3d2b9e","type":"mqtt-broker","z":"","name":"","broker":"mqtt","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]