NodeRED Lesson: MQTT Client

MQTT Client berdasarkan publish & subcribe kepada MQTT Broker. Contoh ini NodeRED subcribe MQTT daripada Hibiscus Sense yang publish MQTT. Data yang diterima adalah data daripada sensor BME280. Kemudian data di paparkan pada dashboard dalam bentuk graf.

Berikut adalah video demo nya.

Node-RED Flow

[{"id":"c0d0523d.66434","type":"function","z":"ca73b40c.bcc058","name":"","func":"p=JSON.parse(msg.payload);\nnode.log(typeof p);\naltitude={\n \"payload\":p.value1\n}\npressure={\n \"payload\":p.value2\n}\ntemperature={\n \"payload\":p.value3\n}\nhumidity={\n \"payload\":p.value4\n}\nreturn [altitude,pressure,temperature,humidity];","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":240,"wires":[["404cce43.36c0d"],["dc1b42b9.3321f"],["119d8b1c.82f665"],["c9911008.65edc"]]},{"id":"404cce43.36c0d","type":"ui_chart","z":"ca73b40c.bcc058","name":"","group":"b6070c1e.8f5ed","order":0,"width":0,"height":0,"label":"Altitude (m)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":630,"y":180,"wires":[[]]},{"id":"dc1b42b9.3321f","type":"ui_chart","z":"ca73b40c.bcc058","name":"","group":"b6070c1e.8f5ed","order":0,"width":0,"height":0,"label":"Pressure (kPa)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":640,"y":220,"wires":[[]]},{"id":"119d8b1c.82f665","type":"ui_chart","z":"ca73b40c.bcc058","name":"","group":"be659f40.4894f","order":0,"width":0,"height":0,"label":"Temperature (°C)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":650,"y":260,"wires":[[]]},{"id":"c9911008.65edc","type":"ui_chart","z":"ca73b40c.bcc058","name":"","group":"be659f40.4894f","order":0,"width":0,"height":0,"label":"Humidity (%)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":630,"y":300,"wires":[[]]},{"id":"f71cea5e.291e08","type":"mqtt in","z":"ca73b40c.bcc058","name":"MQTT","topic":"hibiscus/out","qos":"2","datatype":"auto","broker":"3f54bc74.efdd64","nl":false,"rap":true,"rh":0,"x":290,"y":240,"wires":[["c0d0523d.66434"]]},{"id":"b6070c1e.8f5ed","type":"ui_group","name":"Monitor 1","tab":"943f273a.07ed38","order":1,"disp":false,"width":"10","collapse":false},{"id":"be659f40.4894f","type":"ui_group","name":"Monitor 2","tab":"943f273a.07ed38","order":2,"disp":false,"width":"10","collapse":false},{"id":"3f54bc74.efdd64","type":"mqtt-broker","name":"mqtt.shahrulnizam.com","broker":"mqtt.shahrulnizam.com","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"943f273a.07ed38","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

ESP32 Source Code

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.