2024年10月27日 星期日

OPEN DATA AQI 空氣品質監測網 + NODE-RED

OPEN DATA AQI 空氣品質監測網 + NODE-RED 


首頁 - 空氣品質監測網 https://airtw.moenv.gov.tw/

https://data.gov.tw/datasets/search?p=1&size=10&s=_score_desc&rft=AQI





https://data.gov.tw/dataset/40448



https://data.moenv.gov.tw/api/v2/aqx_p_432?api_key=e8dd42e6-9b8b-43f8-991e-b3dee723a52d&limit=1000&sort=ImportDate desc&format=CSV




https://data.moenv.gov.tw/api/v2/aqx_p_432?api_key=e8dd42e6-9b8b-43f8-991e-b3dee723a52d&limit=1000&sort=ImportDate desc&format=JSON





將pm2.5改成pm25   修改字體顏色 msg.color="red";

var a = context.global.aqi_records;

var site_name=global.get('site_Name');

var pm25;

a.forEach(function(e,i){

    if(e.sitename== site_name){

        pm25 = e['pm2.5'];

    }

});

msg.payload=pm25;

msg.color="red";

return msg;


修改字體顏色 msg.color="red";

<font color={{msg.color}}> <font SIZE=14> {{msg.payload}}


程式:

[{"id":"1a6d4e4dfeb2a89c","type":"inject","z":"e4a0cb7337ebc1ca","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":80,"wires":[["bdd41465f672e54b","05512d2d20bdc046"]]},{"id":"bdd41465f672e54b","type":"http request","z":"e4a0cb7337ebc1ca","name":"temp request","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://data.moenv.gov.tw/api/v2/aqx_p_432?api_key=e8dd42e6-9b8b-43f8-991e-b3dee723a52d&limit=1000&sort=ImportDate desc&format=JSON","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":270,"y":80,"wires":[["50bf4d2a7f40701e","2e1625eebcfbadb8"]]},{"id":"2e1625eebcfbadb8","type":"json","z":"e4a0cb7337ebc1ca","name":"","property":"payload","action":"","pretty":false,"x":450,"y":80,"wires":[["a5028a1af5858c50","00028a2228d705ba"]]},{"id":"27bbad2d119d1e8b","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":20,"wires":[]},{"id":"a5028a1af5858c50","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":40,"wires":[]},{"id":"00028a2228d705ba","type":"function","z":"e4a0cb7337ebc1ca","name":"Get records function ","func":"var msg1=msg.payload.records;\nmsg.payload=msg1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":80,"wires":[["27bbad2d119d1e8b","27277e7be99c652f","7658e8cd086cfb2d"]]},{"id":"50bf4d2a7f40701e","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":40,"wires":[]},{"id":"7658e8cd086cfb2d","type":"ui_table","z":"e4a0cb7337ebc1ca","group":"e25f0f5df917313b","name":"","order":1,"width":30,"height":15,"columns":[],"outputs":0,"cts":false,"x":850,"y":80,"wires":[]},{"id":"05512d2d20bdc046","type":"ui_dropdown","z":"e4a0cb7337ebc1ca","name":"","label":"","tooltip":"","place":"請選擇","group":"644296dd0b088d4a","order":1,"width":0,"height":0,"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"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"},{"label":"屏東(枋山)","value":"屏東(枋山)","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":120,"y":200,"wires":[["1fcb9a66b4cab783","a4250be6a72bb5cc","bdd41465f672e54b"]]},{"id":"406a82461ebb6127","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":160,"wires":[]},{"id":"1fcb9a66b4cab783","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":290,"y":160,"wires":[]},{"id":"a4250be6a72bb5cc","type":"function","z":"e4a0cb7337ebc1ca","name":"save sitename ","func":"var count=flow.get('siteName') || \"\";\nvar siteName=msg.payload;\nglobal.set('site_Name',siteName);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":200,"wires":[["406a82461ebb6127"]]},{"id":"27277e7be99c652f","type":"function","z":"e4a0cb7337ebc1ca","name":"Set context.global.aqi_records","func":"context.global.aqi_records=msg.payload;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":890,"y":120,"wires":[["c860954eba3df369","05347c3ee3a8e576"]]},{"id":"c860954eba3df369","type":"function","z":"e4a0cb7337ebc1ca","name":"get  Sitename  all records","func":"var rawdata = context.global.aqi_records;\nvar site_number=rawdata.length;\n\nvar site_name=global.get('site_Name');\n\nvar site_array=[];\nvar i;\nvar j=0;\n\nfor (i=0; i<site_number;i++)\n{\n    if (site_name==rawdata[i].sitename)\n    {\n      site_array[j]=rawdata[i];\n      j=j+1;\n    }\n}\n\nmsg.payload=site_array;\n//msg.payload= site_name; for debug\n \nflow.set(\"aqi_getdata\",site_array);\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":180,"wires":[["6517e50a61650d90","2db6c6e67d3f94ef","be07333b50c1cb52"]]},{"id":"6517e50a61650d90","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1110,"y":160,"wires":[]},{"id":"05347c3ee3a8e576","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":80,"wires":[]},{"id":"b4ab61d11191a319","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":2,"width":0,"height":0,"name":"","label":"county:","format":"{{msg.payload}}","layout":"row-left","className":"","x":1000,"y":240,"wires":[]},{"id":"3d95c6cd343b76ee","type":"function","z":"e4a0cb7337ebc1ca","name":"get   county","func":"\nvar county= msg.payload[0].county;\nmsg.payload=county;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":240,"wires":[["b4ab61d11191a319"]]},{"id":"3852fb5c8289ed21","type":"function","z":"e4a0cb7337ebc1ca","name":"get   aqi","func":"\nvar aqi= msg.payload[0].aqi;\nmsg.payload=aqi;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":280,"wires":[["cba30b1a0bf5e4a2"]]},{"id":"cba30b1a0bf5e4a2","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":3,"width":0,"height":0,"name":"","label":"aqi   :","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":280,"wires":[]},{"id":"2db6c6e67d3f94ef","type":"link out","z":"e4a0cb7337ebc1ca","name":"link out 60","mode":"link","links":["aa70689dc1280f43"],"x":1045,"y":200,"wires":[]},{"id":"aa70689dc1280f43","type":"link in","z":"e4a0cb7337ebc1ca","name":"link in 58","links":["2db6c6e67d3f94ef"],"x":515,"y":420,"wires":[["3d95c6cd343b76ee","3852fb5c8289ed21","d017f0b0b70ef380","283db37d57500bcd","817b71e58522ab11","7718658e755291db","af256cb701db155d","ea3c8ea89d323a22","b304e296422ceb9f","03e94ca4c106cb7b","2ff4bf6824d17fc5","dc6bc4529078d47e","e9290affe8d87f7a"]]},{"id":"283db37d57500bcd","type":"function","z":"e4a0cb7337ebc1ca","name":"get  status","func":"\nvar status= msg.payload[0].status;\nmsg.payload=status;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":360,"wires":[["79cfc87ecd3257ed"]]},{"id":"79cfc87ecd3257ed","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":5,"width":0,"height":0,"name":"","label":"status:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":360,"wires":[]},{"id":"d017f0b0b70ef380","type":"function","z":"e4a0cb7337ebc1ca","name":"get  pollutan","func":"\nvar pollutan= msg.payload[0].pollutan;\nmsg.payload=pollutan;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":320,"wires":[["a1d62d271bd99d2a"]]},{"id":"a1d62d271bd99d2a","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":4,"width":0,"height":0,"name":"","label":"pollutan:","format":"{{msg.payload}}","layout":"row-left","className":"","x":1000,"y":320,"wires":[]},{"id":"817b71e58522ab11","type":"function","z":"e4a0cb7337ebc1ca","name":"get  so2","func":"\nvar so2= msg.payload[0].so2;\nmsg.payload=so2;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":400,"wires":[["686ede1bd8e554f0"]]},{"id":"686ede1bd8e554f0","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":6,"width":0,"height":0,"name":"","label":"so2:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":400,"wires":[]},{"id":"7718658e755291db","type":"function","z":"e4a0cb7337ebc1ca","name":"get  nox","func":"\nvar nox= msg.payload[0].nox;\nmsg.payload=nox;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":600,"wires":[["2aad8b7a709ac247"]]},{"id":"2aad8b7a709ac247","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":12,"width":0,"height":0,"name":"","label":"nox:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":600,"wires":[]},{"id":"af256cb701db155d","type":"function","z":"e4a0cb7337ebc1ca","name":"get  co","func":"\nvar co= msg.payload[0].co;\nmsg.payload=co;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":440,"wires":[["babf1fe30aa0fd05"]]},{"id":"babf1fe30aa0fd05","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":7,"width":0,"height":0,"name":"","label":"co:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":440,"wires":[]},{"id":"ea3c8ea89d323a22","type":"function","z":"e4a0cb7337ebc1ca","name":"get  o3","func":"\nvar o3= msg.payload[0].o3;\nmsg.payload=o3;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":480,"wires":[["faa2ddbc2970a3be"]]},{"id":"faa2ddbc2970a3be","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":8,"width":0,"height":0,"name":"","label":"o3:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":480,"wires":[]},{"id":"b304e296422ceb9f","type":"function","z":"e4a0cb7337ebc1ca","name":"get  pm10","func":"\nvar pm10= msg.payload[0].pm10;\nmsg.payload=pm10;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":520,"wires":[["7eba1341c7e63f50"]]},{"id":"7eba1341c7e63f50","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":9,"width":0,"height":0,"name":"","label":"pm10:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":520,"wires":[]},{"id":"04052761df475c81","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":10,"width":0,"height":0,"name":"","label":"pm2.5:","format":"<font color={{msg.color}}> <font SIZE=14> {{msg.payload}}","layout":"row-left","className":"","x":1170,"y":300,"wires":[]},{"id":"03e94ca4c106cb7b","type":"function","z":"e4a0cb7337ebc1ca","name":"get  no2","func":"\nvar no2= msg.payload[0].no2;\nmsg.payload=no2;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":560,"wires":[["df445568a6efc59b"]]},{"id":"df445568a6efc59b","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":11,"width":0,"height":0,"name":"","label":"no2","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":560,"wires":[]},{"id":"2ff4bf6824d17fc5","type":"function","z":"e4a0cb7337ebc1ca","name":"get  no","func":"\nvar no= msg.payload[0].no;\nmsg.payload=no;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":640,"wires":[["c2e7c6f50b7364ad"]]},{"id":"c2e7c6f50b7364ad","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":12,"width":0,"height":0,"name":"","label":"no:","format":"{{msg.payload}}","layout":"row-left","className":"","x":990,"y":640,"wires":[]},{"id":"dc6bc4529078d47e","type":"function","z":"e4a0cb7337ebc1ca","name":"get wind_speed","func":"\nvar wind_speed= msg.payload[0].wind_speed;\nmsg.payload=wind_speed;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":680,"wires":[["2b2355e086857a86"]]},{"id":"2b2355e086857a86","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":12,"width":0,"height":0,"name":"","label":"wind_speed:","format":"{{msg.payload}}","layout":"row-left","className":"","x":1010,"y":680,"wires":[]},{"id":"e9290affe8d87f7a","type":"function","z":"e4a0cb7337ebc1ca","name":"get wind_direc","func":"msg.color=\"red\";\nvar wind_direc= msg.payload[0].wind_direc;\nmsg.payload=wind_direc;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":720,"wires":[["3511d61f45c7e808"]]},{"id":"3511d61f45c7e808","type":"ui_text","z":"e4a0cb7337ebc1ca","group":"644296dd0b088d4a","order":12,"width":0,"height":0,"name":"","label":"wind_direc:","format":"<font color={{msg.color}}> {{msg.payload}}","layout":"row-left","className":"","x":1010,"y":720,"wires":[]},{"id":"be07333b50c1cb52","type":"function","z":"e4a0cb7337ebc1ca","name":"function get pm2.5","func":"var a = context.global.aqi_records;\nvar site_name=global.get('site_Name');\nvar pm25;\na.forEach(function(e,i){\n    if(e.sitename== site_name){\n        pm25 = e['pm2.5'];\n    }\n});\nmsg.payload=pm25;\nmsg.color=\"red\";\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1170,"y":200,"wires":[["04052761df475c81","a7f7fa6e0afc7fba"]]},{"id":"a7f7fa6e0afc7fba","type":"debug","z":"e4a0cb7337ebc1ca","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1330,"y":180,"wires":[]},{"id":"e25f0f5df917313b","type":"ui_group","name":"Default","tab":"846ca1f8a495a33e","order":2,"disp":true,"width":30,"collapse":false,"className":""},{"id":"644296dd0b088d4a","type":"ui_group","name":"SiteName","tab":"846ca1f8a495a33e","order":1,"disp":true,"width":"3","collapse":false,"className":""},{"id":"846ca1f8a495a33e","type":"ui_tab","name":"空氣品質指標","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...