2020年11月2日 星期一

OPEN Data 一般天氣預報-今明36小時天氣預報 (2)

OPEN Data 一般天氣預報-今明36小時天氣預報 (2)



[{"id":"8abd1a6c.6ad2d8","type":"http request","z":"264d5d13.d975e2","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":270,"y":60,"wires":[["c28517d2.b6e0f8"]]},{"id":"fcbb2f33.46db3","type":"function","z":"264d5d13.d975e2","name":"set global temp","func":"\nglobal.set(\"tempera\",msg.payload); //global.set\nreturn msg;\n\n//flow.set('YourVariable', value);    // to store a variable (YourVariable)\n//var x = flow.get('YourVariable'); //to retrieve a variable (YourVariable)","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":60,"wires":[["40b86a9f.b563f4","f723747e.27ae28"]]},{"id":"c28517d2.b6e0f8","type":"xml","z":"264d5d13.d975e2","name":"","property":"payload","attr":"","chr":"","x":410,"y":60,"wires":[["fcbb2f33.46db3"]]},{"id":"babf39d4.21fac8","type":"function","z":"264d5d13.d975e2","name":"List locationname","func":"//var rawdata=context.global.temp;\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar citynumber=location.length;\nvar cityarray=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\ncityarray[i]=location[i].locationName[0];\n}\n\n msg.payload=cityarray;\nflow.set(\"loname\",cityarray);\nreturn msg;\n\n/*\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={\"locationName\":locationName,\"time\":starthour+\"-\"+endhour, \"max\":period0max,\n\"min\":period0min};\nreturn msg;\n*/\n\n/*if(time.getHours()<18)\n{\nmsg.payload={\"locationName\":locationName,\"todaymax\":period1max, \"todaymin\":period1min,\n             \"tonightmax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\nelse\nmsg.payload={\"locationName\":locationName,\"tonightmax\":period1max, \"tonightmin\":period1min,\n             \"todaymax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\n\n*/\n\n\n\n\n//msg.payload=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[1];\n\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":120,"wires":[["45b1349f.2bf14c"]]},{"id":"45b1349f.2bf14c","type":"debug","z":"264d5d13.d975e2","name":"List all locationnames ","active":true,"console":"false","complete":"payload","x":700,"y":120,"wires":[]},{"id":"c4866409.85b638","type":"debug","z":"264d5d13.d975e2","name":"report result","active":true,"console":"false","complete":"payload","x":650,"y":360,"wires":[]},{"id":"4c9b36f2.7c5ff8","type":"function","z":"264d5d13.d975e2","name":"set options","func":"var rawdata =global.get(\"tempera\");\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar citynumber=location.length;\nvar i;\n\nvar cityarray=[];\nfor (i=0; i<citynumber;i++)\n{\ncityarray[i]=location[i].locationName[0];\n\n\n}\nmsg.options=cityarray;\nreturn msg;\n\n/*\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={\"locationName\":locationName,\"time\":starthour+\"-\"+endhour, \"max\":period0max,\n\"min\":period0min};\nreturn msg;\n*/\n\n/*if(time.getHours()<18)\n{\nmsg.payload={\"locationName\":locationName,\"todaymax\":period1max, \"todaymin\":period1min,\n             \"tonightmax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\nelse\nmsg.payload={\"locationName\":locationName,\"tonightmax\":period1max, \"tonightmin\":period1min,\n             \"todaymax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\n\n*/\n\n\n\n\n//msg.payload=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[1];\n\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":240,"wires":[["900535b7.7cc6c8","fad9a24b.5509a"]]},{"id":"420b0ab1.ea7e84","type":"function","z":"264d5d13.d975e2","name":"city to number","func":"\nvar cityname;\ncontext.global.locationnumber=0;\ntry {\n   cityname=msg.payload;\n   \n   if(cityname.indexOf('台北')!=-1 ||cityname.indexOf('臺北')!=-1 )\n{\n    context.global.locationnumber=0;\n   \n}\nelse if(cityname.indexOf('新北')!=-1)\n{\n    context.global.locationnumber=1;\n   \n}\nelse if(cityname.indexOf('桃園')!=-1) //\n{\n    context.global.locationnumber=2;\n   \n}\nelse if(cityname.indexOf('臺中')!=-1 || cityname.indexOf('台中')!=-1) \n{\n    context.global.locationnumber= 3;\n   \n}\nelse if(cityname.indexOf('臺南')!=-1 || cityname.indexOf('台南')!=-1) \n{\n    context.global.locationnumber= 4;\n   \n}\nelse if(cityname.indexOf('高雄')!=-1 ) \n{\n    context.global.locationnumber= 5 ;\n   \n}\nelse if(cityname.indexOf('基隆')!=-1 ) \n{\n    context.global.locationnumber= 6 ;\n   \n}\nelse if(cityname.indexOf('新竹縣')!=-1 ) \n{\n    context.global.locationnumber= 7 ;\n   \n}\nelse if(cityname.indexOf('新竹')!=-1 ) \n{\n    context.global.locationnumber= 8 ;\n   \n}\nelse if(cityname.indexOf('連江')!=-1 ) \n{\n    context.global.locationnumber= 21 ;\n   \n}\nelse  \n{\n    context.global.locationnumber= 0 ;\n   \n}\n   \n   \n}\ncatch(err) {\n    cityname=\"台北\";\n    context.global.locationnumber=0;\n}\n\n\n msg.payload= context.global.locationnumber;\nreturn msg;\n","outputs":1,"noerr":0,"x":300,"y":420,"wires":[[]]},{"id":"2889e479.e0982c","type":"function","z":"264d5d13.d975e2","name":"report","func":"var loc=msg.payload;\n//var rawdata=context.global.temp;\nvar rawdata = global.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=locationName+starthour+\"到\"+endhour+\"點溫度最低\"+period0min+\"度最高\"+period0max+\"度\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":360,"wires":[["c4866409.85b638","9fc656d9.f34b58"]]},{"id":"630a9213.ad888c","type":"debug","z":"264d5d13.d975e2","name":"selected city ","active":true,"tosidebar":true,"console":false,"complete":"payload","x":670,"y":280,"wires":[]},{"id":"900535b7.7cc6c8","type":"ui_dropdown","z":"264d5d13.d975e2","name":"","label":"city options","tooltip":"","place":"Select city","group":"31745d9a.412202","order":0,"width":0,"height":0,"passthru":true,"multiple":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":470,"y":280,"wires":[["630a9213.ad888c","c11b28f7.345f28"]]},{"id":"9fc656d9.f34b58","type":"ui_text","z":"264d5d13.d975e2","group":"31745d9a.412202","order":0,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload}}","layout":"row-spread","x":650,"y":400,"wires":[]},{"id":"40b86a9f.b563f4","type":"debug","z":"264d5d13.d975e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":60,"wires":[]},{"id":"fad9a24b.5509a","type":"debug","z":"264d5d13.d975e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","targetType":"msg","x":470,"y":220,"wires":[]},{"id":"c11b28f7.345f28","type":"function","z":"264d5d13.d975e2","name":"city name to number","func":"\nvar rawdata = global.get(\"tempera\");\n\n//context.global.locationnumber=0;\nflow.set(\"locationnumber\",0);\ntry {\n   cityname=msg.payload;\n   \n   if(cityname.indexOf('台北市市')!=-1 ||cityname.indexOf('臺北市')!=-1 )\n{\n    //context.global.locationnumber=0;\n    flow.set(\"locationnumber\",0);\n   \n}\nelse if(cityname.indexOf('新北市')!=-1)\n{\n    //context.global.locationnumber=1;\n    flow.set(\"locationnumber\",1);\n}\nelse if(cityname.indexOf('桃園市')!=-1) //\n{\n    //context.global.locationnumber=2;\n    flow.set(\"locationnumber\",2);\n}\nelse if(cityname.indexOf('臺中市')!=-1 || cityname.indexOf('台中市')!=-1) \n{\n    //context.global.locationnumber= 3;\n    flow.set(\"locationnumber\",3);\n}\nelse if(cityname.indexOf('臺南市')!=-1 || cityname.indexOf('台南市')!=-1) \n{\n    //context.global.locationnumber= 4;\n    flow.set(\"locationnumber\",4);\n   \n}\nelse if(cityname.indexOf('高雄市')!=-1 ) \n{\n    //context.global.locationnumber= 5 ;\n    flow.set(\"locationnumber\",5);\n   \n}\nelse if(cityname.indexOf('基隆市')!=-1 ) \n{\n    //context.global.locationnumber= 6 ;\n    flow.set(\"locationnumber\",6);\n}\nelse if(cityname.indexOf('新竹縣')!=-1 ) \n{\n    //context.global.locationnumber= 7 ;\n    flow.set(\"locationnumber\",7);\n}\nelse if(cityname.indexOf('新竹市')!=-1 ) \n{\n    //context.global.locationnumber= 8 ;\n    flow.set(\"locationnumber\",8);\n}\nelse if(cityname.indexOf('苗栗縣')!=-1 ) \n{\n    //context.global.locationnumber= 9 ;\n    flow.set(\"locationnumber\",9);\n}\nelse if(cityname.indexOf('彰化縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",10);\n}\nelse if(cityname.indexOf('南投縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",11);\n}\nelse if(cityname.indexOf('雲林縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",12);\n}\nelse if(cityname.indexOf('嘉義縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",13);\n}\nelse if(cityname.indexOf('嘉義市')!=-1 ) \n{\n      flow.set(\"locationnumber\",14);\n}\nelse if(cityname.indexOf('屏東縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",15);\n}\nelse if(cityname.indexOf('宜蘭縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",16);\n}\nelse if(cityname.indexOf('花蓮縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",17);\n}\nelse if(cityname.indexOf('臺東縣')!=-1 || cityname.indexOf('台東縣')!=-1)\n{\n      flow.set(\"locationnumber\",18);\n}\nelse if(cityname.indexOf('澎湖縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",19);\n}\nelse if(cityname.indexOf('金門縣')!=-1 ) \n{\n      flow.set(\"locationnumber\",20);\n}\nelse if(cityname.indexOf('連江')!=-1 ) \n{\n    //context.global.locationnumber= 21 ;\n    flow.set(\"locationnumber\",21);\n}\nelse  \n{\n   // context.global.locationnumber= 0 ;\n    flow.set(\"locationnumber\",0);\n}\n   \n   \n}\ncatch(err) {\n    cityname=\"台北市\";\n    //context.global.locationnumber=0;\n    flow.set(\"locationnumber\",0);\n}\n\nmsg.payload= flow.get(\"locationnumber\");\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":360,"wires":[["2889e479.e0982c","d30425d1.ba6148"]]},{"id":"d30425d1.ba6148","type":"debug","z":"264d5d13.d975e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":420,"wires":[]},{"id":"e7c0839.b79c38","type":"ui_button","z":"264d5d13.d975e2","name":"","group":"31745d9a.412202","order":2,"width":0,"height":0,"passthru":false,"label":"START","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":100,"y":60,"wires":[["8abd1a6c.6ad2d8"]]},{"id":"f723747e.27ae28","type":"function","z":"264d5d13.d975e2","name":"show raw data","func":"//flow.set('YourVariable', value);    // to store a variable (YourVariable)\n//var x = flow.get('YourVariable'); //to retrieve a variable (YourVariable)\n//var loc=msg.payload.loc;\n\nvar rawdata = global.get(\"tempera\"); //global.get\n//msg.playload=rawdata.cwbopendata.dataset[0].location;\nmsg.payload=rawdata;\nreturn msg;\n\n/*\nmsg.payload = rawdata;\nreturn msg;\n*/\n\n//msg.playload=rawdata;\n//.cwbopendata.dataset[0].location;\n\n\n/*\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={\"locationName\":locationName,\"time\":starthour+\"-\"+endhour, \"max\":period0max,\n\"min\":period0min};\nreturn msg;\n*/\n\n/*if(time.getHours()<18)\n{\nmsg.payload={\"locationName\":locationName,\"todaymax\":period1max, \"todaymin\":period1min,\n             \"tonightmax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\nelse\nmsg.payload={\"locationName\":locationName,\"tonightmax\":period1max, \"tonightmin\":period1min,\n             \"todaymax\":period2max, \"tonightmin\":period2min,\"tomorrowmax\":period3max, \"tomorrowmin\":period3min};\n}\n\n*/\n\n\n\n\n//msg.payload=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[1];\n\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":120,"wires":[["babf39d4.21fac8"]]},{"id":"8af50820.b49298","type":"ui_button","z":"264d5d13.d975e2","name":"","group":"31745d9a.412202","order":2,"width":0,"height":0,"passthru":false,"label":"Inject City Option","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":110,"y":240,"wires":[["4c9b36f2.7c5ff8"]]},{"id":"31745d9a.412202","type":"ui_group","z":"","name":"Default","tab":"1d173c13.e2dc64","order":1,"disp":true,"width":"6"},{"id":"1d173c13.e2dc64","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}] 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...