2020年8月24日 星期一

Node-Red & MySQL & Line Notify

 Node-Red & MySQL & Line Notify  
















注意

S =msg.payload

msg.topic = "INSERT INTO led ( `LED_Status`) VALUES ( '" + S + "');"

return msg;


Node-Red 程式
=======================================================================

[{"id":"f869fa31.2f2508","type":"tab","label":"流程5","disabled":false,"info":""},{"id":"ae7468f4.24aea8","type":"mqtt in","z":"f869fa31.2f2508","name":"","topic":"alex9ufo/led/led_event","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":120,"y":80,"wires":[["d90adb1e.55bb18","267de439.cf353c","814976c.686a388"]]},{"id":"d90adb1e.55bb18","type":"ui_text","z":"f869fa31.2f2508","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"name":"","label":"MQTT Suscribe Data","format":"{{msg.payload}}","layout":"col-center","x":380,"y":80,"wires":[]},{"id":"d11d794c.f6c4d8","type":"ui_button","z":"f869fa31.2f2508","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"On led","tooltip":"","color":"white","bgcolor":"","icon":"fa-circle","payload":"LED開","payloadType":"str","topic":"","x":90,"y":320,"wires":[["ad1c7f22.8f16b","971b5fae.98e77"]]},{"id":"ed1f01ca.24304","type":"ui_button","z":"f869fa31.2f2508","name":"","group":"6c9116b.b62d4e8","order":0,"width":0,"height":0,"passthru":false,"label":"Off led","tooltip":"","color":"black","bgcolor":"","icon":"fa-circle-o","payload":"LED關","payloadType":"str","topic":"","x":90,"y":380,"wires":[["ad1c7f22.8f16b","971b5fae.98e77"]]},{"id":"ad1c7f22.8f16b","type":"mqtt out","z":"f869fa31.2f2508","name":"","topic":"alex9ufo/led/led_event","qos":"1","retain":"false","broker":"841df58d.ee5e98","x":360,"y":320,"wires":[]},{"id":"971b5fae.98e77","type":"ui_audio","z":"f869fa31.2f2508","name":"","group":"6c9116b.b62d4e8","voice":"zh-TW","always":"","x":320,"y":380,"wires":[]},{"id":"267de439.cf353c","type":"function","z":"f869fa31.2f2508","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":190,"y":220,"wires":[["9ebd8c60.18215"]]},{"id":"9ebd8c60.18215","type":"function","z":"f869fa31.2f2508","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":370,"y":220,"wires":[["31dbb78.b800e48"]]},{"id":"31dbb78.b800e48","type":"http request","z":"f869fa31.2f2508","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":540,"y":220,"wires":[["da02d08f.6b501"]]},{"id":"da02d08f.6b501","type":"debug","z":"f869fa31.2f2508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":220,"wires":[]},{"id":"814976c.686a388","type":"function","z":"f869fa31.2f2508","name":"MySQL Function","func":"S =msg.payload\nmsg.topic = \"INSERT INTO led ( `LED_Status`) VALUES ( '\" + S + \"');\"\nreturn msg;\n\n//INSERT INTO `led` (`id`, `time_led`, `LED_Status`) VALUES ('1', current_timestamp(), 'LED開');","outputs":1,"noerr":0,"x":370,"y":120,"wires":[["97a0fefe.2112d","a08402e0.5d7e9"]]},{"id":"a08402e0.5d7e9","type":"mysql","z":"f869fa31.2f2508","mydb":"3ec1eff7.3a59c","name":"MySQLDatabase","x":590,"y":160,"wires":[[]]},{"id":"97a0fefe.2112d","type":"debug","z":"f869fa31.2f2508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":120,"wires":[]},{"id":"841df58d.ee5e98","type":"mqtt-broker","z":"","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":"6c9116b.b62d4e8","type":"ui_group","z":"","name":"Test","tab":"eeb8e179.a47a4","order":1,"disp":true,"width":"6","collapse":false},{"id":"3ec1eff7.3a59c","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"mysql_led","tz":"GMT +8"},{"id":"eeb8e179.a47a4","type":"ui_tab","z":"","name":"MySQL","icon":"dashboard","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...