2020年9月2日 星期三

Node-Red 擷取 opendata UVI , PM2.5 資料

 Node-Red  擷取 opendata UVI , PM2.5 資料

細懸浮微粒資料(PM2.5) - 資料集- 政府開放資料彙整平台


紫外線即時監測資料 - OpenData.epa 行政院環境保護署環境 ...


http://opendata.epa.gov.tw/webapi/Data/REWIQA/?$orderby=SiteName&$skip=0&$top=1000&format=json


http://opendata.epa.gov.tw/webapi/Data/UV/?$orderby=PublishTime%20desc&$skip=0&$top=1000&format=json








[{"id":"1c2b6e37.6ea2b2","type":"tab","label":"流程11","disabled":false,"info":""},{"id":"c7beb438.d34c48","type":"http in","z":"1c2b6e37.6ea2b2","name":"get air","url":"/air","method":"get","upload":false,"swaggerDoc":"","x":57,"y":391,"wires":[["c311486e.b5b128","3b0616b9.b2919a"]]},{"id":"c311486e.b5b128","type":"http request","z":"1c2b6e37.6ea2b2","name":"air request","method":"GET","ret":"txt","paytoqs":false,"url":"http://opendata.epa.gov.tw/webapi/Data/REWIQA/?$orderby=SiteName&$skip=0&$top=1000&format=json","tls":"","persist":false,"proxy":"","authType":"","x":199,"y":391,"wires":[["b357e11e.6668f"]]},{"id":"92dda2e5.70ea5","type":"http response","z":"1c2b6e37.6ea2b2","name":"http out","x":677,"y":390,"wires":[]},{"id":"602de737.a55f98","type":"debug","z":"1c2b6e37.6ea2b2","name":"air process message","active":true,"tosidebar":true,"console":false,"complete":"payload","x":720,"y":440,"wires":[]},{"id":"75d09ec.530da6","type":"function","z":"1c2b6e37.6ea2b2","name":"air data process","func":"var n=context.global.airnum;\nvar data=msg.payload;\nvar JSONtostring = JSON.stringify(data);\nvar res = JSONtostring.replace(/PM2.5/gi, \"PM2point5\");\nvar airobj = JSON.parse(res);\n\nvar SiteName;\nvar County;\nvar PM2point5;\nvar time;\ntry{\nSiteName=airobj[n].SiteName;\nCounty=airobj[n].County;\nPM2point5=airobj[n].PM2point5;\ntime=airobj[n].PublishTime;\n}\ncatch(err)\n{\n SiteName=airobj[0].SiteName;\nCounty=airobj[0].County;\nPM2point5=airobj[0].PM2point5;\ntime=airobj[0].PublishTime;   \n}\n\nmsg.payload={\"SiteName\": County+SiteName, \"PM2point5\":PM2point5, \"time\":time};\n\n\n//msg.payload=airobj;\nreturn msg;","outputs":1,"noerr":0,"x":483,"y":390,"wires":[["92dda2e5.70ea5","602de737.a55f98"]]},{"id":"3b0616b9.b2919a","type":"function","z":"1c2b6e37.6ea2b2","name":"Set context.global.airnum","func":"context.global.airnum=msg.payload.airnum;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":320,"wires":[[]]},{"id":"b357e11e.6668f","type":"json","z":"1c2b6e37.6ea2b2","name":"json","property":"payload","action":"","pretty":false,"x":336,"y":391,"wires":[["75d09ec.530da6","89edb6cf.dd8678"]]},{"id":"89edb6cf.dd8678","type":"debug","z":"1c2b6e37.6ea2b2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":440,"wires":[]},{"id":"ac011c4d.2234d","type":"http in","z":"1c2b6e37.6ea2b2","name":"get UVI","url":"/UVI","method":"get","upload":false,"swaggerDoc":"","x":50,"y":660,"wires":[["70686fdd.57cb7","16774ab2.d92a35","f3de4ceb.8bc86"]]},{"id":"70686fdd.57cb7","type":"http request","z":"1c2b6e37.6ea2b2","name":"UVI request","method":"GET","ret":"txt","paytoqs":false,"url":"http://opendata.epa.gov.tw/webapi/Data/UV/?$orderby=PublishTime%20desc&$skip=0&$top=1000&format=json","tls":"","persist":false,"proxy":"","authType":"","x":210,"y":660,"wires":[["28e112a5.960fee","109b2a16.9bd006"]]},{"id":"6a257d6d.2e9c24","type":"http response","z":"1c2b6e37.6ea2b2","name":"","x":776,"y":658,"wires":[]},{"id":"109b2a16.9bd006","type":"debug","z":"1c2b6e37.6ea2b2","name":"UVImessage","active":true,"console":"false","complete":"payload","x":430,"y":700,"wires":[]},{"id":"28e112a5.960fee","type":"json","z":"1c2b6e37.6ea2b2","name":"json","x":415,"y":657,"wires":[["de962b20.519bc8","367c0763.30e168"]]},{"id":"de962b20.519bc8","type":"function","z":"1c2b6e37.6ea2b2","name":"UVI data process","func":"var n=context.global.uvnum;\nvar data=msg.payload;\nvar SiteName;\nvar UVI;\nvar County;\nvar time;\ntry\n{\nSiteName= data[n].SiteName;\nUVI= data[n].UVI;\nCounty=data[n].County;\ntime=data[n].PublishTime;\n}\ncatch(err) \n{\n SiteName= data[0].SiteName;\nUVI= data[0].UVI;\nCounty=data[0].County;\ntime=data[0].PublishTime;\n   \n}\n\n\nmsg.payload={\"SiteName\": County+SiteName, \"UVI\":UVI, \"time\":time};\n//msg.payload=data;\nreturn msg;","outputs":1,"noerr":0,"x":588,"y":659,"wires":[["6a257d6d.2e9c24","90169633.71f7a8"]]},{"id":"90169633.71f7a8","type":"debug","z":"1c2b6e37.6ea2b2","name":"UVI process message","active":true,"console":"false","complete":"payload","x":740,"y":720,"wires":[]},{"id":"16774ab2.d92a35","type":"function","z":"1c2b6e37.6ea2b2","name":"Set context.global.uvnum","func":"context.global.uvnum=msg.payload.uvnum;\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":600,"wires":[[]]},{"id":"f3de4ceb.8bc86","type":"debug","z":"1c2b6e37.6ea2b2","name":"monitor http in","active":true,"console":"false","complete":"payload","x":220,"y":720,"wires":[]},{"id":"367c0763.30e168","type":"debug","z":"1c2b6e37.6ea2b2","name":"jsonobject","active":true,"console":"false","complete":"payload","x":580,"y":600,"wires":[]}]

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...