2020年12月6日 星期日

Node-Red 擷取opendata 臺中天氣狀況

 Node-Red 擷取opendata 臺中天氣狀況






[{"id":"f730830d.af134","type":"inject","z":"a4386a37.afa5d8","name":"","repeat":"7200","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["bc600d7b.beacb"]]},{"id":"bc600d7b.beacb","type":"http request","z":"a4386a37.afa5d8","name":"temp request","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://opendata.cwb.gov.tw/govdownload?dataid=F-C0032-001&authorizationkey=rdec-key-123-45678-011121314","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":160,"wires":[["97e171b9.cbd32"]]},{"id":"97e171b9.cbd32","type":"xml","z":"a4386a37.afa5d8","name":"","property":"payload","attr":"","chr":"","x":450,"y":160,"wires":[["5c0012ef.a6f77c"]]},{"id":"5c0012ef.a6f77c","type":"function","z":"a4386a37.afa5d8","name":"set global temp","func":"flow.set(\"tempera\",msg.payload);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":160,"wires":[["7608def6.176f6","4fd325ef.93afcc","bdb68abc.ec3dc8","b7eed092.b5053"]]},{"id":"41f10914.de2e38","type":"http in","z":"a4386a37.afa5d8","name":"tempjson","url":"/tempjson","method":"get","upload":false,"swaggerDoc":"","x":100,"y":240,"wires":[["491704aa.830c6c"]]},{"id":"491704aa.830c6c","type":"function","z":"a4386a37.afa5d8","name":"show raw data","func":"\nvar rawdata = flow.get(\"tempera\");\nmsg.payload = rawdata;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":240,"wires":[["3663007d.d3b04","acb29ba7.e08ee8"]]},{"id":"3663007d.d3b04","type":"http response","z":"a4386a37.afa5d8","name":"http out","x":480,"y":240,"wires":[]},{"id":"acb29ba7.e08ee8","type":"debug","z":"a4386a37.afa5d8","name":"temp data process","active":true,"console":"false","complete":"payload","x":330,"y":320,"wires":[]},{"id":"7608def6.176f6","type":"function","z":"a4386a37.afa5d8","name":"","func":"var loc= 3 ;  //3= 台中市\n//var rawdata=context.global.temp;\nvar rawdata = flow.get(\"tempera\");\nvar locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\nvar period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].startTime[0];\nvar period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].endTime[0];\n\nvar  starthourtemp= period0start.split(\"T\");\nvar  starthour=starthourtemp[1].split(\":\")[0];\nvar  endhourtemp= period0end.split(\"T\");\nvar  endhour=endhourtemp[1].split(\":\")[0];\n\nmsg.payload=period0max;\n\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":770,"y":160,"wires":[["17751112.02444f","172cca86.9f42c5"],[]]},{"id":"17751112.02444f","type":"ui_gauge","z":"a4386a37.afa5d8","name":"","group":"f3abc179.82f69","order":1,"width":0,"height":0,"gtype":"gage","title":"高溫","label":"units","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"26","seg2":"38","x":910,"y":120,"wires":[]},{"id":"7267f40b.ef81dc","type":"ui_gauge","z":"a4386a37.afa5d8","name":"","group":"f3abc179.82f69","order":3,"width":0,"height":0,"gtype":"gage","title":"低溫","label":"units","format":"{{value}}","min":0,"max":"50","colors":["#b3001b","#e6e600","#3acb43"],"seg1":"15","seg2":"38","x":910,"y":200,"wires":[]},{"id":"4fd325ef.93afcc","type":"function","z":"a4386a37.afa5d8","name":"","func":"var loc= 3 ;  //3= 台中市\n//var rawdata=context.global.temp;\nvar rawdata = flow.get(\"tempera\");\nvar locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\nvar period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].startTime[0];\nvar period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].endTime[0];\n\nvar  starthourtemp= period0start.split(\"T\");\nvar  starthour=starthourtemp[1].split(\":\")[0];\nvar  endhourtemp= period0end.split(\"T\");\nvar  endhour=endhourtemp[1].split(\":\")[0];\nvar  S_Date = period0start.substr(0,10);\nvar  E_Date = period0end.substr(0,10);\n\nmsg.payload=locationName+S_Date+ ' , ' + starthour+\"點 到\"+E_Date+' , ' + endhour+\"點, 溫度最低\"+period0min+\"度 ,溫度最高\"+period0max+\"度\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":300,"wires":[["a531a0b2.645e9","16d1ec32.b9d904"]]},{"id":"a531a0b2.645e9","type":"ui_text","z":"a4386a37.afa5d8","group":"f3abc179.82f69","order":0,"width":"8","height":"3","name":"","label":"臺中市天氣: ","format":"{{msg.payload}}","layout":"row-spread","x":930,"y":300,"wires":[]},{"id":"16d1ec32.b9d904","type":"debug","z":"a4386a37.afa5d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":340,"wires":[]},{"id":"bdb68abc.ec3dc8","type":"debug","z":"a4386a37.afa5d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"477ef9dd.e704d8","type":"ui_button","z":"a4386a37.afa5d8","name":"","group":"f3abc179.82f69","order":5,"width":0,"height":0,"passthru":false,"label":"擷取臺中的天氣","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":150,"y":120,"wires":[["bc600d7b.beacb"]]},{"id":"172cca86.9f42c5","type":"debug","z":"a4386a37.afa5d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":160,"wires":[]},{"id":"cf2d30c1.5cde8","type":"debug","z":"a4386a37.afa5d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":240,"wires":[]},{"id":"b7eed092.b5053","type":"function","z":"a4386a37.afa5d8","name":"","func":"var loc= 3 ;  //3= 台中市\n//var rawdata=context.global.temp;\nvar rawdata = flow.get(\"tempera\");\nvar locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\nvar period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].startTime[0];\nvar period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].endTime[0];\n\nvar  starthourtemp= period0start.split(\"T\");\nvar  starthour=starthourtemp[1].split(\":\")[0];\nvar  endhourtemp= period0end.split(\"T\");\nvar  endhour=endhourtemp[1].split(\":\")[0];\n\nmsg.payload=period0min;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":220,"wires":[["7267f40b.ef81dc","cf2d30c1.5cde8"]]},{"id":"f3abc179.82f69","type":"ui_group","z":"","name":"Weather","tab":"56471bab.2ceac4","order":1,"disp":false,"width":"8"},{"id":"56471bab.2ceac4","type":"ui_tab","z":"","name":"Weather","icon":"dashboard"}]

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

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