2019年6月12日 星期三

利用Node-RED 取得 Opendata PM2.5 與UVI 的資料

取得 Opendata

基本上縣市政府網站,都有提供不少 Opendata 的資訊讓開發者使用,許多開發者喜歡到「政府資料開放平臺」上面去挖寶,或是「台北市政府資料開放平臺」,這兩個平台的開放資料都是相當完整且容易介接。

1).  http://opendata2.epa.gov.tw/AQI.json  PM2.5的資料
2). https://quality.data.gov.tw/dq_download_json.php?nid=6076&md5_url=c8abb41c2601d90af0635fc7b845048e   UVI的資料



          http://opendata2.epa.gov.tw/AQI.json


https://quality.data.gov.tw/dq_download_json.php?nid=6076&md5_url=c8abb41c2601d90af0635fc7b845048e

===================================================
function for PM2.5

var a = msg.payload;
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
if(h<10){
    h = '0'+h;
}
if(m<10){
    m = '0' + m;
}
if(s<10){
    s = '0' + s;
}
a.forEach(function(e,i){
    if(e.SiteName=='大里'){
        msg.pm25 ='大里 PM2.5 在(' + h + ':' + m + ':' + s + ') = '+ e['PM2.5'];
    }
});
return msg;

function for UVI


var a = msg.payload;

a.forEach(function(e,i){
    if(e.SiteName=='臺中'){
        msg.uvi ='臺中 UVI 在'+e['PublishTime']+'為' + e['UVI'];
    }
});

return msg;


function中的 msg.pm25 與debug node  msg.pm25 需相同




[{"id":"cedb4de0.de5af","type":"inject","z":"17bb63ed.68b25c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1500,"wires":[["6b83ebfe.0b9da4","51a79ec9.5069d"]]},{"id":"6b83ebfe.0b9da4","type":"http request","z":"17bb63ed.68b25c","name":"","method":"GET","ret":"obj","url":"http://opendata2.epa.gov.tw/AQI.json","tls":"","x":270,"y":1440,"wires":[["42e9019e.32813"]]},{"id":"51a79ec9.5069d","type":"http request","z":"17bb63ed.68b25c","name":"","method":"GET","ret":"obj","url":"https://quality.data.gov.tw/dq_download_json.php?nid=6076&md5_url=c8abb41c2601d90af0635fc7b845048e","tls":"","x":270,"y":1560,"wires":[["ec2c1865.45fe08"]]},{"id":"42e9019e.32813","type":"function","z":"17bb63ed.68b25c","name":"PM2.5","func":"var a = msg.payload;\nvar date = new Date();\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}\na.forEach(function(e,i){\n    if(e.SiteName=='大里'){\n        msg.pm25 ='大里 PM2.5 在(' + h + ':' + m + ':' + s + ') = '+ e['PM2.5'];\n    }\n});\nreturn msg;\n","outputs":1,"noerr":0,"x":430,"y":1440,"wires":[["6bfe282f.000698"]]},{"id":"ec2c1865.45fe08","type":"function","z":"17bb63ed.68b25c","name":"UVI","func":"var a = msg.payload;\n\na.forEach(function(e,i){\n    if(e.SiteName=='臺中'){\n        msg.uvi ='臺中 UVI 在'+e['PublishTime']+'為' + e['UVI'];\n    }\n});\nreturn msg;\n","outputs":1,"noerr":0,"x":430,"y":1560,"wires":[["b27f94ea.ea4d78"]]},{"id":"6bfe282f.000698","type":"debug","z":"17bb63ed.68b25c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"pm25","x":630,"y":1440,"wires":[]},{"id":"b27f94ea.ea4d78","type":"debug","z":"17bb63ed.68b25c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"uvi","x":620,"y":1560,"wires":[]}]

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

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