2020年8月30日 星期日

利用 Node-RED 結合 Line Bot,在匯率低於數值時自動傳送信息。

利用 Node-RED 結合 Line Bot,在匯率低於數值時自動傳送信息。

使用 Node-RED 從台灣銀行網站自動抓取日幣匯率,結合 Messaging API 可以做到當日幣匯率低於一個數值時自動發送信息到你的手機。



參考來源 https://blog.hanlee.co/node-red-line-bot-jpy-currency/






[{"id":"639381b4.decba","type":"inject","z":"2fe5a795.b44618","name":"","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":120,"wires":[["63a4a95.925ad58"]]},{"id":"63a4a95.925ad58","type":"http request","z":"2fe5a795.b44618","name":"","method":"GET","ret":"txt","url":"http://rate.bot.com.tw/xrt?Lang=zh-TW","tls":"","x":240,"y":120,"wires":[["38a8cc.2269c734"]]},{"id":"38a8cc.2269c734","type":"html","z":"2fe5a795.b44618","name":"filter","property":"payload","outproperty":"payload","tag":".rate-content-cash.text-right.print_hide","ret":"html","as":"single","x":370,"y":120,"wires":[["29ecf860.b24508","91e26219.6161e"]]},{"id":"29ecf860.b24508","type":"function","z":"2fe5a795.b44618","name":"Get JPY Currency 1","func":"var currency = 0.20;\n\nvar data = {\n    jpy: Number(msg.payload[15])\n}\n\nvar isLow =  flow.get('isLow') || false;\nmsg.payload = data\nif (data.jpy < currency && !isLow) {\n    isLow = true;\n    flow.set('isLow', isLow);\n    return msg;\n}\nif (data.jpy > currency && !isLow) {\n    isLow = false;\n    flow.set('isLow', isLow);\n    return msg;\n}","outputs":1,"noerr":0,"x":540,"y":120,"wires":[["8dc39773.503288"]]},{"id":"1d418e6a.0e52a2","type":"debug","z":"2fe5a795.b44618","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":730,"y":60,"wires":[]},{"id":"8dc397w373.5403288","type":"function","z":"2fe45a795.b444618","name":"傳送信息","func":"//CHANNEL_ACCESS_TOKEN = 'Messaging API Token';\nCHANNEL_ACCESS_TOKEN = 'E2ElxCQeoDszSHF0N1TJsyytnnae+HF1XZ7334YVYj1RQcpjAT1oi2Fa24TScNbOz+q815fFVp4MuFW+UC4PsfKbvtc/o0OM6hchpxuQURZyvizGq+/cAz/TgCwJ9wQ4ebkQyEXEDzaYUZ/Dx3yaaBgwdB04t89/1O/w1cDnyilFU=';\nUSER_ID = 'Ua2f646d82a75d31dee884a6fdfa95f76'; //'使用者ID(不是Line ID)';\nmessage = {\n    type:'text',\n    text:'目前日圓匯率:'+msg.payload.jpy\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":740,"y":160,"wires":[["ea9fccf4.509b4"]]},{"id":"ea9fccf4.509b4","type":"http request","z":"2fe5a795.b44618","name":"Messaging API 傳送","method":"POST","ret":"txt","paytoqs":false,"url":"https://api.line.me/v2/bot/message/push","tls":"","persist":false,"proxy":"","authType":"","x":580,"y":240,"wires":[["5c8619a1.7b35a8"]]},{"id":"a3af338a.4308","type":"http in","z":"2fe5a795.b44618","name":"Messaging API 接收","url":"/line_hook","method":"post","upload":false,"swaggerDoc":"","x":110,"y":320,"wires":[["3774c8fd.50b198"]]},{"id":"3774c8fd.50b198","type":"debug","z":"2fe5a795.b44618","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":310,"y":320,"wires":[]},{"id":"69e3a5fb.06462c","type":"inject","z":"2fe5a795.b44618","name":"發送測試信息","topic":"","payload":"{\"jpy\":\"測試信息\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":470,"y":160,"wires":[["8dc39773.503288"]]},{"id":"5c8619a1.7b35a8","type":"debug","z":"2fe5a795.b44618","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":580,"y":320,"wires":[]},{"id":"91e26219.6161e","type":"function","z":"2fe5a795.b44618","name":"GET JP Currency 2","func":"//var jp = msg.payload[15];\nvar data = {\n    jpy: Number(msg.payload[15])\n}\nvar date = new Date();\nmsg.payload = data\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 = '(' + h + ':' + m + ':' + s + ')\\n'+\n'日幣匯率:' + data.jpy ;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":60,"wires":[["1d418e6a.0e52a2"]]}]



沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...