2023年9月28日 星期四

Connecting Node-Red and MQTT Broker

 Connecting Node-Red and MQTT Broker

系統方塊圖







Node-Red  節點

節點

設定內容

備註

 on Button  

Label : ON  (大寫)

Payload : on (小寫)

 

 off Button

Label : OFF (大寫)

Payload : off (小寫)

 

 溫度 Text input

Mode : number

Delay : 300 ms

 

 

MQTT out 的設定





MQTT in 的設定




 Function

var a=msg.payload;

msg.payload='';

 

if (a=='on')

    msg.payload=true

if (a=='off')

    msg.payload=false

 

return msg;

 


LED



TEXT









Dashboard 的Layout 設定




Node-Red 程式

[{"id":"676dee5a541d2c6a","type":"ui_button","z":"9febb32c6c5543b0","name":"","group":"75ebc44c62276bfe","order":9,"width":3,"height":1,"passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":230,"y":160,"wires":[["ba9dfc51c58a437c"]]},{"id":"a8f4413b32230f05","type":"ui_button","z":"9febb32c6c5543b0","name":"","group":"75ebc44c62276bfe","order":10,"width":3,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":230,"y":220,"wires":[["ba9dfc51c58a437c"]]},{"id":"441c871dacc833a4","type":"ui_text_input","z":"9febb32c6c5543b0","name":"","label":"溫度","tooltip":"請輸入溫度","group":"75ebc44c62276bfe","order":11,"width":3,"height":1,"passthru":true,"mode":"number","delay":300,"topic":"topic","sendOnBlur":true,"className":"","topicType":"msg","x":230,"y":280,"wires":[["af2b617f0f818c67"]]},{"id":"ba9dfc51c58a437c","type":"mqtt out","z":"9febb32c6c5543b0","name":"ESP32 LED","topic":"alex9ufo/esp32/led","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":450,"y":180,"wires":[]},{"id":"af2b617f0f818c67","type":"mqtt out","z":"9febb32c6c5543b0","name":"ESP32 Temperature","topic":"alex9ufo/esp32/temp","qos":"2","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":480,"y":280,"wires":[]},{"id":"7f44805cc86fcf5b","type":"mqtt in","z":"9febb32c6c5543b0","name":"","topic":"alex9ufo/esp32/led","qos":"1","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":270,"y":380,"wires":[["148e347b8294a3a1","6184060c2ae79db0"]]},{"id":"d8a4773e94b15f3d","type":"ui_led","z":"9febb32c6c5543b0","order":2,"group":"75ebc44c62276bfe","width":5,"height":2,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":610,"y":380,"wires":[]},{"id":"148e347b8294a3a1","type":"function","z":"9febb32c6c5543b0","name":"function ","func":"var a=msg.payload;\nmsg.payload='';\n\nif (a=='on')\n    msg.payload=true\nif (a=='off')\n    msg.payload=false\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":380,"wires":[["d8a4773e94b15f3d","f5fa640f6a30b3b9"]]},{"id":"b3958b5fed7b60d1","type":"mqtt in","z":"9febb32c6c5543b0","name":"","topic":"alex9ufo/esp32/temp","qos":"2","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":270,"y":460,"wires":[["0038c9c971028389"]]},{"id":"0038c9c971028389","type":"ui_text","z":"9febb32c6c5543b0","group":"75ebc44c62276bfe","order":6,"width":0,"height":0,"name":"","label":"溫度","format":"{{msg.payload}}","layout":"row-left","className":"","x":450,"y":460,"wires":[]},{"id":"6184060c2ae79db0","type":"debug","z":"9febb32c6c5543b0","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":450,"y":420,"wires":[]},{"id":"f5fa640f6a30b3b9","type":"debug","z":"9febb32c6c5543b0","name":"debug 196","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":340,"wires":[]},{"id":"75ebc44c62276bfe","type":"ui_group","name":"Default","tab":"f62d63d55905ecd0","order":1,"disp":true,"width":9,"collapse":false,"className":""},{"id":"841df58d.ee5e98","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"f62d63d55905ecd0","type":"ui_tab","name":"Home_MQTT","icon":"dashboard","disabled":false,"hidden":false}]

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...