實驗2-1 LED control (MQTT + Node-Red + Sqlite + Li ne Notify)
[{"id":"57da059ec95e597e","type":"mqtt in","z":"5f992d028747508b","name":"","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","inputs":0,"x":140,"y":80,"wires":[["b2eba4ee3ad04a9b","1f1bf165106c3364","800138e2fa6b5a95"]]},{"id":"cf7929e1dc1f49f6","type":"ui_text","z":"5f992d028747508b","group":"46aabdb0f7bc62c1","order":0,"width":0,"height":0,"name":"","label":"ESP32發行到MQTT的資料","format":"{{msg.payload}}","layout":"col-center","className":"","x":440,"y":120,"wires":[]},{"id":"9966a56e4c194e95","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":0,"width":"3","height":"1","passthru":false,"label":"LED 開","tooltip":"","color":"white","bgcolor":"","className":"","icon":"fa-circle","payload":"ON","payloadType":"str","topic":"","topicType":"str","x":120,"y":400,"wires":[["953a7c0c5f0b9bb3","059c2cebf07ca67c","49e1085191a13188"]]},{"id":"8944c3c632b4881d","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":0,"width":"3","height":"1","passthru":false,"label":"LED 關","tooltip":"","color":"black","bgcolor":"","className":"","icon":"fa-circle-o","payload":"OFF","payloadType":"str","topic":"","topicType":"str","x":120,"y":440,"wires":[["953a7c0c5f0b9bb3","059c2cebf07ca67c","49e1085191a13188"]]},{"id":"953a7c0c5f0b9bb3","type":"mqtt out","z":"5f992d028747508b","name":"Control LED","topic":"alex9ufo/inTopic/led/led_event","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":390,"y":500,"wires":[]},{"id":"b2eba4ee3ad04a9b","type":"function","z":"5f992d028747508b","name":"Format timestamp","func":"var date = new Date();\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,"x":170,"y":260,"wires":[["ce9a650f65d05095"]]},{"id":"ce9a650f65d05095","type":"function","z":"5f992d028747508b","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":350,"y":260,"wires":[["fd5234723ea48f84"]]},{"id":"fd5234723ea48f84","type":"http request","z":"5f992d028747508b","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":520,"y":260,"wires":[["ba8df1f296e206e3"]]},{"id":"ba8df1f296e206e3","type":"debug","z":"5f992d028747508b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":260,"wires":[]},{"id":"1f1bf165106c3364","type":"debug","z":"5f992d028747508b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":80,"wires":[]},{"id":"d2dcb00d2dfa1eb4","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":0,"width":"3","height":"1","passthru":false,"label":"LED 開關反向","tooltip":"","color":"blue","bgcolor":"","className":"","icon":"fa-circle-o","payload":"TOGGLE","payloadType":"str","topic":"","topicType":"str","x":140,"y":480,"wires":[["953a7c0c5f0b9bb3","059c2cebf07ca67c","49e1085191a13188"]]},{"id":"800138e2fa6b5a95","type":"function","z":"5f992d028747508b","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":250,"y":180,"wires":[["cf7929e1dc1f49f6","83a40f62df09f249","6b8c3a1c3cec0397"]]},{"id":"ad0eea0d1ef039a1","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":0,"width":"3","height":"1","passthru":false,"label":"LED 開5秒鐘","tooltip":"","color":"purple","bgcolor":"","className":"","icon":"fa-circle-o","payload":"TIMER","payloadType":"str","topic":"","topicType":"str","x":130,"y":560,"wires":[["953a7c0c5f0b9bb3","059c2cebf07ca67c","49e1085191a13188"]]},{"id":"f23457d961919b2b","type":"debug","z":"5f992d028747508b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":220,"wires":[]},{"id":"543e002f781ad1de","type":"comment","z":"5f992d028747508b","name":"Node-Red publish 到 HiveMQ Broker , ESP32訂閱","info":"將 alex9ufo/inTopic 到(publish)HiveMQ Broker \n給 Arduino 訂閱(Subscribe)","x":250,"y":600,"wires":[]},{"id":"432d059452c3d17a","type":"comment","z":"5f992d028747508b","name":"ESP32向 HiveMQ Broker發行 Node-Red 訂閱subscribe","info":"將 Arduino 發行到(publish)HiveMQ Broker alex9ufo/led/led_status \n給 Node-red 或 MQTTB-Box 訂閱(Subscribe)","x":240,"y":40,"wires":[]},{"id":"9635ae8f45d96599","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":0,"width":"3","height":"1","passthru":false,"label":"LED 閃爍","tooltip":"","color":"yellow","bgcolor":"","className":"","icon":"fa-circle-o","payload":"FLASH","payloadType":"str","topic":"","topicType":"str","x":120,"y":520,"wires":[["953a7c0c5f0b9bb3","059c2cebf07ca67c","49e1085191a13188"]]},{"id":"059c2cebf07ca67c","type":"ui_audio","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","voice":"zh-TW","always":true,"x":380,"y":560,"wires":[]},{"id":"49e1085191a13188","type":"ui_text","z":"5f992d028747508b","group":"46aabdb0f7bc62c1","order":0,"width":0,"height":0,"name":"","label":"Node-RED發行到MQTT的資料","format":"{{msg.payload}}","layout":"row-center","className":"","x":430,"y":440,"wires":[]},{"id":"789671ac55f5b9f5","type":"inject","z":"5f992d028747508b","name":"CREATE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":340,"wires":[["4885df399c5b715b"]]},{"id":"e11b3ada51352da1","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":11,"width":"4","height":"1","passthru":false,"label":"建立資料庫(LED只能執行一次)","tooltip":"","color":"","bgcolor":" purple","className":"","icon":"","payload":"","payloadType":"str","topic":"","topicType":"str","x":170,"y":300,"wires":[["4885df399c5b715b"]]},{"id":"4885df399c5b715b","type":"sqlite","z":"5f992d028747508b","mydb":"af927aba.0dc108","sqlquery":"fixed","sql":"CREATE TABLE LEDS (id INTEGER, timeled TEXT,ledstatus TEXT, PRIMARY KEY(id AUTOINCREMENT))","name":"CREATE led.db","x":400,"y":340,"wires":[["2b9972183f540956"]]},{"id":"2b9972183f540956","type":"debug","z":"5f992d028747508b","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"caab6a99213a0d02","type":"ui_button","z":"5f992d028747508b","name":"","group":"46aabdb0f7bc62c1","order":10,"width":"3","height":"1","passthru":false,"label":"View Data (LED)","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視LED資料庫","payloadType":"str","topic":"SELECT * FROM LEDS ORDER BY id DESC LIMIT 100;","topicType":"str","x":470,"y":160,"wires":[["852ed9b9ce5989cd","83a40f62df09f249"]]},{"id":"83a40f62df09f249","type":"ui_text_input","z":"5f992d028747508b","name":"","label":"","tooltip":"","group":"46aabdb0f7bc62c1","order":9,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","sendOnBlur":true,"className":"","topicType":"str","x":660,"y":180,"wires":[["dd7cf3a4df736de4"]]},{"id":"dd7cf3a4df736de4","type":"ui_audio","z":"5f992d028747508b","name":"播放聲音","group":"46aabdb0f7bc62c1","voice":"Google 國語(臺灣)","always":true,"x":800,"y":180,"wires":[]},{"id":"852ed9b9ce5989cd","type":"sqlite","z":"5f992d028747508b","mydb":"af927aba.0dc108","sqlquery":"msg.topic","sql":"","name":"LED","x":650,"y":140,"wires":[["3f1f8e28d531b7cc"]]},{"id":"3f1f8e28d531b7cc","type":"ui_template","z":"5f992d028747508b","group":"46aabdb0f7bc62c1","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].timeled}}</td>\n <td>{{msg.payload[$index].ledstatus}}</td> \n </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":800,"y":140,"wires":[[]]},{"id":"6b8c3a1c3cec0397","type":"function","z":"5f992d028747508b","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.params = { $thetime:hms, $thevalue:msg.payload }\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":220,"wires":[["96acafbee0f35c78"]]},{"id":"96acafbee0f35c78","type":"sqlite","z":"5f992d028747508b","mydb":"af927aba.0dc108","sqlquery":"prepared","sql":"insert into LEDS(timeled ,ledstatus) values ($thetime , $thevalue)\n","name":"LED","x":510,"y":220,"wires":[["f23457d961919b2b"]]},{"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":"46aabdb0f7bc62c1","type":"ui_group","name":"LED讀取","tab":"2bf82b8e33f9dd7c","order":1,"disp":true,"width":"15","collapse":false},{"id":"af927aba.0dc108","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\rfid_led.db","mode":"RWC"},{"id":"2bf82b8e33f9dd7c","type":"ui_tab","name":"LED","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
沒有留言:
張貼留言