本文做者:天工智能物聯網node
本文檔介紹了基於樹莓派+百度天工(物接入、TSDB、物可視)快速搭建一個環境溫溼度監測告警系統。幫助用戶熟悉天工物接入的接入方式、物影子概念以及使用方式等內容,快速搭建本身物聯網硬件和應用。json
閱讀本示例前建議先熟悉快速入門文檔。小程序
該場景演示物聯網應用場景中經常使用的功能,包括設備接入、數據上報、數據存儲、數據展現、遠程控制、配置下發等。微信小程序
硬件設計
首先咱們設計了一款智能溫溼度監測儀,監測儀運行時會實時監測當前所處環境的溫溼度,同時能夠設置溫溼度的告警值,當溫溼度達到設定值時,相應的告警燈亮起——這是設備硬件部分具有的功能,還未涉及到物聯網api
設備接入
爲了可以實時查看到環境溫信息,進而須要將設備接入物聯網平臺,若是當前環境溫溼度達到設置的閾值,觸發設備告警燈亮起,並上報設備當前狀態和溫溼度信息,正常狀況下則每30秒上報一次當前溫溼度信息到平臺安全
配置下發
經過遠程向監測儀下發配置信息,修改溫溼度的告警值微信
遠程控制
硬件部分具有告警指示燈功能,溫度、溼度值分別達到告警值時,對應的指示燈會亮起並保持常亮,經過遠程指令消除告警狀態熄滅指示燈session
數據存儲(拓展)
平臺接收到信息後能夠將溫溼度數據存儲,以便進行數據展現、分析dom
數據展現(拓展)
設備接入平臺後,咱們經過大屏的對實時和歷史數據進行儀表盤、圖表等展現監控,同時可展現告警狀態異步
首先按以下配置信息在控制檯建立一個物模型,物模型中設置了6個屬性,分別表明溫溼度當前值、溫溼度告警指示燈狀態、溫溼度告警閾值,詳細配置以下:
名稱:hygrothermoscope
描述:用於天工平臺能力演示的通用設備
序號 | 顯示名稱 | 屬性名稱 | 數據類型 | 默認值 | 單位 |
---|---|---|---|---|---|
1 | 溫度 | temperature | number | 0.00 | ℃ |
2 | 溼度 | humidity | number | 0.00 | %rh |
3 | 溫度告警 | temperature_alarm | number | 0 | |
4 | 溼度告警 | humidity_alarm | number | 0 | |
5 | 溫度閾值 | temperature_alarm_value | number | 25 | ℃ |
6 | 溼度閾值 | humidity_alarm_value | number | 40 | %rh |
配置頁面如圖:
建立完物模型後,爲設備建立一個物影子,來得到設備接入天工平臺須要的MQTT鏈接用戶名和密碼,建立成功後注意保存影子的鏈接信息,配置信息以下:
名稱:demo01
描述:——
物模型:hygrothermoscope
配置頁面如圖:
按下表鏈接樹莓派和傳感器、告警指示燈
DHT11電氣參數
電源電壓:3~5.5V(典型值:5V);
溫度量程:0~50℃,偏差 ±2℃;
溼度量程:20~90%RH,偏差 ±5%RH;
採樣週期:大於等於1秒/次。
元器件 | 引腳 | 樹莓派GPIO |
---|---|---|
DHT11 | VDD | 5V Power(pin2) |
DATA | GPIO24(pin18) | |
GND | Ground(pin14) | |
溫度告警指示燈 | 正極 | GPIO23(pin16) |
負極 | Ground(pin6) | |
溼度告警指示燈 | 正極 | GPIO25(pin22) |
負極 | Ground(pin9) |
鏈接後的實物圖:
程序編寫
爲了讓整個程序更加便於理解和維護,咱們將程序的各個模塊寫成獨立node-red流程,每一個流程完成獨立的功能,node-red的啓動能夠參考 node-red安裝和啓動教程
本實踐編寫完成的node-red流程 下載保存 後,可直接導入本身的設備中體驗,只需修改任意MQTT節點中服務端地址、用戶名和密碼便可,具體方法後邊教程有提示。
流程模塊 | 描述 |
---|---|
獲取傳感器數據流程 | 1s週期採集傳感器數據並保存在全局變量中 |
獲取配置信息流程 | 從雲端拉取設備影子做爲配置信息,初始化設備 |
上報溫溼度數據流程 | 30s週期上報溫溼度數據 |
告警觸發與上報流程 | 實時監測溫溼度變化,達到閾值時觸發告警指示燈點亮,並上報當前設備狀態 |
接收雲端指令流程 | 接收雲端下發的溫溼度告警閾值配置、熄滅告警指示燈指令 |
獲取傳感器數據流程
設置當前溫溼度狀態function節點代碼
global.set('humidity',Number(msg.humidity).toFixed(2))
global.set('temperature',Number(msg.payload).toFixed(2))
return {};
獲取配置信息流程
先檢測一下消息發佈節點是否就緒,使用get_shadow組裝payload,向$baidu/iot/shadow/demo01/get主題發佈消息,請求得到設備影子,get_shadow function節點代碼
var res={}
var parmars={
"requestId": new Date().getTime(),
}
res.payload=parmars
return res;
對$baidu/iot/shadow/demo01/get主題的訂閱,對應node-red中的MQTT輸出節點,第一次使用時添加該節點到界面內,雙擊配置信息,會要求先選擇mqtt鏈接配置
返回頁面選中剛剛新建的服務端,設置主題爲$baidu/iot/shadow/demo01/get,點擊完成便可完成MQTT客戶端配置,此後再須要使用MQTT節點時,不須要再次配置鏈接信息,只須要設置相應的發佈或訂閱主題便可
訂閱$baidu/iot/shadow/demo01/get/accepted主題,接收天工返回的設備影子信息,並使用初始化設備狀態,function節點代碼
global.set('temperature_alarm_value',msg.payload.reported.temperature_alarm_value)
global.set('humidity_alarm_value',msg.payload.reported.humidity_alarm_value)
global.set('humidity_alarm',0)
global.set('temperature_alarm',0)
global.set('humidity',0)
global.set('temperature',0)
global.set('humidity_alarm_has_reported',false)
global.set('temperature_alarm_has_reported',false)
return {};
可同時訂閱$baidu/iot/shadow/demo01/update/rejected主題,調試過程當中,如設備影子請求失敗,會在此接收到消息
上報溫溼度數據
設置觸發器,每30s觸發formate函數執行一次,formate函數會從全局變量中得到當前設備記錄的溫溼度數值,組裝設備影子上報消息,向$baidu/iot/shadow/demo01/update主題發佈更新設備影子信息,formate function代碼
var res={}
var parmars={
"requestId": new Date().getTime(),
"reported": {}
}
parmars.reported.randomnum=Math.random(100)*1000
parmars.reported.temperature=global.get('temperature')
parmars.reported.humidity=global.get('humidity')
res.payload=parmars
return res;
告警觸發與上報
h_alarm_on代碼
var res={}
var turn_on=0
if(global.get('humidity')>global.get('humidity_alarm_value')){
global.set('humidity_alarm',1)
if(global.get('humidity_alarm_has_reported')){
}else{
global.set('humidity_alarm_has_reported',true)
turn_on=1
}
}
res.payload=turn_on
return res;
formate代碼
var res={}
var parmars={
"requestId": new Date().getTime(),
"reported": {}
}
parmars.reported.randomnum=Math.random(100)*1000
parmars.reported.temperature=global.get('temperature')
parmars.reported.humidity=global.get('humidity')
parmars.reported.temperature_alarm=global.get('temperature_alarm')
parmars.reported.humidity_alarm=global.get('humidity_alarm')
res.payload=parmars
return res;
通過上邊的流程編寫以後,咱們將程序部署到樹莓派中去,只須要點擊頁面右上角的部署,node-red會把咱們編寫的程序自動部署並運行
接着咱們就能夠經過觀察控制檯設備影子數據變化驗證咱們的成果了。
step1:觀察控制檯設備影子數據變化,初始時像這樣,設備開始上報數據了
step2:簡單粗暴的方式,向傳感器哈氣,固然是用加溼器或電吹風效果更突出,效果是這樣,溫溼度數值增高,報警燈亮起
最後咱們演示一下如何向設備下發指令,下發指令操做咱們使用控制檯提供的下發功能,固然你也能夠經過調用天工提供的api實現,在咱們的demo中設備能夠響應的指令有兩種,一種是控制告警指示燈熄滅,另外一種遠程設置告警閾值。
打開demo01物影子詳情頁,切換到物詳情tab,將6個屬性所有設置爲「上報即存儲」,設置以後設備上報的全部數據將自動存儲到咱們設置的TSDB中
使用物可視大屏將設備數據彙總顯示,關於物可視的使用請閱讀物可視相關文檔,此處咱們直接展現本次基於單臺設備經過拖拉拽零代碼實現的大屏效果,更多效果能夠進一步發掘
此外,你也能夠發掘更多的控制方法,好比控制端經過建立MQTT鏈接,向更新設備影子主題發佈包含desired的消息,如下原始控制指令可參考
指令下發topic
$baidu/iot/shadow/demo01/update
設置閾值
{
"requestId":"1234567890",
"desired":{
"humidity_alarm_value":12,
"temperature_alarm_value":24
}
}
消除告警
{
"requestId":"1234567890",
"desired":{
"temperature_alarm":0,
"humidity_alarm":0
}
}
複製並粘貼保存爲.json文件,導入你的node-red便可使用(必定要記得修改MQTT節點的信息)
[{"id":"e0b82240.b53ae","type":"tab","label":"獲取環境溫溼度","disabled":false,"info":""},{"id":"79ed18b7.b0cba8","type":"tab","label":"獲取設備影子","disabled":false,"info":""},{"id":"fcc59dc.0f9396","type":"tab","label":"上報設備狀態","disabled":false,"info":""},{"id":"eb9cfc66.b315","type":"tab","label":"指示燈告警","disabled":false,"info":""},{"id":"cc69204f.1129b","type":"tab","label":"接收雲端指令","disabled":false,"info":""},{"id":"876561eb.4dc06","type":"mqtt-broker","z":"","name":"mqtt-demo01","broker":"1cb210f148044b6c8ac45382ef0d9e02.mqtt.iot.gz.baidubce.com","port":"1883","clientid":"demo01","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"aeaf02d5.9bfb","type":"mqtt out","z":"79ed18b7.b0cba8","name":"","topic":"$baidu/iot/shadow/demo01/get","qos":"0","retain":"","broker":"876561eb.4dc06","x":670,"y":60,"wires":[]},{"id":"1c4ebe.2fe0c143","type":"mqtt in","z":"79ed18b7.b0cba8","name":"","topic":"$baidu/iot/shadow/demo01/get/accepted","qos":"0","datatype":"json","broker":"876561eb.4dc06","x":220,"y":160,"wires":[["32f0f23.b929f0e"]]},{"id":"32f0f23.b929f0e","type":"function","z":"79ed18b7.b0cba8","name":"初始化設備","func":"\n\nglobal.set('temperature_alarm_value',msg.payload.reported.temperature_alarm_value)\n\nglobal.set('humidity_alarm_value',msg.payload.reported.humidity_alarm_value)\n\nglobal.set('humidity_alarm',0)\n\nglobal.set('temperature_alarm',0)\n\nglobal.set('humidity',0)\n\nglobal.set('temperature',0)\n\nglobal.set('humidity_alarm_has_reported',false)\n\nglobal.set('temperature_alarm_has_reported',false)\n\n\n\nreturn {};\n\n\n","outputs":1,"noerr":0,"x":520,"y":160,"wires":[["27781181.55b2be"]]},{"id":"27781181.55b2be","type":"debug","z":"79ed18b7.b0cba8","name":"獲取影子成功","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":740,"y":160,"wires":[]},{"id":"ad0d021d.af49f","type":"function","z":"79ed18b7.b0cba8","name":"get_shadow","func":"var res={}\n\nvar parmars={\n \"requestId\": new Date().getTime(),\n}\n\nres.payload=parmars\n\nreturn res;","outputs":1,"noerr":0,"x":370,"y":60,"wires":[["aeaf02d5.9bfb"]]},{"id":"1e5c7528.4ac8eb","type":"status","z":"79ed18b7.b0cba8","name":"","scope":["1c4ebe.2fe0c143"],"x":140,"y":60,"wires":[["ad0d021d.af49f"]]},{"id":"55874635.ff36b8","type":"inject","z":"fcc59dc.0f9396","name":"週期上報","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":260,"wires":[["464a70e6.efb22","b17d0f7c.856ed"]]},{"id":"464a70e6.efb22","type":"function","z":"fcc59dc.0f9396","name":"formate","func":"var res={}\n\nvar parmars={\n \"requestId\": new Date().getTime(),\n \"reported\": {}\n}\nparmars.reported.randomnum=Math.random(100)*1000\n\nparmars.reported.temperature=global.get('temperature')\n\nparmars.reported.humidity=global.get('humidity')\n\n\nres.payload=parmars\n\nreturn res;","outputs":1,"noerr":0,"x":380,"y":260,"wires":[["a4e7196e.af6578","66b34bbc.208864"]]},{"id":"a4e7196e.af6578","type":"mqtt out","z":"fcc59dc.0f9396","name":"","topic":"$baidu/iot/shadow/demo01/update","qos":"0","retain":"","broker":"876561eb.4dc06","x":720,"y":260,"wires":[]},{"id":"bcdb86b3.317e38","type":"rpi-gpio out","z":"cc69204f.1129b","name":"溫度告警燈","pin":"16","set":true,"level":"0","freq":"","out":"out","x":650,"y":200,"wires":[]},{"id":"41b5ee5b.2e3fa","type":"mqtt out","z":"cc69204f.1129b","name":"","topic":"$baidu/iot/shadow/demo01/update","qos":"0","retain":"","broker":"876561eb.4dc06","x":980,"y":320,"wires":[]},{"id":"1b30c52e.29897b","type":"function","z":"cc69204f.1129b","name":"t_alarm_off","func":"\nvar res={}\nvar turn_on=0\n\nif(msg.payload.desired.temperature_alarm==1){\n turn_on=1\n}\nres.payload=turn_on\n\nreturn res;","outputs":1,"noerr":0,"x":390,"y":160,"wires":[["479a6a71.773114"]]},{"id":"8a6175a2.3e85a8","type":"function","z":"cc69204f.1129b","name":"h_alarm_off","func":"var res={}\nvar turn_on=0\n\nif(msg.payload.desired.humidity_alarm==1){\n turn_on=1\n}\n\n\nres.payload=turn_on\n\nreturn res;","outputs":1,"noerr":0,"x":390,"y":280,"wires":[["d9c514fd.bd0d88"]]},{"id":"4fab39be.a5d838","type":"rpi-gpio out","z":"cc69204f.1129b","name":"溼度告警燈","pin":"22","set":true,"level":"0","freq":"","out":"out","x":650,"y":280,"wires":[]},{"id":"67b64145.91291","type":"mqtt in","z":"cc69204f.1129b","name":"","topic":"$baidu/iot/shadow/demo01/delta","qos":"0","datatype":"json","broker":"876561eb.4dc06","x":150,"y":280,"wires":[["1b30c52e.29897b","8a6175a2.3e85a8","c2f39cb9.96667","4f0b2611.ff8238"]]},{"id":"8b3c3146.b77f2","type":"function","z":"cc69204f.1129b","name":"t_alarm_reported","func":"\nvar res={}\nglobal.set('temperature_alarm',0)\nglobal.set('temperature_alarm_has_reported',false)\n\nvar parmars={\n \"requestId\": new Date().getTime(),\n \"reported\": {}\n}\nparmars.reported.randomnum=Math.random(100)*1000\n\nparmars.reported.temperature_alarm=msg.payload==1?1:0\n\n\nres.payload=parmars\n\nreturn res;","outputs":1,"noerr":0,"x":670,"y":160,"wires":[["41b5ee5b.2e3fa","c207e56d.a67738"]]},{"id":"67886b16.9d5274","type":"function","z":"cc69204f.1129b","name":"h_alarm_reported","func":"\n\nvar res={}\nglobal.set('humidity_alarm',0)\nglobal.set('humidity_alarm_has_reported',false)\nvar parmars={\n \"requestId\": new Date().getTime(),\n \"reported\": {}\n}\nparmars.reported.randomnum=Math.random(100)*1000\n\nparmars.reported.humidity_alarm=msg.payload==1?1:0\n\n\nres.payload=parmars\n\nreturn res;","outputs":1,"noerr":0,"x":670,"y":320,"wires":[["41b5ee5b.2e3fa","c207e56d.a67738"]]},{"id":"4ff05547.39024c","type":"function","z":"cc69204f.1129b","name":"set_alarm","func":"var parmars={\n \"requestId\": new Date().getTime(),\n \"reported\": {\n temperature_alarm_value:global.get('temperature_alarm_value')||100,\n humidity_alarm_value:global.get('humidity_alarm_value')||100\n }\n}\n\nif(msg.payload.desired.temperature_alarm_value){\n global.set('temperature_alarm_value',msg.payload.desired.temperature_alarm_value)\n parmars.reported.temperature_alarm_value=msg.payload.desired.temperature_alarm_value\n}\n\nif(msg.payload.desired.humidity_alarm_value ){\n global.set('humidity_alarm_value',msg.payload.desired.humidity_alarm_value) \n parmars.reported.humidity_alarm_value=msg.payload.desired.humidity_alarm_value\n}\n\n\nmsg.payload=parmars\n\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":420,"wires":[["41b5ee5b.2e3fa","c207e56d.a67738"]]},{"id":"d9c514fd.bd0d88","type":"switch","z":"cc69204f.1129b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":320,"wires":[["67886b16.9d5274","4fab39be.a5d838"]]},{"id":"479a6a71.773114","type":"switch","z":"cc69204f.1129b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":200,"wires":[["8b3c3146.b77f2","bcdb86b3.317e38"]]},{"id":"c2f39cb9.96667","type":"function","z":"cc69204f.1129b","name":"if_set_alarm","func":"\nvar parmars=msg.payload.desired.hasOwnProperty(\"temperature_alarm_value\")||msg.payload.desired.hasOwnProperty(\"humidity_alarm_value\")\n\nmsg.to_set=parmars\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":380,"wires":[["bdaa5c71.ca261"]]},{"id":"bdaa5c71.ca261","type":"switch","z":"cc69204f.1129b","name":"","property":"to_set","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":420,"wires":[["4ff05547.39024c"]]},{"id":"8b4e4b3d.6d7ae8","type":"mqtt in","z":"fcc59dc.0f9396","name":"","topic":"$baidu/iot/shadow/demo01/update/accepted","qos":"0","datatype":"json","broker":"876561eb.4dc06","x":230,"y":400,"wires":[["66b34bbc.208864"]]},{"id":"66b34bbc.208864","type":"debug","z":"fcc59dc.0f9396","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":400,"wires":[]},{"id":"ca8cd639.9a4258","type":"debug","z":"79ed18b7.b0cba8","name":"獲取影子失敗","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":540,"y":260,"wires":[]},{"id":"a9da906e.29bde","type":"mqtt in","z":"79ed18b7.b0cba8","name":"","topic":"$baidu/iot/shadow/demo01/update/rejected","qos":"0","datatype":"json","broker":"876561eb.4dc06","x":230,"y":260,"wires":[["ca8cd639.9a4258"]]},{"id":"2981152c.63017a","type":"rpi-dht22","z":"e0b82240.b53ae","name":"讀DHT11數據","topic":"rpi-dht11","dht":"11","pintype":"0","pin":"18","x":400,"y":240,"wires":[["a2c9546.eeb9ca8","b835ff81.33c0c"]]},{"id":"a2c9546.eeb9ca8","type":"function","z":"e0b82240.b53ae","name":"設置設備當前溫溼度狀態","func":"\nglobal.set('humidity',Number(msg.humidity).toFixed(2))\nglobal.set('temperature',Number(msg.payload).toFixed(2))\n\nreturn {};","outputs":1,"noerr":0,"x":630,"y":240,"wires":[["c3c0dca4.3972d"]]},{"id":"6662a21c.a9726c","type":"inject","z":"e0b82240.b53ae","name":"週期觸發器","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":240,"wires":[["2981152c.63017a"]]},{"id":"cb542070.5ebac","type":"rpi-gpio out","z":"eb9cfc66.b315","name":"溫度告警燈","pin":"16","set":true,"level":"0","freq":"","out":"out","x":790,"y":420,"wires":[]},{"id":"aecdb85d.c5d758","type":"rpi-gpio out","z":"eb9cfc66.b315","name":"溼度告警燈","pin":"22","set":true,"level":"0","freq":"","out":"out","x":790,"y":240,"wires":[]},{"id":"3da13ab1.337fb6","type":"inject","z":"eb9cfc66.b315","name":"","topic":"","payload":"humidity","payloadType":"global","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":240,"wires":[["85ca2d2.6cbc7d"]]},{"id":"69c07bf5.efa0c4","type":"inject","z":"eb9cfc66.b315","name":"","topic":"","payload":"temperature","payloadType":"global","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":420,"wires":[["72da2f99.47e7b"]]},{"id":"65a20d4f.e76724","type":"mqtt out","z":"eb9cfc66.b315","name":"","topic":"$baidu/iot/shadow/demo01/update","qos":"0","retain":"","broker":"876561eb.4dc06","x":1060,"y":360,"wires":[]},{"id":"72da2f99.47e7b","type":"function","z":"eb9cfc66.b315","name":"t_alarm_on","func":"var res={}\nvar turn_on=0\n\n\n\nif(global.get('temperature')>global.get('temperature_alarm_value')){\n\n if(global.get('temperature_alarm_has_reported')){\n\n}else{\n global.set('temperature_alarm_has_reported',true) \n turn_on=1\n}\n}\nres.payload=turn_on\n\nreturn res;","outputs":1,"noerr":0,"x":450,"y":420,"wires":[["7066ca16.508d64"]]},{"id":"85ca2d2.6cbc7d","type":"function","z":"eb9cfc66.b315","name":"h_alarm_on","func":"\nvar res={}\nvar turn_on=0\nif(global.get('humidity')>global.get('humidity_alarm_value')){\n global.set('humidity_alarm',1)\n if(global.get('humidity_alarm_has_reported')){\n \n }else{\n global.set('humidity_alarm_has_reported',true)\n turn_on=1\n }\n}\nres.payload=turn_on\nreturn res;","outputs":1,"noerr":0,"x":450,"y":240,"wires":[["4dd08a6c.87ecc4"]]},{"id":"7066ca16.508d64","type":"switch","z":"eb9cfc66.b315","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":420,"wires":[["cb542070.5ebac","c83ff371.eaa0e"]]},{"id":"4dd08a6c.87ecc4","type":"switch","z":"eb9cfc66.b315","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":240,"wires":[["aecdb85d.c5d758","c83ff371.eaa0e"]]},{"id":"c3c0dca4.3972d","type":"debug","z":"e0b82240.b53ae","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":850,"y":240,"wires":[]},{"id":"c83ff371.eaa0e","type":"function","z":"eb9cfc66.b315","name":"formate","func":"var res={}\n\nvar parmars={\n \"requestId\": new Date().getTime(),\n \"reported\": {}\n}\nparmars.reported.randomnum=Math.random(100)*1000\n\nparmars.reported.temperature=global.get('temperature')\n\nparmars.reported.humidity=global.get('humidity')\n\nparmars.reported.temperature_alarm=global.get('temperature_alarm')\n\nparmars.reported.humidity_alarm=global.get('humidity_alarm')\n\n\nres.payload=parmars\n\nreturn res;","outputs":1,"noerr":0,"x":780,"y":340,"wires":[["65a20d4f.e76724","c3d36c20.b83a6"]]},{"id":"c3d36c20.b83a6","type":"debug","z":"eb9cfc66.b315","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":280,"wires":[]},{"id":"4f0b2611.ff8238","type":"debug","z":"cc69204f.1129b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":390,"y":520,"wires":[]},{"id":"c207e56d.a67738","type":"debug","z":"cc69204f.1129b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":220,"wires":[]},{"id":"b835ff81.33c0c","type":"change","z":"e0b82240.b53ae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"100","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":400,"wires":[["a490710e.a86f7"]]},{"id":"a490710e.a86f7","type":"debug","z":"e0b82240.b53ae","name":"測試change","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":400,"wires":[]},{"id":"b17d0f7c.856ed","type":"change","z":"fcc59dc.0f9396","name":"組裝數據","rules":[{"t":"set","p":"payload.requestId","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":140,"wires":[["791b173b.086ba8"]]},{"id":"791b173b.086ba8","type":"debug","z":"fcc59dc.0f9396","name":"組裝數據結果","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":680,"y":140,"wires":[]}]