2019年10月7日 星期一

Node-Red 基本元件操作實驗

Node-Red本元件操作實驗

Node-Red使用Json資料庫儲存資料

應用程式存取網址  選取 JSON檔案格式
https://opendata.epa.gov.tw/webapi/api/rest/datastore/355000000I-000259?sort=SiteName&offset=0&limit=1000















[{"id":"c55a4b45.0cdf98","type":"inject","z":"d2ac9b5e.1faa08","name":"","topic":"","payload":"","payloadType":"date","repeat":"20","crontab":"","once":true,"onceDelay":"5","x":110,"y":80,"wires":[["3fd95521.40e43a","f44d2ebd.aa6f8"]]},{"id":"3fd95521.40e43a","type":"http request","z":"d2ac9b5e.1faa08","name":"PM2.5網頁","method":"GET","ret":"obj","url":"http://opendata.epa.gov.tw/ws/Data/REWIQA/?$orderby=SiteName&$skip=0&$top=1000&format=json","tls":"","x":410,"y":80,"wires":[["a99ed099.b2b7b","b08ed856.94e488"]]},{"id":"2b7d15ba.f685ca","type":"function","z":"d2ac9b5e.1faa08","name":"設定地區","func":"var a = msg.payload;\n\na.forEach (function(e,i){ \n   if(e.SiteName == global.get('Location')) {\n        \n        msg.PM25 = ' PM2.5=' + e['PM2.5'] ;\n        msg.AQI = ' AQI=' + e['AQI'] ;\n        msg.Status = ' Status=' + e['Status'] ;\n        msg.PublishTime =' PublishTime='+ e['PublishTime'] ;\n        msg.payload=global.get('Location')+msg.PM25+msg.AQI+msg.Status+msg.PublishTime;\n\n        msg.PM251 =  e['PM2.5'] ;\n        msg.AQI1 =  e['AQI'] ;\n        msg.Status1 = e['Status'] ;\n        msg.PublishTime1 = e['PublishTime'] ;\n   }\n} );\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":240,"wires":[["b8db8759.46bfa8","ed4a20fd.ecada","1b20ea9e.47aea5","879be4e4.5b0f78","40d3c2e4.a20e0c","acebd89d.8ef228","69819cf6.2232c4","874c0434.f9f868","d585534c.b2b0a"]]},{"id":"b8db8759.46bfa8","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"PM25","x":870,"y":240,"wires":[]},{"id":"ed4a20fd.ecada","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"Status","x":670,"y":240,"wires":[]},{"id":"1b20ea9e.47aea5","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"PublishTime","x":870,"y":300,"wires":[]},{"id":"879be4e4.5b0f78","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"AQI","x":660,"y":300,"wires":[]},{"id":"b6b94e54.4d635","type":"comment","z":"d2ac9b5e.1faa08","name":"台灣空氣品質狀況","info":"","x":110,"y":40,"wires":[]},{"id":"40d3c2e4.a20e0c","type":"mqtt out","z":"d2ac9b5e.1faa08","name":"空氣品質 AQI","topic":"alex9ufo/Dali/AQI","qos":"1","retain":"true","broker":"40bf4d5e.0395f4","x":680,"y":180,"wires":[]},{"id":"1b2055db.7a243a","type":"ui_gauge","z":"d2ac9b5e.1faa08","name":"","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","gtype":"gage","title":"PM2.5 [0..35] 良好","label":"units","format":"{{value}}","min":0,"max":"80","colors":["#00b500","#e6e600","#ca3838"],"seg1":"35","seg2":"53","x":950,"y":360,"wires":[],"inputLabels":["msg.PM25"]},{"id":"f9561345.51fcf","type":"ui_text","z":"d2ac9b5e.1faa08","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"2","name":"","label":"空氣品質","format":"{{msg.payload}}","layout":"row-spread","x":920,"y":480,"wires":[],"inputLabels":["msg.payload"]},{"id":"acebd89d.8ef228","type":"function","z":"d2ac9b5e.1faa08","name":"PM2.5 [0..80]","func":"msg.payload=msg.PM251;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":360,"wires":[["1b2055db.7a243a"]]},{"id":"69819cf6.2232c4","type":"function","z":"d2ac9b5e.1faa08","name":"AQI [0..400]","func":"msg.payload= msg.AQI1;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":420,"wires":[["f48d7445.519b58"]]},{"id":"f48d7445.519b58","type":"ui_gauge","z":"d2ac9b5e.1faa08","name":"","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","gtype":"gage","title":"AQI [0..50] 良好","label":"units","format":"{{value}}","min":0,"max":"400","colors":["#00b500","#e6e600","#ca3838"],"seg1":"50","seg2":"100","x":940,"y":420,"wires":[],"inputLabels":["msg.PM25"]},{"id":"874c0434.f9f868","type":"function","z":"d2ac9b5e.1faa08","name":"Status","func":"msg.payload=msg.Status1;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":480,"wires":[["f9561345.51fcf"]]},{"id":"d585534c.b2b0a","type":"function","z":"d2ac9b5e.1faa08","name":"PublishTime","func":"msg.payload=msg.PublishTime1;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":540,"wires":[["298e66f7.64a34a"]]},{"id":"298e66f7.64a34a","type":"ui_text","z":"d2ac9b5e.1faa08","group":"ac7bd49c.51cf38","order":0,"width":"6","height":"3","name":"","label":"發表時間","format":"{{msg.payload}}","layout":"row-spread","x":920,"y":540,"wires":[],"inputLabels":["msg.payload"]},{"id":"a99ed099.b2b7b","type":"DataIn","z":"d2ac9b5e.1faa08","collection":"7a14aca8.b15994","name":"PM2.5","update":false,"path":"/myRootTest","x":650,"y":80,"wires":[]},{"id":"f44d2ebd.aa6f8","type":"trigger","z":"d2ac9b5e.1faa08","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":260,"y":140,"wires":[["4e72cc00.8e9084"]]},{"id":"4e72cc00.8e9084","type":"DataOut","z":"d2ac9b5e.1faa08","collection":"7a14aca8.b15994","name":"PM2.5","path":"/myRootTest","error":false,"x":300,"y":240,"wires":[["2b7d15ba.f685ca","5d25865e.a5b848"]]},{"id":"b3b8c570.82b628","type":"function","z":"d2ac9b5e.1faa08","name":"","func":"if (msg.payload===null)\n{\n    global.set('Location','大里');\n}\nelse\n{\n    global.set('Location',msg.payload);\n}\nnode.status({filee:\"green\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":240,"wires":[["4e72cc00.8e9084"]]},{"id":"26364fb8.d2499","type":"ui_dropdown","z":"d2ac9b5e.1faa08","name":"","label":"","place":"Select option","group":"ac7bd49c.51cf38","order":0,"width":0,"height":0,"passthru":true,"options":[{"label":"大里","value":"大里","type":"str"},{"label":"二林","value":"二林","type":"str"},{"label":"板橋","value":"板橋","type":"str"},{"label":"士林","value":"士林","type":"str"},{"label":"南投","value":"南投","type":"str"}],"payload":"","topic":"","x":80,"y":160,"wires":[["b3b8c570.82b628"]]},{"id":"b08ed856.94e488","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":120,"wires":[]},{"id":"5d25865e.a5b848","type":"debug","z":"d2ac9b5e.1faa08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":320,"wires":[]},{"id":"40bf4d5e.0395f4","type":"mqtt-broker","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":15,"cleansession":true,"birthQos":"0","willQos":"0"},{"id":"ac7bd49c.51cf38","type":"ui_group","z":"","name":"空氣品質狀況","tab":"ba052423.3729f8","order":1,"disp":true,"width":"6","collapse":false},{"id":"7a14aca8.b15994","type":"json-db-collection","z":"","name":"DATA","collection":"DATA","save":false},{"id":"ba052423.3729f8","type":"ui_tab","z":"","name":"Weather","icon":"dashboard","order":1}]

沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...