MQTT發送的數據通過Node-RED創建的流程從MQTT通信消息轉換為LINE消息。
Node-RED , Line , MQTT
參考來源 https://qiita.com/kmaepu/items/6711c127c2a0434d5d98
[{"id":"e650e7b0.c39ae8","type":"tab","label":"MQTT與Node-RED","disabled":false,"info":""},{"id":"3b836a0b.8ed016","type":"inject","z":"e650e7b0.c39ae8","name":"","topic":"","payload":"Hello","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["68813400.ac67dc","84138d0b.7d64a"]]},{"id":"bd044a6.39730b8","type":"inject","z":"e650e7b0.c39ae8","name":"","topic":"","payload":"開始您的腹肌訓練!我要你支持我!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":360,"wires":[["cd6e0953.5c6ca8"]]},{"id":"91c15743.930228","type":"inject","z":"e650e7b0.c39ae8","name":"","topic":"","payload":"我想我做了20次!誇獎我!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":420,"wires":[["b1952dda.729eb"]]},{"id":"94627113.a5326","type":"template","z":"e650e7b0.c39ae8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"從現在開始,我將開始肌肉訓練!\n這次支持您的腹肌!","output":"str","x":291,"y":63,"wires":[["68813400.ac67dc","84138d0b.7d64a"]]},{"id":"20006501.84109a","type":"template","z":"e650e7b0.c39ae8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"這次我做了{{payload}}次!\n謝謝你的努力!","output":"str","x":290,"y":120,"wires":[["68813400.ac67dc","84138d0b.7d64a"]]},{"id":"131bafc1.02d7b","type":"template","z":"e650e7b0.c39ae8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"達到{{payload}}次!","output":"str","x":290,"y":180,"wires":[["68813400.ac67dc","84138d0b.7d64a"]]},{"id":"fe70ce7c.f6261","type":"comment","z":"e650e7b0.c39ae8","name":"測試流程","info":"","x":120,"y":240,"wires":[]},{"id":"ffcee50d.2742e8","type":"comment","z":"e650e7b0.c39ae8","name":"通過MQTT與Node-RED 進行數據傳輸/接收","info":"","x":220,"y":20,"wires":[]},{"id":"ff251965.b65f28","type":"mqtt in","z":"e650e7b0.c39ae8","name":"/start","topic":"alex9ufo/IOT/MQTT_test/start","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":110,"y":60,"wires":[["94627113.a5326"]]},{"id":"cd6e0953.5c6ca8","type":"mqtt out","z":"e650e7b0.c39ae8","name":"/start","topic":"alex9ufo/IOT/MQTT_test/start","qos":"1","retain":"false","broker":"841df58d.ee5e98","x":470,"y":360,"wires":[]},{"id":"ce743adb.d39768","type":"mqtt in","z":"e650e7b0.c39ae8","name":"/end","topic":"alex9ufo/IOT/MQTT_test/end","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":110,"y":120,"wires":[["20006501.84109a"]]},{"id":"e4573e54.a1bd7","type":"mqtt in","z":"e650e7b0.c39ae8","name":"/count","topic":"alex9ufo/IOT/MQTT_test/count","qos":"1","datatype":"auto","broker":"841df58d.ee5e98","x":110,"y":180,"wires":[["131bafc1.02d7b"]]},{"id":"b1952dda.729eb","type":"mqtt out","z":"e650e7b0.c39ae8","name":"/end","topic":"alex9ufo/IOT/MQTT_test/end","qos":"1","retain":"false","broker":"841df58d.ee5e98","x":470,"y":420,"wires":[]},{"id":"68813400.ac67dc","type":"function","z":"e650e7b0.c39ae8","name":"Set Line Notify API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer cEI4hx24xyopKGAArgZcKJNHE1V7KeeIi4Lzny3dDNO'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":140,"wires":[["fa76df59.8a107"]]},{"id":"fa76df59.8a107","type":"http request","z":"e650e7b0.c39ae8","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":600,"y":200,"wires":[["d72767b0.3fa668"]]},{"id":"d72767b0.3fa668","type":"debug","z":"e650e7b0.c39ae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":200,"wires":[]},{"id":"84138d0b.7d64a","type":"function","z":"e650e7b0.c39ae8","name":"傳送信息 MQTT2","func":"// CHANNEL_ACCESS_TOKEN = 'Messaging API Token';\n// USER_ID ='使用者ID(不是Line ID)';\n//MQTT2\nCHANNEL_ACCESS_TOKEN = 'UOf9DXSFQxPaDHLPl9jbsqj2Jhf9StEiqqjgLpa8PzKPsWaTAVwIRCmGfHXTkkuctxI1KLs8tc9kLU6VsWvSkCiydI0GQzaI2KnT3e4t7f8OVzy7wuj43qW+Eynp3V+QXKQdk2rZfB1T33fnT7crhwdB04t89/1O/w1cDnyilFU=';\nUSER_ID = 'Ua212f6426d82a75d31dee884a6fdfa95f76'; \nmessage = {\n type:'text',\n text: msg.payload\n};\nheaders = {\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,\n};\npayload = {\n 'to': USER_ID,\n 'messages': [message]\n};\nmsg.headers = headers;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":300,"wires":[["f7cde34f.82131","2e80e7cc.890338"]]},{"id":"f7cde34f.82131","type":"http request","z":"e650e7b0.c39ae8","name":"Messaging API 傳送","method":"POST","ret":"txt","paytoqs":false,"url":"https://api.line.me/v2/bot/message/push","tls":"","persist":false,"proxy":"","authType":"","x":680,"y":360,"wires":[["69a08235.940abc"]]},{"id":"69a08235.940abc","type":"debug","z":"e650e7b0.c39ae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":360,"wires":[]},{"id":"2e80e7cc.890338","type":"debug","z":"e650e7b0.c39ae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":880,"y":300,"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":""}]