2021年8月25日 星期三

Node-Red 擷取空氣品質指標(AQI)的opendata 中的83個陣列資料中的台中市的5個Sitename中相關的7個欄位資料擷取,並定期2小時送至Line Notify

 Node-Red 擷取空氣品質指標(AQI)的opendata 中的83個陣列資料中的台中市的5個Sitename中相關的7個欄位資料擷取,再選擇5站其中一站 展示於 UI 上 並定期2小時送至Line Notify







[{"id":"75e765f7.d089fc","type":"inject","z":"63963f52.edd65","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"7200","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":140,"wires":[["c4293ab0.cc70b8"]]},{"id":"c4293ab0.cc70b8","type":"http request","z":"63963f52.edd65","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://data.epa.gov.tw/api/v1/aqx_p_432?limit=1000&api_key=9be7b239-557b-4c10-9775-78cadfc555e9&sort=ImportDate%20desc&format=json","tls":"","persist":false,"proxy":"","authType":"","x":300,"y":140,"wires":[["b60a9bf1.ff0798"]]},{"id":"f3985ede.7f10a","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":180,"wires":[]},{"id":"2ec34186.229bde","type":"function","z":"63963f52.edd65","name":"","func":"var a = msg.payload;\nlet arr = [];\nlet obj;\n\na.forEach(function(e,i){\n    if(e.County=='臺中市')\n    {\n        obj = {}\n        obj.SiteName = e.SiteName;\n        obj.AQI = e.AQI;\n        obj.Status = e.Status;\n        obj.SO2 = e.SO2;        \n        obj.PM10 = e.PM10;\n        obj.PM25 = e['PM2.5'];\n        obj.PublishTime=e.PublishTime;\n        \n        arr.push(obj)         \n        \n        //msg.PM25 = e['PM2.5'];\n        //msg.PublishTime = e['PublishTime'];\n    }\n    msg.payload = arr;\n});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":200,"wires":[["f3985ede.7f10a","267727c0.7adae8"]]},{"id":"b60a9bf1.ff0798","type":"json","z":"63963f52.edd65","name":"","property":"payload","action":"","pretty":false,"x":430,"y":140,"wires":[["bfacf93c.4e70f8"]]},{"id":"a5172131.f1236","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":140,"wires":[]},{"id":"bfacf93c.4e70f8","type":"function","z":"63963f52.edd65","name":"","func":"msg.payload=msg.payload.records;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":140,"wires":[["2ec34186.229bde","a5172131.f1236"]]},{"id":"4a2bf719.a08ff8","type":"function","z":"63963f52.edd65","name":"Format timestamp","func":"var date = new Date();\n//var h = date.getHours()+8;\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 + msg.PM25 + ' --> Time:(' + h + ':' + m + ':' + s + ')' ;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":340,"wires":[["b197a382.36a5b"]]},{"id":"b197a382.36a5b","type":"function","z":"63963f52.edd65","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer UsNew4h6FT1BsUPQRg402XBN3vJ1JaAFLSst2W3QCpLKFS'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":340,"wires":[["b2e90492.f772e8"]]},{"id":"b2e90492.f772e8","type":"http request","z":"63963f52.edd65","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":660,"y":340,"wires":[["b40b956f.365c38"]]},{"id":"b40b956f.365c38","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":340,"wires":[]},{"id":"a822b090.7f475","type":"ui_dropdown","z":"63963f52.edd65","name":"","label":"","tooltip":"","place":"請選擇地點","group":"f4ddc713.cb9a58","order":0,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":520,"y":440,"wires":[["7007b385.1cbd8c"]]},{"id":"ec8188d8.2b6768","type":"inject","z":"63963f52.edd65","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.5","topic":"","payload":"","payloadType":"date","x":130,"y":440,"wires":[["377262e8.6b7f1e"]]},{"id":"377262e8.6b7f1e","type":"change","z":"63963f52.edd65","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"[\"豐原\", \"沙鹿\",\"大里\",\"忠明\",\"西屯\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":440,"wires":[["a822b090.7f475","3a9d35c3.a2c6da"]]},{"id":"3a9d35c3.a2c6da","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","x":530,"y":500,"wires":[]},{"id":"267727c0.7adae8","type":"function","z":"63963f52.edd65","name":"set global temp","func":"context.global.AQItemp=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":760,"y":220,"wires":[[]]},{"id":"7007b385.1cbd8c","type":"function","z":"63963f52.edd65","name":"","func":"var a = context.global.AQItemp;\nvar b = msg.payload;\na.forEach(function(e,i){\n    if(e.SiteName==b)\n    {\n        msg.SiteName = e.SiteName;\n        msg.AQI = e.AQI;\n        msg.Status = e.Status;\n        msg.SO2 = e.SO2;        \n        msg.PM10 = e.PM10;\n        msg.PM25 = e['PM25'];\n        msg.PublishTime=e.PublishTime;\n\n    }\n\n});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":440,"wires":[["d3ebfff9.6ba2e","87a47a7e.ea75c8","e72dfe7b.0c662"]]},{"id":"d3ebfff9.6ba2e","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":500,"wires":[]},{"id":"7474bb85.19b474","type":"json","z":"63963f52.edd65","name":"","property":"payload","action":"str","pretty":false,"x":150,"y":340,"wires":[["4a2bf719.a08ff8","47567f25.9d4fa"]]},{"id":"47567f25.9d4fa","type":"ui_text","z":"63963f52.edd65","group":"f4ddc713.cb9a58","order":4,"width":0,"height":0,"name":"","label":"台中5站之","format":"{{msg.payload}}","layout":"row-spread","x":290,"y":280,"wires":[]},{"id":"87a47a7e.ea75c8","type":"function","z":"63963f52.edd65","name":"","func":"var PM25;\nPM25 = msg.PM25;                    \nmsg.payload=PM25;\nreturn  msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":810,"y":440,"wires":[["60c9ebf0.384664","6bfb87d4.6df4c8"]]},{"id":"60c9ebf0.384664","type":"ui_gauge","z":"63963f52.edd65","name":"","group":"f4ddc713.cb9a58","order":5,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":950,"y":440,"wires":[]},{"id":"6bfb87d4.6df4c8","type":"debug","z":"63963f52.edd65","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":400,"wires":[]},{"id":"e72dfe7b.0c662","type":"function","z":"63963f52.edd65","name":"","func":"msg.payload=[ \"站名 :\" +msg.SiteName , \"空氣品質指數 : \" + msg.AQI ,\"空氣品質 : \" + msg.Status , \"SO2 : \" + msg.SO2 , \"PM10 : \"+ msg.PM10 , \"PM2.5 : \" + msg.PM25 , \"發行時間 \" + msg.PublishTime   ] ;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":150,"y":380,"wires":[["7474bb85.19b474"]]},{"id":"f4ddc713.cb9a58","type":"ui_group","name":"AQI","tab":"763667c5.ae1af8","order":1,"disp":true,"width":"6","collapse":false},{"id":"763667c5.ae1af8","type":"ui_tab","name":"LAB","icon":"dashboard"}]

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...