2024年2月4日 星期日

Node-Red 取得opendata PM2.5 經MQTT Server 回傳至Line Notify+Node-Red

Node-Red 取得opendata PM2.5 經MQTT Server 回傳至Line Notify+Node-Red






  {
            "sitename": "沙鹿",
            "county": "臺中市",
            "aqi": "37",
            "pollutant": "",
            "status": "良好",
            "so2": "1.5",
            "co": "0.36",
            "o3": "22.9",
            "o3_8hr": "26.8",
            "pm10": "37",
            "pm2.5": "14",
            "no2": "15",
            "nox": "18.3",
            "no": "3.3",
            "wind_speed": "3",
            "wind_direc": "320",
            "publishtime": "2024\/02\/05 16:00:00",
            "co_8hr": "0.3",
            "pm2.5_avg": "11.5",
            "pm10_avg": "23",
            "so2_avg": "1",
            "longitude": "120.568794",
            "latitude": "24.225628",
            "siteid": "29"
        },
        {
            "sitename": "大里",
            "county": "臺中市",
            "aqi": "31",
            "pollutant": "",
            "status": "良好",
            "so2": "1.1",
            "co": "0.26",
            "o3": "34.1",
            "o3_8hr": "34.2",
            "pm10": "8",
            "pm2.5": "8",
            "no2": "",
            "nox": "",
            "no": "",
            "wind_speed": "1.4",
            "wind_direc": "302",
            "publishtime": "2024\/02\/05 16:00:00",
            "co_8hr": "0.2",
            "pm2.5_avg": "7.9",
            "pm10_avg": "9",
            "so2_avg": "1",
            "longitude": "120.67844444",
            "latitude": "24.09961111",
            "siteid": "30"
        },
        {
            "sitename": "忠明",
            "county": "臺中市",
            "aqi": "37",
            "pollutant": "",
            "status": "良好",
            "so2": "1.6",
            "co": "0.3",
            "o3": "31.1",
            "o3_8hr": "28.2",
            "pm10": "14",
            "pm2.5": "11",
            "no2": "13.7",
            "nox": "14.5",
            "no": "0.7",
            "wind_speed": "3.1",
            "wind_direc": "302",
            "publishtime": "2024\/02\/05 16:00:00",
            "co_8hr": "0.3",
            "pm2.5_avg": "11.3",
            "pm10_avg": "19",
            "so2_avg": "1",
            "longitude": "120.641092",
            "latitude": "24.151958",
            "siteid": "31"
        },

https://data.moenv.gov.tw/api/v2/aqx_p_432?api_key=e81dd42e6-9b18b-43f8-991e-b3dee723a52d&limit=1000&sort=ImportDate%20desc&format=JSON

改成自己的金鑰



