2018年8月25日 星期六

MQTT Json Extract 溫度 濕度 資料

WeMosD1 送出二個Mqtt

  client.publish("alex9ufo/DS18B20/temp",jsonChar);
 與
  client.publish("alex9ufo/DHT11/temp_humi" , json_buffer);

jason 檔案如下

{"data":{"DS18B20": "28.50"}}

{"device_name":"ESP_7536714","type":"dth","temperature":"27.00","humidity":"45.00"}



DHT11 Temperature=27.00, Humidity   =45.00
Publish message:
alex9ufo/DS18B20/temp{"data":{"DS18B20": "28.50"}}
alex9ufo/DHT11/temp_humi{"device_name":"ESP_7536714","type":"dth","temperature":"27.00","humidity":"45.00"}
DS18B20 Temperature=28.50
DHT11 Temperature=27.00, Humidity   =45.00
Publish message:
alex9ufo/DS18B20/temp{"data":{"DS18B20": "28.50"}}
alex9ufo/DHT11/temp_humi{"device_name":"ESP_7536714","type":"dth","temperature":"27.00","humidity":"45.00"}

利用Node-Red 擷取出 溫度 濕度 資料  並將 字串轉int 格式
=======================================
//var pres = msg.payload.pressure;
var temp = msg.payload.data.DS18B20;
//var humidity = msg.payload.humidity;
var tmp1= parseInt(temp);
msg.payload = tmp1;
return msg;

=======================================
//var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
//var humidity = msg.payload.humidity;
var tmp1= parseInt(temp);
msg.payload = tmp1;
return msg;
=======================================
//var pres = msg.payload.pressure;
//var temp = msg.payload.temperature;
var humidity = msg.payload.humidity
var tmp1= parseInt(humidity);
msg.payload = tmp1;
return msg;




