2020年11月29日 星期日

Node-Red 擷取 空氣品質指數 AQI 數據

Node-Red 擷取 空氣品質指數 AQI 數據


https://opendata.epa.gov.tw/Data/Contents/AQI/


var loc= flow.get('Location');

flow.set("tempera",msg.payload);

var rawdata = flow.get("tempera");


var citynumber=rawdata.length;

var i;

var AQI,Status,PublishTime;


if (loc=== null) {

    loc='大里';

}



for (i=0; i<citynumber;i++)

{

    if (rawdata[i].SiteName===loc)

    {

        AQI=rawdata[i].AQI;

        Status=rawdata[i].Status;

        PublishTime=rawdata[i].PublishTime;

        break;

    }

}

msg.payload='地點 :' + loc +'空氣品質AQI='+ AQI+' , 空氣='+ Status + ' 發佈時間' +PublishTime ;

return msg;









[{"id":"1cb291e0.a2a27e","type":"inject","z":"72daf6a8.527e68","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":220,"wires":[["e9ce1e11.9cc13","e9cc41c8.708a1"]]},{"id":"e9ce1e11.9cc13","type":"http request","z":"72daf6a8.527e68","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://opendata.epa.gov.tw/webapi/Data/REWIQA/?$orderby=SiteName&$skip=0&$top=1000&format=json","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":100,"wires":[["2ecdccd3.50a154","29732d61.7fd372"]]},{"id":"2ecdccd3.50a154","type":"DataIn","z":"72daf6a8.527e68","collection":"bc9b0fb0.43472","name":"","update":false,"topic":"/PM25Data","x":530,"y":120,"wires":[]},{"id":"a58b9e80.2d45f","type":"DataOut","z":"72daf6a8.527e68","collection":"bc9b0fb0.43472","name":"","topic":"/PM25Data","error":false,"x":490,"y":300,"wires":[["73d8e1b7.e2aec","732ba94e.6dd2a8","e10ae21d.73ccb","7f10b072.cb50e"]]},{"id":"e9cc41c8.708a1","type":"trigger","z":"72daf6a8.527e68","name":"","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":330,"y":220,"wires":[["a58b9e80.2d45f"]]},{"id":"e34d884c.ed01f8","type":"function","z":"72daf6a8.527e68","name":"","func":"if (msg.payload === null)\n{\n    flow.set('Location','大里');\n}\nelse\n{\n    flow.set('Location',msg.payload);\n}\nnode.status({fill:\"green\",shape:\"dot\",text:msg.payload});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":300,"wires":[["a58b9e80.2d45f","70aea15c.5ec1b"]]},{"id":"5294ebd9.66fe94","type":"ui_dropdown","z":"72daf6a8.527e68","name":"","label":"選擇地點","tooltip":"","place":"Select option","group":"1cc27a89.bee075","order":63,"width":"3","height":"6","passthru":true,"multiple":false,"options":[{"label":"二林","value":"二林","type":"str"},{"label":"三義","value":"三義","type":"str"},{"label":"大里","value":"大里","type":"str"},{"label":"小港","value":"小港","type":"str"},{"label":"斗六","value":"斗六","type":"str"},{"label":"西屯","value":"西屯","type":"str"},{"label":"鳳山","value":"鳳山","type":"str"}],"payload":"","topic":"","x":140,"y":300,"wires":[["e34d884c.ed01f8"]]},{"id":"73d8e1b7.e2aec","type":"function","z":"72daf6a8.527e68","name":"","func":"var loc= flow.get('Location');\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\nvar AQI,Status,PublishTime;\n\nif (loc=== null) {\n    loc='大里';\n}\n\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName===loc)\n    {\n        AQI=rawdata[i].AQI;\n        Status=rawdata[i].Status;\n        PublishTime=rawdata[i].PublishTime;\n        break;\n    }\n}\n\nmsg.payload='地點 :' + loc +'空氣品質AQI='+ AQI+' , 空氣='+ Status + ' 發佈時間' +PublishTime ;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":300,"wires":[["2c69af24.32335","1141aa83.c1d7c5"]]},{"id":"3aeed31e.00f38c","type":"ui_button","z":"72daf6a8.527e68","name":"","group":"1cc27a89.bee075","order":12,"width":"4","height":"1","passthru":false,"label":"取得AQI資料","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":140,"y":100,"wires":[["e9ce1e11.9cc13","e9cc41c8.708a1"]]},{"id":"1141aa83.c1d7c5","type":"ui_text","z":"72daf6a8.527e68","group":"1cc27a89.bee075","order":10,"width":"20","height":"1","name":"","label":"空氣品質指標(AQI)","format":"{{msg.payload}}","layout":"row-left","x":870,"y":300,"wires":[]},{"id":"8fce20e0.5cc7e","type":"ui_gauge","z":"72daf6a8.527e68","name":"","group":"1cc27a89.bee075","order":62,"width":"6","height":"6","gtype":"gage","title":"PM10微克/立方公尺(μg/m3) ","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":900,"y":460,"wires":[]},{"id":"29732d61.7fd372","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":80,"wires":[]},{"id":"70aea15c.5ec1b","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":310,"y":360,"wires":[]},{"id":"732ba94e.6dd2a8","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"2c69af24.32335","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":260,"wires":[]},{"id":"84a09e78.89fff","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":340,"wires":[]},{"id":"ed62362c.491278","type":"debug","z":"72daf6a8.527e68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":420,"wires":[]},{"id":"c2dd4913.021288","type":"ui_gauge","z":"72daf6a8.527e68","name":"","group":"1cc27a89.bee075","order":14,"width":"6","height":"6","gtype":"gage","title":"AQI","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":830,"y":380,"wires":[]},{"id":"e10ae21d.73ccb","type":"function","z":"72daf6a8.527e68","name":"","func":"var loc= flow.get('Location');\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\nvar AQI,Status;\n\nif (loc=== null) {\n    loc='大里';\n}\n\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName===loc)\n    {\n        AQI=rawdata[i].AQI;\n        Status=rawdata[i].Status;\n        break;\n    }\n}\n\nmsg.payload= AQI;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":340,"wires":[["84a09e78.89fff","c2dd4913.021288"]]},{"id":"7f10b072.cb50e","type":"function","z":"72daf6a8.527e68","name":"","func":"var loc= flow.get('Location');\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\nvar PM10;\n\nif (loc=== null) {\n    loc='大里';\n}\n\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName===loc)\n    {\n        PM10=rawdata[i].PM10;\n        break;\n    }\n}\n\nmsg.payload= PM10;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":420,"wires":[["ed62362c.491278","8fce20e0.5cc7e"]]},{"id":"bc9b0fb0.43472","type":"json-db-collection","z":"","name":"DATA","collection":"DATA","save":true},{"id":"1cc27a89.bee075","type":"ui_group","z":"","name":"Info","tab":"2e8eb9a2.9f45f6","order":1,"disp":true,"width":"24","collapse":false},{"id":"2e8eb9a2.9f45f6","type":"ui_tab","z":"","name":"Weather","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...