2021年8月25日 星期三

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

 

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

 



空氣品質指標(AQI)

每小時提供各測站之空氣品質指標(AQI),原始資料版本公告於空氣品質監測網https://airtw.epa.gov.tw

https://data.epa.gov.tw/api/v1/aqx_p_432?limit=1000&api_key=9be7b239-557b-4c10-9775-78cadfc555e9&sort=ImportDate%20desc&format=json

 

原有的資料



第一次擷取資料



Node名稱

設定

 備註

http請求

GET

https://data.epa.gov.tw/api/v1/aqx_p_432?limit=1000&api_key=9be7b239-557b-4c10-9775-78cadfc555e9&sort=ImportDate%20desc&format=json

UTF-8字串

 

Json

JSON字串與物件object互轉

 

函數

msg.payload=msg.payload.records;

return msg;

擷取msg.payload.records的欄位其他的捨去

第一次擷取後資料

array[83]

[0 … 9]

0: object

SiteName: "基隆"

County: "基隆市"

AQI: "45"

Pollutant: ""

Status: "良好"

SO2: "3.2"

CO: "0.17"

CO_8hr: "0.2"

O3: "47.6"

O3_8hr: "33"

PM10: "48"

PM2.5: "21"

NO2: "5.8"

NOx: "7"

NO: "1.2"

WindSpeed: "1.2"

WindDirec: "5"

PublishTime: "2021/08/25 14:00:00"

PM2.5_AVG: "13"

PM10_AVG: "24"

SO2_AVG: "1"

Longitude: "121.760056"

Latitude: "25.129167"

SiteId: "1"

ImportDate: "2021-08-25 14:53:02.253000"

 



Node名稱

設定

 備註

函數

var a = msg.payload;

let arr = [];

let obj;

 

a.forEach(function(e,i){

    if(e.County=='臺中市')

    {

        obj = {}

        obj.SiteName = e.SiteName;

        obj.AQI = e.AQI;

        obj.Status = e.Status;

        obj.SO2 = e.SO2;       

        obj.PM10 = e.PM10;

        obj.PM25 = e['PM2.5'];

        obj.PublishTime=e.PublishTime;

       

        arr.push(obj)         

       

    }

    msg.payload = arr;

});

return msg;

 

 

 

 

第二次擷取後資料 (剩下台中市的5筆資料 每一筆共7個欄位)

SiteName: "豐原"   AQI: "49"    Status: "良好"    SO2: "2.5"   PM10: "38"   PM25: "21" PublishTime: "2021/08/25 14:00:00"

 

array[5]

0: object

SiteName: "豐原"

AQI: "49"

Status: "良好"

SO2: "2.5"

PM10: "38"

PM25: "21"

PublishTime: "2021/08/25 14:00:00"

1: object

2: object

3: object

4: object


[{"id":"75e765f7.d089fc","type":"inject","z":"63963f52.edd65","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"7200","crontab":"","once":false,"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":"b60a9bf1.ff0798","type":"json","z":"63963f52.edd65","name":"","property":"payload","action":"","pretty":false,"x":430,"y":140,"wires":[["bfacf93c.4e70f8"]]},{"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":"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":220,"wires":[["f3985ede.7f10a","ee13afc2.04bce"]]},{"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":"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":220,"wires":[]}]

沒有留言:

張貼留言

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

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