ESP32 — MQTT 基本範例 (Node-Red , MQTT, SQLite)---2
https://www.youtube.com/watch?v=lecWlbk5TVU
https://www.youtube.com/watch?v=BOuHvjaQmac
ESP32 arduino程式 (WOKWI)
Node-Red程式
[{"id":"e4de61f840ff4186","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":540,"y":420,"wires":[["9b39e7f9d0de3c6c"]]},{"id":"7d81c14d45b924d9","type":"function","z":"1cb8c7b06aa228ec","name":"CREATE DATABASE","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id))\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":420,"wires":[["e4de61f840ff4186"]]},{"id":"43a9ffc15d03ddc0","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":7,"width":3,"height":1,"passthru":false,"label":"建立LED資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":420,"wires":[["7d81c14d45b924d9","3b2a733d94aa3174"]]},{"id":"28d0c6542865dcab","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":1,"width":3,"height":1,"passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":70,"y":60,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"aad1c2096a9d30b3","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":2,"width":3,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":70,"y":100,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"908599ef8c86ed18","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":3,"width":3,"height":1,"passthru":false,"label":"TIMER","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"timer","payloadType":"str","topic":"topic","topicType":"msg","x":80,"y":140,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"274736447d2b843d","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":4,"width":3,"height":1,"passthru":false,"label":"FLASH","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"flash","payloadType":"str","topic":"topic","topicType":"msg","x":80,"y":180,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"5e6bcf2aef18ddd3","type":"function","z":"1cb8c7b06aa228ec","name":"INSERT","func":"var 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(); //秒\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}\nvar var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\n\nvar myLED = msg.payload;\n\n\nmsg.topic = \"INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED, $var_date , $var_time ) \" ;\nmsg.payload = [myLED, var_date , var_time ]\nreturn msg;\n\n\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":280,"wires":[["4ca8f98f0e9682d0"]]},{"id":"b276c95f6102c9e6","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":255,"y":120,"wires":[],"l":false},{"id":"4ca8f98f0e9682d0","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":560,"y":280,"wires":[["818d2b33739f7962","12249c85f15ce393"]]},{"id":"9b39e7f9d0de3c6c","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":420,"wires":[]},{"id":"818d2b33739f7962","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"43a95c8e62974938","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":9,"width":6,"height":1,"passthru":false,"label":"檢視資料庫資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":360,"wires":[["12249c85f15ce393","3b2a733d94aa3174"]]},{"id":"12249c85f15ce393","type":"function","z":"1cb8c7b06aa228ec","name":"檢視資料","func":"//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":360,"wires":[["35735ca5dc3427a1"]]},{"id":"9220d9a167300332","type":"ui_table","z":"1cb8c7b06aa228ec","group":"e9069c1d660c717d","name":"","order":1,"width":8,"height":10,"columns":[],"outputs":0,"cts":false,"x":730,"y":360,"wires":[]},{"id":"35735ca5dc3427a1","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":580,"y":360,"wires":[["9220d9a167300332"]]},{"id":"a78e0cc08c28827b","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":860,"y":480,"wires":[["767ef5c9f2337832"]]},{"id":"be3ad5eddc38f6e5","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":8,"width":3,"height":1,"passthru":false,"label":"刪除所有資料 ","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除所有資料 ","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":480,"wires":[["921595beceb1bf10","386929a18f8c3baa"]]},{"id":"3d5c971ba2dd4094","type":"function","z":"1cb8c7b06aa228ec","name":"DELETE ALL DATA","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DELETE from LEDSTATUS\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":480,"wires":[["a78e0cc08c28827b"]]},{"id":"921595beceb1bf10","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":225,"y":540,"wires":[],"l":false},{"id":"386929a18f8c3baa","type":"ui_toast","z":"1cb8c7b06aa228ec","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":290,"y":480,"wires":[["78a9770191c1eb0f"]]},{"id":"78a9770191c1eb0f","type":"function","z":"1cb8c7b06aa228ec","name":"OK or Cancel","func":"var topic=msg.payload;\nif (topic==\"\"){\n return [msg,null];\n \n}\nif (topic==\"Cancel\"){\n return [null,msg];\n \n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":480,"wires":[["3d5c971ba2dd4094"],[]]},{"id":"3b2a733d94aa3174","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":245,"y":380,"wires":[],"l":false},{"id":"767ef5c9f2337832","type":"link out","z":"1cb8c7b06aa228ec","name":"link out 57","mode":"link","links":["f3248f140546ebdf"],"x":845,"y":420,"wires":[]},{"id":"f3248f140546ebdf","type":"link in","z":"1cb8c7b06aa228ec","name":"link in 55","links":["767ef5c9f2337832"],"x":915,"y":420,"wires":[["12249c85f15ce393"]]},{"id":"62a3a53547369382","type":"mqtt out","z":"1cb8c7b06aa228ec","name":"Control LED out","topic":"alex9ufo/led/led_event","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":280,"y":60,"wires":[]},{"id":"dbbfb6c3eed987cd","type":"mqtt in","z":"1cb8c7b06aa228ec","name":"Control LED in","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":280,"wires":[["5e6bcf2aef18ddd3","0187a4131d9cbc68"]]},{"id":"363407e738e7cff2","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":180,"wires":[]},{"id":"0187a4131d9cbc68","type":"ui_text","z":"1cb8c7b06aa228ec","group":"adfc6534bf97e4f1","order":5,"width":6,"height":1,"name":"","label":"MQTT來的","format":"<font color = RED>{{msg.payload}}","layout":"row-left","className":"","x":450,"y":220,"wires":[]},{"id":"0c28f914af70b6c9","type":"mqtt in","z":"1cb8c7b06aa228ec","name":"Control LED in","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":220,"wires":[["3a3953fad846f64b"]]},{"id":"3a3953fad846f64b","type":"function","z":"1cb8c7b06aa228ec","name":"判斷","func":"var check= flow.get('ledsimu');\nvar mqttin=msg.payload;\n\nif (check == true)\n{\n msg.payload=mqttin;\n return [msg,null];\n}\nif (check == false)\n{\n msg.payload=mqttin;\n return [null ,msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":220,"wires":[["0187a4131d9cbc68","5e6bcf2aef18ddd3"],[]]},{"id":"f5c97c74cc496505","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\2024EX_LED2.db","mode":"RWC"},{"id":"adfc6534bf97e4f1","type":"ui_group","name":"LED2_控制","tab":"2eed7cc3b24b8f69","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e9069c1d660c717d","type":"ui_group","name":"顯示區","tab":"2eed7cc3b24b8f69","order":3,"disp":true,"width":8,"collapse":false,"className":""},{"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":"2eed7cc3b24b8f69","type":"ui_tab","name":"WOKWI_LED","icon":"dashboard","order":125,"disabled":false,"hidden":false}]
2024-05-27 更新 Node-Red 含 Line Notify
[{"id":"e4de61f840ff4186","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":540,"y":420,"wires":[["9b39e7f9d0de3c6c"]]},{"id":"7d81c14d45b924d9","type":"function","z":"1cb8c7b06aa228ec","name":"CREATE DATABASE","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id))\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":420,"wires":[["e4de61f840ff4186"]]},{"id":"43a9ffc15d03ddc0","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":7,"width":3,"height":1,"passthru":false,"label":"建立LED資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":420,"wires":[["7d81c14d45b924d9","3b2a733d94aa3174"]]},{"id":"28d0c6542865dcab","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":1,"width":3,"height":1,"passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":70,"y":60,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"aad1c2096a9d30b3","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":2,"width":3,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":70,"y":100,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"908599ef8c86ed18","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":3,"width":3,"height":1,"passthru":false,"label":"TIMER","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"timer","payloadType":"str","topic":"topic","topicType":"msg","x":80,"y":140,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"274736447d2b843d","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":4,"width":3,"height":1,"passthru":false,"label":"FLASH","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"flash","payloadType":"str","topic":"topic","topicType":"msg","x":80,"y":180,"wires":[["b276c95f6102c9e6","62a3a53547369382","363407e738e7cff2"]]},{"id":"5e6bcf2aef18ddd3","type":"function","z":"1cb8c7b06aa228ec","name":"INSERT","func":"var 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(); //秒\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}\nvar var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\n\nvar myLED = msg.payload;\n\n\nmsg.topic = \"INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED, $var_date , $var_time ) \" ;\nmsg.payload = [myLED, var_date , var_time ]\nreturn msg;\n\n\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":280,"wires":[["4ca8f98f0e9682d0"]]},{"id":"b276c95f6102c9e6","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":255,"y":120,"wires":[],"l":false},{"id":"4ca8f98f0e9682d0","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":560,"y":280,"wires":[["818d2b33739f7962","12249c85f15ce393"]]},{"id":"9b39e7f9d0de3c6c","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":420,"wires":[]},{"id":"818d2b33739f7962","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"43a95c8e62974938","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":9,"width":6,"height":1,"passthru":false,"label":"檢視資料庫資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":360,"wires":[["12249c85f15ce393","3b2a733d94aa3174"]]},{"id":"12249c85f15ce393","type":"function","z":"1cb8c7b06aa228ec","name":"檢視資料","func":"//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":360,"wires":[["35735ca5dc3427a1"]]},{"id":"9220d9a167300332","type":"ui_table","z":"1cb8c7b06aa228ec","group":"e9069c1d660c717d","name":"","order":1,"width":8,"height":10,"columns":[],"outputs":0,"cts":false,"x":730,"y":360,"wires":[]},{"id":"35735ca5dc3427a1","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":580,"y":360,"wires":[["9220d9a167300332"]]},{"id":"a78e0cc08c28827b","type":"sqlite","z":"1cb8c7b06aa228ec","mydb":"f5c97c74cc496505","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":860,"y":480,"wires":[["767ef5c9f2337832"]]},{"id":"be3ad5eddc38f6e5","type":"ui_button","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","order":8,"width":3,"height":1,"passthru":false,"label":"刪除所有資料 ","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除所有資料 ","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":480,"wires":[["921595beceb1bf10","386929a18f8c3baa"]]},{"id":"3d5c971ba2dd4094","type":"function","z":"1cb8c7b06aa228ec","name":"DELETE ALL DATA","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DELETE from LEDSTATUS\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":480,"wires":[["a78e0cc08c28827b"]]},{"id":"921595beceb1bf10","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":225,"y":540,"wires":[],"l":false},{"id":"386929a18f8c3baa","type":"ui_toast","z":"1cb8c7b06aa228ec","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":290,"y":480,"wires":[["78a9770191c1eb0f"]]},{"id":"78a9770191c1eb0f","type":"function","z":"1cb8c7b06aa228ec","name":"OK or Cancel","func":"var topic=msg.payload;\nif (topic==\"\"){\n return [msg,null];\n \n}\nif (topic==\"Cancel\"){\n return [null,msg];\n \n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":480,"wires":[["3d5c971ba2dd4094"],[]]},{"id":"3b2a733d94aa3174","type":"ui_audio","z":"1cb8c7b06aa228ec","name":"","group":"adfc6534bf97e4f1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":245,"y":380,"wires":[],"l":false},{"id":"767ef5c9f2337832","type":"link out","z":"1cb8c7b06aa228ec","name":"link out 57","mode":"link","links":["f3248f140546ebdf"],"x":845,"y":420,"wires":[]},{"id":"f3248f140546ebdf","type":"link in","z":"1cb8c7b06aa228ec","name":"link in 55","links":["767ef5c9f2337832"],"x":915,"y":420,"wires":[["12249c85f15ce393"]]},{"id":"62a3a53547369382","type":"mqtt out","z":"1cb8c7b06aa228ec","name":"Control LED out","topic":"alex9ufo/led/led_event","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":280,"y":60,"wires":[]},{"id":"dbbfb6c3eed987cd","type":"mqtt in","z":"1cb8c7b06aa228ec","name":"Control LED in","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":280,"wires":[["5e6bcf2aef18ddd3","0187a4131d9cbc68"]]},{"id":"363407e738e7cff2","type":"debug","z":"1cb8c7b06aa228ec","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":180,"wires":[]},{"id":"0187a4131d9cbc68","type":"ui_text","z":"1cb8c7b06aa228ec","group":"adfc6534bf97e4f1","order":5,"width":6,"height":1,"name":"","label":"MQTT來的","format":"<font color = RED>{{msg.payload}}","layout":"row-left","className":"","x":450,"y":220,"wires":[]},{"id":"0c28f914af70b6c9","type":"mqtt in","z":"1cb8c7b06aa228ec","name":"Control LED in","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":220,"wires":[["3a3953fad846f64b"]]},{"id":"3a3953fad846f64b","type":"function","z":"1cb8c7b06aa228ec","name":"判斷","func":"var check= flow.get('ledsimu');\nvar mqttin=msg.payload;\n\nif (check == true)\n{\n msg.payload=mqttin;\n return [msg,null];\n}\nif (check == false)\n{\n msg.payload=mqttin;\n return [null ,msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":220,"wires":[["0187a4131d9cbc68","5e6bcf2aef18ddd3"],[]]},{"id":"620c6304c6809821","type":"comment","z":"1cb8c7b06aa228ec","name":"Line API","info":"","x":80,"y":600,"wires":[]},{"id":"7139ab918dd842bf","type":"function","z":"1cb8c7b06aa228ec","name":"Format timestamp","func":"var date = new Date();\nvar h = date.getHours()+8;\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":310,"y":640,"wires":[["37578ace0bc47a29"]]},{"id":"37578ace0bc47a29","type":"function","z":"1cb8c7b06aa228ec","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,"initialize":"","finalize":"","libs":[],"x":490,"y":640,"wires":[["1a27b5a0ccdeb3f0"]]},{"id":"1a27b5a0ccdeb3f0","type":"http request","z":"1cb8c7b06aa228ec","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":660,"y":640,"wires":[["0df091a0ac52c38c"]]},{"id":"0df091a0ac52c38c","type":"debug","z":"1cb8c7b06aa228ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":640,"wires":[]},{"id":"ad5fdcf07bb10bdf","type":"mqtt in","z":"1cb8c7b06aa228ec","name":"Control LED in","topic":"alex9ufo/led/led_status","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":640,"wires":[["7139ab918dd842bf"]]},{"id":"f5c97c74cc496505","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\2024EX_LED2.db","mode":"RWC"},{"id":"adfc6534bf97e4f1","type":"ui_group","name":"LED2_控制","tab":"2eed7cc3b24b8f69","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e9069c1d660c717d","type":"ui_group","name":"顯示區","tab":"2eed7cc3b24b8f69","order":3,"disp":true,"width":8,"collapse":false,"className":""},{"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":"2eed7cc3b24b8f69","type":"ui_tab","name":"WOKWI_LED","icon":"dashboard","order":125,"disabled":false,"hidden":false}]
設定 LINE Notify https://md.webduino.io/s/LCGRt1Jve
「LINE Notify」的服務,透過開通權杖 ( Token ),讓 Node-Red(LED) 主動傳訊息至 LINE 帳號中,可用來結合通知、警告等應用。
步驟:
準備好自己的 LINE 帳號密碼。
前往 LINE Notify 官方網站。( 請使用電腦開啟!)
登入帳號。
點擊右上角帳號,選擇選單中的「個人頁面」。
點擊「發行權杖」。
設定權杖,填寫權杖名稱、接收通知的聊天室。這裡以「透過1對1聊天接收LINE Notify的通知」為例。
- 權杖名稱:發送訊息時,會顯示的名稱。
- 接收通知的聊天室:要使用 Notify 的聊天室,或是個人訊息。
按下「發行」後,會出現發行的權杖如下圖,並將權杖複製。
權杖只會顯示 1 次,每次使用程式積木都需要輸入,為避免忘記,建議先將權杖記錄下來。
設定完成後,就可以在「已連動的服務」中看到剛剛設定的權杖了。
打開 LINE 應用程式,可以看到名稱為「LINE Notify」的帳號發送訊息「已發行個人存取權杖。」。
沒有留言:
張貼留言