2020年11月28日 星期六

Node-Red 擷取 open data 即時天氣狀況暨溫濕度

 Node-Red 擷取 open data 即時天氣狀況暨溫濕度

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

https://opendata.epa.gov.tw/webapi/api/rest/datastore/355000000I-000272?offset=0&limit=1000

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













//==================================

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

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

var citynumber=rawdata.length;

var cityarray=[];

var i;

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

{

    cityarray[i]=rawdata[i].SiteName;

}

msg.payload=cityarray;

flow.set("loname",cityarray);

return msg;

//==================================

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

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

var citynumber=rawdata.length;

var i;

var Temp;

var Mois;

var Weat;

var dataDate;

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

{

    if (rawdata[i].SiteName==='臺中')

    {

        Temp=rawdata[i].Temperature;

        Mois=rawdata[i].Moisture;

        Weat=rawdata[i].Weather;

        dataDate=rawdata[i].DataCreationDate;

        break;

    }

}

msg.payload='溫度='+Temp+'°C , 濕度='+Mois+'% , 天氣'+ Weat+ ' , 發佈時間' + dataDate;

return msg;

//==================================

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

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

var citynumber=rawdata.length;

var i;

var Temp;

var Mois;

var Weat;

var dataDate;

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

{

    if (rawdata[i].SiteName==='臺中')

    {

        Temp=rawdata[i].Temperature;

        Mois=rawdata[i].Moisture;

        Weat=rawdata[i].Weather;

        dataDate=rawdata[i].DataCreationDate;

        break;

    }

}

msg.payload= Mois;

return msg;

//=================================

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

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

var citynumber=rawdata.length;

var i;

var Temp;

var Mois;

var Weat;

var dataDate;


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

{

    if (rawdata[i].SiteName==='臺中')

    {

        Temp=rawdata[i].Temperature;

        Mois=rawdata[i].Moisture;

        Weat=rawdata[i].Weather;

        dataDate=rawdata[i].DataCreationDate;

        break;

    }

}

msg.payload= Temp;

return msg;


//================================

[{"id":"7243489f.6a8558","type":"ui_button","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":2,"width":"0","height":"0","passthru":false,"label":"取得台中市天氣(等待約30秒以上)","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":240,"y":160,"wires":[["e76cbb94.d60f98","80baac1d.e7688"]]},{"id":"84ad41ed.d8693","type":"ui_gauge","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":3,"width":"4","height":"4","gtype":"gage","title":"溫度","label":"°C","format":"{{value}}","min":0,"max":"50","colors":["#00b395","#e6e600","#ca3838"],"seg1":"28","seg2":"38","x":810,"y":380,"wires":[]},{"id":"4a7a499d.a293c8","type":"ui_gauge","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":62,"width":"4","height":"4","gtype":"gage","title":"濕度","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"35","seg2":"70","x":810,"y":300,"wires":[]},{"id":"913afbcc.1196b8","type":"inject","z":"c1b84172.51787","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":60,"wires":[["e76cbb94.d60f98"]]},{"id":"e76cbb94.d60f98","type":"http request","z":"c1b84172.51787","name":"temp request","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://opendata.epa.gov.tw/webapi/Data/ATM00698/?$skip=0&$top=1000&format=json","tls":"","persist":false,"proxy":"","authType":"","x":310,"y":60,"wires":[["a47cf11c.57984"]]},{"id":"d73f973e.ef0298","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":60,"wires":[]},{"id":"a47cf11c.57984","type":"json","z":"c1b84172.51787","name":"","property":"payload","action":"","pretty":false,"x":470,"y":60,"wires":[["d73f973e.ef0298","87a5a900.ec7548","4bb9abf5.b29bf4","5a2d58c3.44eba8","1165f3d8.b0bf0c"]]},{"id":"87a5a900.ec7548","type":"function","z":"c1b84172.51787","name":"List locationname","func":"\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar cityarray=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\n    cityarray[i]=rawdata[i].SiteName;\n}\n\nmsg.payload=cityarray;\nflow.set(\"loname\",cityarray);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":120,"wires":[["9cf7ec6a.de0ec"]]},{"id":"9cf7ec6a.de0ec","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":120,"wires":[]},{"id":"4bb9abf5.b29bf4","type":"function","z":"c1b84172.51787","name":"取得天氣溫濕度","func":"\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\n\nvar Temp;\nvar Mois;\nvar Weat;\nvar dataDate;\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName==='臺中')\n    {\n        Temp=rawdata[i].Temperature;\n        Mois=rawdata[i].Moisture;\n        Weat=rawdata[i].Weather;\n        dataDate=rawdata[i].DataCreationDate;\n        break;\n    }\n}\n\nmsg.payload='溫度='+Temp+'°C , 濕度='+Mois+'% , 天氣'+ Weat+ ' , 發佈時間' + dataDate;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":180,"wires":[["bfd558bd.5f41e8","b3f9559b.085eb8"]]},{"id":"bfd558bd.5f41e8","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":180,"wires":[]},{"id":"b3f9559b.085eb8","type":"ui_text","z":"c1b84172.51787","group":"1cc27a89.bee075","order":0,"width":"12","height":"2","name":"","label":"","format":"{{msg.payload}}","layout":"col-center","x":810,"y":220,"wires":[]},{"id":"80baac1d.e7688","type":"function","z":"c1b84172.51787","name":"清除","func":"msg.payload='  ';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":380,"wires":[["b3f9559b.085eb8","4a7a499d.a293c8","84ad41ed.d8693"]]},{"id":"5a2d58c3.44eba8","type":"function","z":"c1b84172.51787","name":"濕度","func":"\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\n\nvar Temp;\nvar Mois;\nvar Weat;\nvar dataDate;\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName==='臺中')\n    {\n        Temp=rawdata[i].Temperature;\n        Mois=rawdata[i].Moisture;\n        Weat=rawdata[i].Weather;\n        dataDate=rawdata[i].DataCreationDate;\n        break;\n    }\n}\nmsg.payload= Mois;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":260,"wires":[["4a7a499d.a293c8","67014f63.76a22"]]},{"id":"67014f63.76a22","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":260,"wires":[]},{"id":"1165f3d8.b0bf0c","type":"function","z":"c1b84172.51787","name":"溫度","func":"\nflow.set(\"tempera\",msg.payload);\nvar rawdata = flow.get(\"tempera\");\n\nvar citynumber=rawdata.length;\nvar i;\n\nvar Temp;\nvar Mois;\nvar Weat;\nvar dataDate;\n\nfor (i=0; i<citynumber;i++)\n{\n    if (rawdata[i].SiteName==='臺中')\n    {\n        Temp=rawdata[i].Temperature;\n        Mois=rawdata[i].Moisture;\n        Weat=rawdata[i].Weather;\n        dataDate=rawdata[i].DataCreationDate;\n        break;\n    }\n}\nmsg.payload= Temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":340,"wires":[["84ad41ed.d8693","47ae54e5.c08f6c"]]},{"id":"47ae54e5.c08f6c","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":340,"wires":[]},{"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}]




沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...