2024年3月12日 星期二

MQTT Explorer 與 Node-Red 介面的實驗

 MQTT Explorer 與 Node-Red 介面的實驗



MQTT EXplorer 與 Node-Red介面的設定
(1) 設定 MQTT EXplorer Client 
 

(2)  



    Node-Red LED ON  --> MQTT Explorer LED= on
   
     MQTT Explorer  Topic : alex9ufo/2024/RFID/Back_LED 
                                  Payload:  ON
     -->  Node-Red  LED ON





(2)  Node-Red LED OFF  --> MQTT Explorer LED= off
   
     MQTT Explorer  Topic : alex9ufo/2024/RFID/Back_LED 
                                  Payload:  OFF
     -->  Node-Red  LED OFF















Node-Red 程式畫面




node-red程式

[{"id":"9f51922c96475745","type":"mqtt in","z":"024ba427a7f5812e","name":"Rack LED","topic":"alex9ufo/2024/RFID/Back_LED","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":520,"wires":[["a8fcaef90ac2a7ea","2778b0a8751644f1","5f2c87735b333a9c","c0707331bbc29acc"]]},{"id":"a8fcaef90ac2a7ea","type":"function","z":"024ba427a7f5812e","name":"function LED on ,off","func":"var onoff=msg.payload;\n\nif (onoff==\"ON\")\n{\n    msg.payload=true;\n}\nif (onoff==\"OFF\")\n{\n    msg.payload=false;\n}  \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":600,"wires":[["11f9b3fed3944fec"]]},{"id":"bfb3b1e0afad219b","type":"inject","z":"024ba427a7f5812e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":370,"y":680,"wires":[["11f9b3fed3944fec"]]},{"id":"03dd3a2a9506eea5","type":"inject","z":"024ba427a7f5812e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":370,"y":640,"wires":[["11f9b3fed3944fec"]]},{"id":"11f9b3fed3944fec","type":"ui_led","z":"024ba427a7f5812e","order":1,"group":"7b4b159b9632feb1","width":6,"height":5,"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":570,"y":600,"wires":[]},{"id":"1639f0d1ca085251","type":"ui_button","z":"024ba427a7f5812e","name":"","group":"7b4b159b9632feb1","order":2,"width":0,"height":0,"passthru":false,"label":"LED ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":80,"wires":[["1953eedb67e61c2c","16609fe88dddf2ab","1b28a9dbc6b3afc8"]]},{"id":"415bdb9608b58cee","type":"ui_button","z":"024ba427a7f5812e","name":"","group":"7b4b159b9632feb1","order":3,"width":0,"height":0,"passthru":false,"label":"LED OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":180,"wires":[["1953eedb67e61c2c","16609fe88dddf2ab","1b28a9dbc6b3afc8"]]},{"id":"1953eedb67e61c2c","type":"ui_audio","z":"024ba427a7f5812e","name":"","group":"7b4b159b9632feb1","voice":"Google US English","always":"","x":420,"y":140,"wires":[]},{"id":"16609fe88dddf2ab","type":"mqtt out","z":"024ba427a7f5812e","name":"LED","topic":"alex9ufo/2024/RFID/LED","qos":"0","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":410,"y":80,"wires":[]},{"id":"2778b0a8751644f1","type":"ui_text","z":"024ba427a7f5812e","group":"7b4b159b9632feb1","order":5,"width":0,"height":0,"name":"","label":"MQTT<<訂閱>>的訊息","format":"{{msg.payload}}","layout":"row-left","className":"","x":380,"y":560,"wires":[]},{"id":"1b28a9dbc6b3afc8","type":"ui_text","z":"024ba427a7f5812e","group":"7b4b159b9632feb1","order":4,"width":0,"height":0,"name":"","label":"MQTT  [ [發行] ] 的訊息","format":"{{msg.payload}}","layout":"row-left","className":"","x":460,"y":180,"wires":[]},{"id":"4d98ddd8f5354d4f","type":"ui_text","z":"024ba427a7f5812e","group":"7b4b159b9632feb1","order":6,"width":0,"height":0,"name":"","label":"MQTT 的Broker :","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-left","className":"","x":710,"y":340,"wires":[]},{"id":"a6a877eb4be7a0cf","type":"function","z":"024ba427a7f5812e","name":"function on off","func":"var on_off=flow.get(\"onoff\");\n\nif (on_off== true)\n{\n    msg.payload='HiveMQTT';\n    flow.set(\"onoff\",false)\n}   \nelse\n{\n    msg.payload='   ';\n    flow.set(\"onoff\",true)\n}\nmsg.color=\"red\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":340,"wires":[["4d98ddd8f5354d4f","8f16f50beb2fd914"]]},{"id":"1ab8fc00ab6a2801","type":"inject","z":"024ba427a7f5812e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":170,"y":340,"wires":[["a6a877eb4be7a0cf","b234e6b8f0c79306"]]},{"id":"8f16f50beb2fd914","type":"delay","z":"024ba427a7f5812e","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":480,"y":280,"wires":[["a6a877eb4be7a0cf"]]},{"id":"b234e6b8f0c79306","type":"function","z":"024ba427a7f5812e","name":"function  flow set","func":"flow.set(\"onoff\",true);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":380,"wires":[[]]},{"id":"c6aada400221f416","type":"comment","z":"024ba427a7f5812e","name":"發行 alex9ufo/2024/RFID/LED","info":"","x":220,"y":140,"wires":[]},{"id":"a0786c74e597ace5","type":"comment","z":"024ba427a7f5812e","name":"訂閱 alex9ufo/2024/RFID/Back_LED","info":"","x":240,"y":440,"wires":[]},{"id":"cffb26e93155b0b4","type":"comment","z":"024ba427a7f5812e","name":"定期 閃爍 HiveMQTT","info":"","x":200,"y":280,"wires":[]},{"id":"a3da334ec58d571b","type":"inject","z":"024ba427a7f5812e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":780,"wires":[["96d55c93b931523e"]]},{"id":"5ebf60e91bf99d7a","type":"template","z":"024ba427a7f5812e","name":"Image in","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<img src=\"data:image/png;base64,{{payload}}\"style=\"width=\"400\" height=\"300\"\"/>","output":"str","x":680,"y":780,"wires":[["621cc26def28f659"]]},{"id":"621cc26def28f659","type":"ui_template","z":"024ba427a7f5812e","group":"610b6d14a9aef1a0","name":"MQTT","order":1,"width":10,"height":8,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":850,"y":780,"wires":[[]]},{"id":"96d55c93b931523e","type":"file in","z":"024ba427a7f5812e","name":"","filename":"D:\\2024RFID\\作業1\\EX1.png","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":340,"y":780,"wires":[["c62ccd80dad331eb"]]},{"id":"c62ccd80dad331eb","type":"base64","z":"024ba427a7f5812e","name":"","action":"","property":"payload","x":540,"y":780,"wires":[["5ebf60e91bf99d7a"]]},{"id":"b7ab30b1c8592615","type":"comment","z":"024ba427a7f5812e","name":"On inject add MQTT picture  to the dashboard","info":"","x":250,"y":840,"wires":[]},{"id":"8d7b00ea7d339381","type":"comment","z":"024ba427a7f5812e","name":"存放路徑若是不同需修改","info":"存放路徑\nD:\\2024RFID\\作業1\\EX1.png\n若是不同需修改","x":170,"y":720,"wires":[]},{"id":"5f2c87735b333a9c","type":"function","z":"024ba427a7f5812e","name":"function ","func":"msg.payload=\" ---ESP32 回來 LED的狀態---\" +msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":520,"wires":[["7cb295df3f651ad8","a588fcd00a340802"]]},{"id":"7cb295df3f651ad8","type":"function","z":"024ba427a7f5812e","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"x":550,"y":540,"wires":[["69f4d04c83a3b62d"]]},{"id":"69f4d04c83a3b62d","type":"http request","z":"024ba427a7f5812e","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":700,"y":540,"wires":[["3db96139024c408b"]]},{"id":"3db96139024c408b","type":"debug","z":"024ba427a7f5812e","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":540,"wires":[]},{"id":"b53b1192a01aea88","type":"comment","z":"024ba427a7f5812e","name":"Line Notify Message ","info":"","x":790,"y":500,"wires":[]},{"id":"a588fcd00a340802","type":"ui_text","z":"024ba427a7f5812e","group":"610b6d14a9aef1a0","order":2,"width":0,"height":0,"name":"","label":"ESP32 LED至Line訊息","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-left","className":"","x":580,"y":500,"wires":[]},{"id":"c51ffa9eeb9c79b7","type":"ui_text","z":"024ba427a7f5812e","group":"7bec0a4da1755d2d","order":1,"width":6,"height":4,"name":"","label":"RFID UID -->","format":"{{msg.payload}}","layout":"row-left","className":"","x":1290,"y":80,"wires":[]},{"id":"075b1e287e5d9347","type":"mqtt in","z":"024ba427a7f5812e","name":"RFID_UID","topic":"alex9ufo/2024/RFID/RFID_UID","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":780,"y":80,"wires":[["c51ffa9eeb9c79b7","df55f1819e8b66e7","afdbad21b78a0b02"]]},{"id":"df55f1819e8b66e7","type":"delay","z":"024ba427a7f5812e","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":920,"y":40,"wires":[["dae09bddc266dc4c"]]},{"id":"dae09bddc266dc4c","type":"function","z":"024ba427a7f5812e","name":"function  覆蓋","func":"msg.payload=\"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":40,"wires":[["c51ffa9eeb9c79b7"]]},{"id":"afdbad21b78a0b02","type":"function","z":"024ba427a7f5812e","name":"function  ","func":"msg.payload=\" ---ESP32 回來 UID號碼---\" +msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":920,"y":180,"wires":[["66e6317ca7b54715","82904e831754affc"]]},{"id":"66e6317ca7b54715","type":"function","z":"024ba427a7f5812e","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"x":1070,"y":180,"wires":[["10568f34aa90f487"]]},{"id":"10568f34aa90f487","type":"http request","z":"024ba427a7f5812e","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":1220,"y":180,"wires":[["6a38bfa68353e278"]]},{"id":"6a38bfa68353e278","type":"debug","z":"024ba427a7f5812e","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":180,"wires":[]},{"id":"82904e831754affc","type":"ui_text","z":"024ba427a7f5812e","group":"610b6d14a9aef1a0","order":3,"width":0,"height":0,"name":"","label":"ESP32 RFID至Line訊息","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-left","className":"","x":1090,"y":140,"wires":[]},{"id":"3b949643e95630ef","type":"mqtt in","z":"024ba427a7f5812e","name":"RFID_PICC","topic":"alex9ufo/2024/RFID/RFID_PICC","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":790,"y":280,"wires":[["13f661295c829301","389105838630bc97"]]},{"id":"389105838630bc97","type":"delay","z":"024ba427a7f5812e","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":980,"y":240,"wires":[["22f59fb343de54a2"]]},{"id":"22f59fb343de54a2","type":"function","z":"024ba427a7f5812e","name":"function  覆蓋","func":"msg.payload=\"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":240,"wires":[["13f661295c829301"]]},{"id":"13f661295c829301","type":"ui_text","z":"024ba427a7f5812e","group":"7bec0a4da1755d2d","order":3,"width":6,"height":5,"name":"","label":"RFID  -->","format":"{{msg.payload}}","layout":"row-left","className":"","x":1320,"y":280,"wires":[]},{"id":"c0707331bbc29acc","type":"debug","z":"024ba427a7f5812e","name":"debug 270","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":480,"wires":[]},{"id":"603bb104.d6134","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":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"7b4b159b9632feb1","type":"ui_group","name":"LED","tab":"dd5fce9c0b030350","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"610b6d14a9aef1a0","type":"ui_group","name":"LINE","tab":"dd5fce9c0b030350","order":2,"disp":true,"width":10,"collapse":false,"className":""},{"id":"7bec0a4da1755d2d","type":"ui_group","name":"RFID","tab":"dd5fce9c0b030350","order":3,"disp":true,"width":"6","collapse":false,"className":""},{"id":"dd5fce9c0b030350","type":"ui_tab","name":"2024RFID產業專班","icon":"dashboard","order":103,"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...