2021年8月24日 星期二

Node-Red UI 控制LED 5項功能並發行到MQTT ,再由UI訂閱MQTT 發行的訊息 並將收到結果送到UI SQLite Line Notify 上

 Node-Red UI 控制LED 5項功能並發行到MQTT ,再由UI訂閱MQTT 發行的訊息

並將收到結果送到UI SQLite Line Notify 上









[{"id":"81fcc172.b649c","type":"mqtt in","z":"b54306a0.2dba08","name":"","topic":"alex9ufo/inTopic/led/led_event","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":140,"y":140,"wires":[["6bd2f63e.91f458","5be77bc1.5e5f04","8fb7612a.9e94e"]]},{"id":"44f43ce1.52cea4","type":"ui_text","z":"b54306a0.2dba08","group":"ac0f1141.eb50e","order":0,"width":0,"height":0,"name":"","label":"ESP32發行到MQTT的資料","format":"{{msg.payload}}","layout":"col-center","x":560,"y":100,"wires":[]},{"id":"6ad0db60.45b7d4","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":0,"width":"4","height":"1","passthru":false,"label":"LED 開","tooltip":"","color":"white","bgcolor":"","icon":"fa-circle","payload":"ON","payloadType":"str","topic":"","x":80,"y":340,"wires":[["dd3a0c40.1bf03","b8f50787.64dcd8","d6da87f2.7031e8"]]},{"id":"a816230c.bd915","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":0,"width":"4","height":"1","passthru":false,"label":"LED 關","tooltip":"","color":"black","bgcolor":"","icon":"fa-circle-o","payload":"OFF","payloadType":"str","topic":"","x":80,"y":380,"wires":[["dd3a0c40.1bf03","b8f50787.64dcd8","d6da87f2.7031e8"]]},{"id":"dd3a0c40.1bf03","type":"mqtt out","z":"b54306a0.2dba08","name":"","topic":"alex9ufo/inTopic/led/led_event","qos":"1","retain":"true","broker":"841df58d.ee5e98","x":390,"y":420,"wires":[]},{"id":"6bd2f63e.91f458","type":"function","z":"b54306a0.2dba08","name":"Format timestamp","func":"var date = new Date();\n//var h = date.getHours()+8;\nvar h = date.getHours();\nvar m = date.getMinutes();\nvar s = date.getSeconds();\nif(h<10){\n    h = '0'+h;\n}\nif(m<10){\n    m = '0' + m;\n}\nif(s<10){\n    s = '0' + s;\n}\nmsg.payload = msg.payload + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":240,"wires":[["b25bd209.b48af"]]},{"id":"b25bd209.b48af","type":"function","z":"b54306a0.2dba08","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQ1yyIAwtggn1kf1ZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"x":470,"y":240,"wires":[["670d157d.a1ae2c"]]},{"id":"670d157d.a1ae2c","type":"http request","z":"b54306a0.2dba08","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":620,"y":240,"wires":[["dcb71013.e6c49"]]},{"id":"dcb71013.e6c49","type":"debug","z":"b54306a0.2dba08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":240,"wires":[]},{"id":"5be77bc1.5e5f04","type":"debug","z":"b54306a0.2dba08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":310,"y":200,"wires":[]},{"id":"f7af02e2.06a61","type":"ui_audio","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","voice":"Google 國語(臺灣)","always":true,"x":500,"y":140,"wires":[]},{"id":"ed0f4882.a1c028","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":0,"width":"4","height":"1","passthru":false,"label":"LED 開關反向","tooltip":"","color":"blue","bgcolor":"","icon":"fa-circle-o","payload":"TOGGLE","payloadType":"str","topic":"","x":100,"y":420,"wires":[["dd3a0c40.1bf03","b8f50787.64dcd8","d6da87f2.7031e8"]]},{"id":"8fb7612a.9e94e","type":"function","z":"b54306a0.2dba08","name":"","func":"var st1;\nif (msg.payload === \"ON\") {\n   st1=\"LED開\"; \n} \nelse if (msg.payload === \"OFF\") {\n  st1=\"LED關\";\n}\nelse if (msg.payload === \"FLASH\") {\n  st1=\"LED閃爍\";\n}\nelse if (msg.payload === \"TIMER\") {\n  st1=\"LED開五秒鐘\";\n}\nelse if (msg.payload === \"TOGGLE\") {\n  st1=\"LED ON OFF 交換\";\n}\n\nmsg.payload=st1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":140,"wires":[["f7af02e2.06a61","44f43ce1.52cea4","5e8beddd.ea9cb4"]]},{"id":"3f9840bb.01189","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":0,"width":"4","height":"1","passthru":false,"label":"LED 開5秒鐘","tooltip":"","color":"purple","bgcolor":"","icon":"fa-circle-o","payload":"TIMER","payloadType":"str","topic":"","x":90,"y":500,"wires":[["dd3a0c40.1bf03","b8f50787.64dcd8","d6da87f2.7031e8"]]},{"id":"5e8beddd.ea9cb4","type":"function","z":"b54306a0.2dba08","name":"INSERT","func":"msg.topic = \"INSERT INTO LED (time_led, led_status) VALUES (?,?)\";\n//msg.topic = \"INSERT INTO LED (id, time_led, led_status) VALUES (?,?,?)\";\n\n\nvar Today = new Date();\nvar yyyy = Today.getFullYear(); //年\nvar MM = Today.getMonth()+1;    //月\nvar dd = Today.getDate();       //日\nvar h = Today.getHours();       //時\nvar m = Today.getMinutes();     //分\nvar s = Today.getSeconds();     //秒\n\nif(MM<10)\n{\n   MM = '0'+MM;\n}\n\nif(dd<10)\n{\n   dd = '0'+dd;\n}\n\nif(h<10)\n{\n   h = '0'+h;\n}\n\nif(m<10)\n{\n  m = '0' + m;\n}\n\nif(s<10)\n{\n  s = '0' + s;\n}\n\nvar hms= yyyy + '/'+ MM + '/'+ dd + ' ' + h + ':' + m + ':' + s ;\n//var id= Date.now() ;\n//msg.payload = [id ,hms, msg.payload];\nmsg.payload = [hms, msg.payload];\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":180,"wires":[["70f85224.66a75c"]]},{"id":"70f85224.66a75c","type":"sqlite","z":"b54306a0.2dba08","mydb":"f5a33dc2.f6f08","sqlquery":"msg.topic","sql":"","name":"LED Status","x":630,"y":180,"wires":[["c88acfce.2a435"]]},{"id":"c88acfce.2a435","type":"debug","z":"b54306a0.2dba08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":180,"wires":[]},{"id":"7ce64989.ac2a88","type":"comment","z":"b54306a0.2dba08","name":"Node-Red publish 到 HiveMQ Broker  ","info":"將 alex9ufo/inTopic 到(publish)HiveMQ Broker \n給 Arduino 訂閱(Subscribe)","x":160,"y":300,"wires":[]},{"id":"16d32146.69272f","type":"comment","z":"b54306a0.2dba08","name":"Node-Red向 HiveMQ Broker訂閱subscribe","info":"將  Arduino 發行到(publish)HiveMQ Broker alex9ufo/led/led_status \n給 Node-red 或 MQTTB-Box 訂閱(Subscribe)","x":180,"y":100,"wires":[]},{"id":"5c03786d.1047f8","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":0,"width":"4","height":"1","passthru":false,"label":"LED 閃爍","tooltip":"","color":"yellow","bgcolor":"","icon":"fa-circle-o","payload":"FLASH","payloadType":"str","topic":"","x":80,"y":460,"wires":[["dd3a0c40.1bf03","b8f50787.64dcd8","d6da87f2.7031e8"]]},{"id":"b8f50787.64dcd8","type":"ui_audio","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","voice":"Google 國語(臺灣)","always":true,"x":320,"y":500,"wires":[]},{"id":"d6da87f2.7031e8","type":"ui_text","z":"b54306a0.2dba08","group":"ac0f1141.eb50e","order":0,"width":0,"height":0,"name":"","label":"Node-RED發行到MQTT的資料","format":"{{msg.payload}}","layout":"row-left","x":390,"y":340,"wires":[]},{"id":"38c59cae.9b9254","type":"function","z":"b54306a0.2dba08","name":"產生資料庫TABLE","func":"msg.topic = ' CREATE TABLE \"LED\" (\t\"id\"\tINTEGER,\t\"time_led\"\tTEXT,\"led_status\"\tTEXT,PRIMARY KEY(\"id\" AUTOINCREMENT))';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":560,"wires":[["4f135015.99984"]]},{"id":"29fbe590.9f17ba","type":"inject","z":"b54306a0.2dba08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":620,"wires":[["38c59cae.9b9254"]]},{"id":"6c9cc2fb.d8c9cc","type":"ui_button","z":"b54306a0.2dba08","name":"建立LED資料庫(只能執行一次)","group":"ac0f1141.eb50e","order":66,"width":"4","height":"2","passthru":false,"label":"建立LED資料庫(只能執行一次)","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":150,"y":560,"wires":[["38c59cae.9b9254"]]},{"id":"4f135015.99984","type":"sqlite","z":"b54306a0.2dba08","mydb":"f5a33dc2.f6f08","sqlquery":"msg.topic","sql":"","name":"LED Status","x":570,"y":560,"wires":[["886a4158.431a9","de8e9a34.114338"]]},{"id":"886a4158.431a9","type":"debug","z":"b54306a0.2dba08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":560,"wires":[]},{"id":"de8e9a34.114338","type":"ui_template","z":"b54306a0.2dba08","group":"ac0f1141.eb50e","name":"","order":0,"width":"12","height":"4","format":"<table style=\"width:100%\">\n  <tr>\n    <th>Index</th> \n    <th>Time</th> \n    <th>Status</th>\n  </tr>\n  <tr ng-repeat=\"x in msg.payload | limitTo:20\">\n    <td>{{$index}}</td>\n    <td>{{msg.payload[$index].time_led }}</td>\n    <td>{{msg.payload[$index].led_status}}</td> \n  </tr>\n</table>\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":760,"y":600,"wires":[[]]},{"id":"9bdf819a.db03f","type":"ui_button","z":"b54306a0.2dba08","name":"","group":"ac0f1141.eb50e","order":10,"width":"4","height":"2","passthru":false,"label":"檢視LED資料庫","tooltip":"","color":"","bgcolor":"","icon":"","payload":"檢視LED資料庫","payloadType":"str","topic":"SELECT * FROM LED ORDER BY  id  DESC LIMIT 100;","x":400,"y":620,"wires":[["4f135015.99984"]]},{"id":"c110dfd9.a5329","type":"comment","z":"b54306a0.2dba08","name":"送出訊息 到 Line Notify","info":"","x":480,"y":280,"wires":[]},{"id":"841df58d.ee5e98","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ac0f1141.eb50e","type":"ui_group","name":"LED","tab":"834e019a.2dfbb","order":1,"disp":true,"width":"8","collapse":true},{"id":"f5a33dc2.f6f08","type":"sqlitedb","db":"c:\\users\\alex\\.node-red\\LED_MQTT_LINE.db","mode":"RWC"},{"id":"834e019a.2dfbb","type":"ui_tab","name":"MongoDB","icon":"dashboard","disabled":false,"hidden":false}]

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...