[{"id":"89ad6b4aa5ce1629","type":"inject","z":"74c417894ebe4fde","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"120","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":60,"wires":[["00c7035b7f63d64c"]]},{"id":"1e8a983474b291e8","type":"function","z":"74c417894ebe4fde","name":"func2","func":"var a = msg.payload;\nvar pm25;\n\na=Array.from(a);\n\na.forEach(function(e,i){\n    if(e.sitename=='大里'){\n        pm25 = e['pm2.5_avg'];\n    }\n});\nmsg.payload=pm25;\n\n//to store values use:\nflow.set('flowPM25',pm25);\n\nreturn msg;\n\n\n\n//var flowPM25=flow.get('flowPM25') || 0;\n//var flowStatus=flow.get('flowStatus') ;\n//var flowPublishTime=flow.get('flowPublishTime') ;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":180,"wires":[["d922fbd375c022d2","5e07f4ba688793a1"]]},{"id":"5e07f4ba688793a1","type":"debug","z":"74c417894ebe4fde","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":180,"wires":[]},{"id":"00c7035b7f63d64c","type":"http request","z":"74c417894ebe4fde","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://data.moenv.gov.tw/api/v2/aqx_p_432?api_key=e8dd42e6-9b8b-43f8-991e-b3dee723a52d&limit=1000&sort=ImportDate%20desc&format=JSON","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":240,"y":60,"wires":[["439bff74d05a15eb","ccedd3ceed710617"]]},{"id":"ebd8971451667511","type":"ui_text","z":"74c417894ebe4fde","group":"f64f0af7fe862c9e","order":3,"width":0,"height":0,"name":"","label":"空氣品質","format":"{{msg.payload}}","layout":"row-left","className":"","x":560,"y":400,"wires":[]},{"id":"3e40ccdb93825cd5","type":"ui_text","z":"74c417894ebe4fde","group":"f64f0af7fe862c9e","order":4,"width":0,"height":0,"name":"","label":"發佈時間","format":"{{msg.payload}}","layout":"row-left","className":"","x":560,"y":440,"wires":[]},{"id":"d922fbd375c022d2","type":"ui_gauge","z":"74c417894ebe4fde","name":"","group":"f64f0af7fe862c9e","order":1,"width":8,"height":4,"gtype":"gage","title":"細懸浮微粒PM2.5","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":590,"y":220,"wires":[]},{"id":"439bff74d05a15eb","type":"debug","z":"74c417894ebe4fde","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":60,"wires":[]},{"id":"ccedd3ceed710617","type":"function","z":"74c417894ebe4fde","name":"func1","func":"msg.payload= msg.payload.records\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":140,"wires":[["017d6225cc331fd5","1dac0906f16a8150","1e8a983474b291e8"]]},{"id":"017d6225cc331fd5","type":"debug","z":"74c417894ebe4fde","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":140,"wires":[]},{"id":"1dac0906f16a8150","type":"function","z":"74c417894ebe4fde","name":"function 88","func":"for (var i = 0; i < msg.payload.length; i++) {\n    if(msg.payload[i].sitename==\"大里\"){  \n        var newMsg = {};\n        newMsg.payload = msg.payload[i];\n        node.send(newMsg);\n    }\n}\nreturn null;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":280,"wires":[["aa3cf2a22e96c8eb","941d2f1dc53652e3","399739dcb882c814","665716649f881332"]]},{"id":"aa3cf2a22e96c8eb","type":"debug","z":"74c417894ebe4fde","name":"debug  ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":280,"wires":[]},{"id":"941d2f1dc53652e3","type":"json","z":"74c417894ebe4fde","name":"","property":"payload","action":"str","pretty":false,"x":430,"y":340,"wires":[["4431b433e1f7c50d"]]},{"id":"4431b433e1f7c50d","type":"debug","z":"74c417894ebe4fde","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"399739dcb882c814","type":"function","z":"74c417894ebe4fde","name":"func2","func":"var PM25,Status,PublishTime;\nStatus=msg.payload.status;        \nmsg.payload=Status;\n\n//to store values use:\nflow.set('flowStatus',Status);\n\nreturn msg;\n\n\n\n//var flowPM25=flow.get('flowPM25') || 0;\n//var flowStatus=flow.get('flowStatus') ;\n//var flowPublishTime=flow.get('flowPublishTime') ;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":400,"wires":[["ebd8971451667511"]]},{"id":"665716649f881332","type":"function","z":"74c417894ebe4fde","name":"func2","func":"var PM25,Status,PublishTime;\n\n \nPublishTime=msg.payload.publishtime;\nmsg.payload=PublishTime;\n\n//to store values use:\nflow.set('flowPublishTime',PublishTime);\n\nreturn msg;\n\n\n\n//var flowPM25=flow.get('flowPM25') || 0;\n//var flowStatus=flow.get('flowStatus') ;\n//var flowPublishTime=flow.get('flowPublishTime') ;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":440,"wires":[["3e40ccdb93825cd5","a9f29e53590f796f"]]},{"id":"6f6d4c66bbb39396","type":"mqtt out","z":"74c417894ebe4fde","name":"PM25","topic":"alex9ufo/PM25","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":590,"y":520,"wires":[]},{"id":"7d6d280b84907c23","type":"mqtt in","z":"74c417894ebe4fde","name":"PM25","topic":"alex9ufo/PM25","qos":"1","datatype":"auto-detect","broker":"603bb104.d6134","nl":false,"rap":true,"rh":0,"inputs":0,"x":790,"y":120,"wires":[["305dfaa1dd1b079f","158f73016922f32e","e9fea79b02646127"]]},{"id":"490e6bf9455d882d","type":"function","z":"74c417894ebe4fde","name":"set  flow variable","func":"//var PM25,Status,PublishTime;\nvar flowPM25=flow.get('flowPM25') || 0;\nvar flowStatus=flow.get('flowStatus') ;\nvar flowPublishTime=flow.get('flowPublishTime') ;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":380,"wires":[[]]},{"id":"9f1a67fe02033640","type":"inject","z":"74c417894ebe4fde","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":380,"wires":[["490e6bf9455d882d"]]},{"id":"3490e14f9ff8fe75","type":"function","z":"74c417894ebe4fde","name":"function ","func":"var f1=flow.get('flowPM25') || 0;\nvar f2=flow.get('flowStatus') ;\nvar f3=flow.get('flowPublishTime') ;\n\nvar v4=\"MQTT發行訊息為 台中市大里區 , PM2.5=\";\nv4+=f1;\nv4+=\"天候狀況\";\nv4+=f2;\n\nv4+=\"發布時間\";\nv4+=f3;\n\nmsg.payload=v4;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":520,"wires":[["6f6d4c66bbb39396","d61fbc10f8fab89f"]]},{"id":"a9f29e53590f796f","type":"delay","z":"74c417894ebe4fde","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":260,"y":520,"wires":[["3490e14f9ff8fe75"]]},{"id":"305dfaa1dd1b079f","type":"debug","z":"74c417894ebe4fde","name":"debug 262","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":60,"wires":[]},{"id":"d61fbc10f8fab89f","type":"ui_text","z":"74c417894ebe4fde","group":"551944bcad742ef1","order":1,"width":8,"height":3,"name":"","label":"MQTT發行訊息","format":"{{msg.payload}}","layout":"row-left","className":"","x":600,"y":600,"wires":[]},{"id":"158f73016922f32e","type":"ui_text","z":"74c417894ebe4fde","group":"551944bcad742ef1","order":3,"width":8,"height":3,"name":"","label":"MQTT接收訊息","format":"{{msg.payload}}","layout":"row-left","className":"","x":980,"y":120,"wires":[]},{"id":"e9fea79b02646127","type":"function","z":"74c417894ebe4fde","name":"function ","func":"msg.payload=\" --訂閱MQTT的訊息---\" +msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":180,"wires":[["8e5a33f864d47f7a","a65bd6bb901d2cd7"]]},{"id":"8e5a33f864d47f7a","type":"function","z":"74c417894ebe4fde","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"x":1130,"y":180,"wires":[["52591b7051c6ec4f"]]},{"id":"52591b7051c6ec4f","type":"http request","z":"74c417894ebe4fde","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","authType":"","x":1280,"y":180,"wires":[["648619e21e91f6e2"]]},{"id":"648619e21e91f6e2","type":"debug","z":"74c417894ebe4fde","name":"debug 263","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1430,"y":180,"wires":[]},{"id":"01e2331858995585","type":"comment","z":"74c417894ebe4fde","name":"Line Notify Message ","info":"","x":1210,"y":140,"wires":[]},{"id":"a65bd6bb901d2cd7","type":"delay","z":"74c417894ebe4fde","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1100,"y":260,"wires":[["41cc1b799336aeb0"]]},{"id":"41cc1b799336aeb0","type":"ui_audio","z":"74c417894ebe4fde","name":"","group":"551944bcad742ef1","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":"","x":1260,"y":260,"wires":[]},{"id":"f64f0af7fe862c9e","type":"ui_group","name":"2024 大里","tab":"ba052423.3729f8","order":3,"disp":true,"width":8,"collapse":false,"className":""},{"id":"603bb104.d6134","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"551944bcad742ef1","type":"ui_group","name":"Line+MQTT ","tab":"ba052423.3729f8","order":4,"disp":true,"width":8,"collapse":false,"className":""},{"id":"ba052423.3729f8","type":"ui_tab","name":"AQI","icon":"dashboard","order":1}]

沒有留言:

張貼留言

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

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