ESP32 and Node-RED with MQTT (Publish and Subscribe)
參考來源 https://randomnerdtutorials.com/esp8266-and-node-red-with-mqtt/
mqtt_server = "broker.mqtt-dashboard.com"
client.publish("alex9ufo/Thinkitive/temp"
client.publish("alex9ufo/Thinkitive/hum"
client.subscribe("alex9ufo/room/lamp");
WOKWI ESP32程式
Node-Red 程式
[{"id":"3322eee9576783df","type":"mqtt in","z":"4b78f7e5d13e6604","name":"濕度","topic":"alex9ufo/Thinkitive/hum","qos":"1","datatype":"auto-detect","broker":"b9efc827e98bf7f9","nl":false,"rap":true,"rh":0,"inputs":0,"x":230,"y":120,"wires":[["c955bb867c3764eb"]]},{"id":"e10e2c7d299e3c2c","type":"mqtt out","z":"4b78f7e5d13e6604","name":"燈泡","topic":"alex9ufo/room/lamp","qos":"1","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b9efc827e98bf7f9","x":410,"y":180,"wires":[]},{"id":"df3ef8083edb59a3","type":"mqtt in","z":"4b78f7e5d13e6604","name":"溫度","topic":"alex9ufo/Thinkitive/temp","qos":"1","datatype":"auto-detect","broker":"b9efc827e98bf7f9","nl":false,"rap":true,"rh":0,"inputs":0,"x":230,"y":60,"wires":[["88fc71e9f52b3d9e"]]},{"id":"4619b3053d03f1a8","type":"ui_switch","z":"4b78f7e5d13e6604","name":"","label":"switch","tooltip":"","group":"3ac0cc1879cac657","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":230,"y":180,"wires":[["e10e2c7d299e3c2c"]]},{"id":"88fc71e9f52b3d9e","type":"ui_chart","z":"4b78f7e5d13e6604","name":"溫度","group":"9cb87f6334be2cce","order":1,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"0","ymax":"40","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,"className":"","x":410,"y":60,"wires":[[]]},{"id":"c955bb867c3764eb","type":"ui_gauge","z":"4b78f7e5d13e6604","name":"濕度'","group":"9cb87f6334be2cce","order":2,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":410,"y":120,"wires":[]},{"id":"b9efc827e98bf7f9","type":"mqtt-broker","name":"broker.mqtt-dashboard.com","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"3ac0cc1879cac657","type":"ui_group","name":"Lamp","tab":"0c1ba72ccee260d2","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"9cb87f6334be2cce","type":"ui_group","name":"Sensor","tab":"0c1ba72ccee260d2","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"0c1ba72ccee260d2","type":"ui_tab","name":"Room","icon":"dashboard","disabled":false,"hidden":false}]








沒有留言:
張貼留言