[{"id":"3affa9c0.1c6896","type":"mqtt in","z":"34bd759c.1796da","name":"","topic":"alex9ufo/#","qos":"0","broker":"41a78e1b.8ebeb","x":100,"y":40,"wires":[["551ad94f.d99f58"]]},{"id":"4d0c7e60.1edac","type":"function","z":"34bd759c.1796da","name":"Convert to float","func":"var str = msg.payload;\nmsg.payload = parseFloat (str);\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":100,"wires":[["5055c086.b7b71"]]},{"id":"5055c086.b7b71","type":"switch","z":"34bd759c.1796da","name":"Check Temp > 28°C","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"28","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":880,"y":100,"wires":[["844df3cf.80a0b"]]},{"id":"95dd3ea1.e2b11","type":"template","z":"34bd759c.1796da","name":"Message","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"警告!\n\\冰箱的溫度會下降!\\\n不可能解凍。","output":"str","x":700,"y":220,"wires":[["13f92463.30b53c"]]},{"id":"13f92463.30b53c","type":"template","z":"34bd759c.1796da","name":"Subject","field":"topic","fieldType":"msg","format":"handlebars","syntax":"plain","template":"!!警告冰箱溫度警告!","output":"str","x":900,"y":220,"wires":[["69e427a6.77f4d8"]]},{"id":"844df3cf.80a0b","type":"trigger","z":"34bd759c.1796da","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"1","extend":false,"units":"min","reset":"","bytopic":"all","name":"Trigger mail","x":1090,"y":100,"wires":[["95dd3ea1.e2b11"]]},{"id":"8025f79b.06ecf8","type":"ui_chart","z":"34bd759c.1796da","name":"","group":"5590022e.fa566c","order":0,"width":"0","height":"0","label":"溫度紀錄","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":true,"ymin":"0","ymax":"100","removeOlder":"120","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":660,"y":20,"wires":[[],[]]},{"id":"3dda0770.b80798","type":"ui_gauge","z":"34bd759c.1796da","name":"","group":"5590022e.fa566c","order":0,"width":"0","height":"0","gtype":"gage","title":"現在溫度","label":"°C","format":"{{value}}","min":"0","max":"100","colors":["#035ab1","#e6e600","#ca3838"],"seg1":"","seg2":"","x":660,"y":60,"wires":[]},{"id":"69e427a6.77f4d8","type":"e-mail","z":"34bd759c.1796da","server":"smtp.gmail.com","port":"465","secure":true,"name":"alex.pts2594@gmail.com","dname":"send Gmail ","x":1090,"y":220,"wires":[]},{"id":"f8b3f670.53e638","type":"json","z":"34bd759c.1796da","name":"","property":"payload","action":"","pretty":false,"x":270,"y":260,"wires":[["a470db29.1cbd58","4f1146f9.8e81a8"]]},{"id":"a470db29.1cbd58","type":"function","z":"34bd759c.1796da","name":"temperature extract ","func":"//var pres = msg.payload.pressure;\nvar temp = msg.payload.temperature;\n//var humidity = msg.payload.humidity;\nvar tmp1= parseInt(temp);\nmsg.payload = tmp1;\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":320,"wires":[["6c306cdb.d310e4","df3b6a40.aa5138"]]},{"id":"551ad94f.d99f58","type":"switch","z":"34bd759c.1796da","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"alex9ufo/DS18B20/temp","vt":"str"},{"t":"eq","v":"alex9ufo/DHT11/temp_humi","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":200,"wires":[["785e43d.661a0bc"],["f8b3f670.53e638"]]},{"id":"785e43d.661a0bc","type":"json","z":"34bd759c.1796da","name":"","property":"payload","action":"","pretty":false,"x":270,"y":160,"wires":[["a43d7c64.d0297"]]},{"id":"a43d7c64.d0297","type":"function","z":"34bd759c.1796da","name":"data extract","func":"//var pres = msg.payload.pressure;\nvar temp = msg.payload.data.DS18B20;\n//var humidity = msg.payload.humidity;\nvar tmp1= parseInt(temp);\nmsg.payload = tmp1;\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":80,"wires":[["8025f79b.06ecf8","3dda0770.b80798","4d0c7e60.1edac"]]},{"id":"4f1146f9.8e81a8","type":"function","z":"34bd759c.1796da","name":"humidity  extract","func":"//var pres = msg.payload.pressure;\n//var temp = msg.payload.temperature;\nvar humidity = msg.payload.humidity\nvar tmp1= parseInt(humidity);\nmsg.payload = tmp1;\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":400,"wires":[["c4021ed1.ff08e","a0b2217e.11516"]]},{"id":"6c306cdb.d310e4","type":"ui_chart","z":"34bd759c.1796da","name":"","group":"19f20bd0.2ae064","order":0,"width":"0","height":"0","label":"溫度紀錄","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":true,"ymin":"0","ymax":"100","removeOlder":"120","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":680,"y":300,"wires":[[],[]]},{"id":"df3b6a40.aa5138","type":"ui_gauge","z":"34bd759c.1796da","name":"","group":"5590022e.fa566c","order":0,"width":"0","height":"0","gtype":"gage","title":"現在溫度","label":"°C","format":"{{value}}","min":"0","max":"100","colors":["#035ab1","#e6e600","#ca3838"],"seg1":"","seg2":"","x":680,"y":340,"wires":[]},{"id":"c4021ed1.ff08e","type":"ui_chart","z":"34bd759c.1796da","name":"","group":"d593b7b4.155088","order":0,"width":"0","height":"0","label":"濕度紀錄","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":true,"ymin":"0","ymax":"100","removeOlder":"120","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":680,"y":400,"wires":[[],[]]},{"id":"a0b2217e.11516","type":"ui_gauge","z":"34bd759c.1796da","name":"","group":"5590022e.fa566c","order":0,"width":"0","height":"0","gtype":"gage","title":"現在濕度","label":"°C","format":"{{value}}","min":"0","max":"100","colors":["#035ab1","#e6e600","#ca3838"],"seg1":"","seg2":"","x":680,"y":440,"wires":[]},{"id":"41a78e1b.8ebeb","type":"mqtt-broker","z":"","name":"mqtt","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5590022e.fa566c","type":"ui_group","z":"","name":"DS18B20","tab":"6a28d450.774d9c","order":1,"disp":true,"width":"6","collapse":false},{"id":"19f20bd0.2ae064","type":"ui_group","z":"","name":"DHT11_temp","tab":"6a28d450.774d9c","order":2,"disp":true,"width":"6","collapse":false},{"id":"d593b7b4.155088","type":"ui_group","z":"","name":"DHT11_humi","tab":"6a28d450.774d9c","order":3,"disp":true,"width":"6","collapse":false},{"id":"6a28d450.774d9c","type":"ui_tab","z":"","name":"DS18B20_DHT11","icon":"dashboard","order":5}]

沒有留言:

張貼留言

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

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