我是node-red和IoT的新手,但目前正在開發一個項目。 基本上我的目標是爲施工人員創建一個警報系統。我想測量高度,環境溫度和安全機制的狀態(鎖定或不鎖定)。根據讀數,系統應該做出決定(如果測量超過閾值 - 發送通知[蜂鳴器/ LED])。在Node-RED中實現多個輸入
的邏輯如下:
- 當系統導通時,測量初始高度(H初始),
- 的時間(沒有定義還)在特定時間段之後,測量電流高度(h電流)。
- 當前和初始高度之間的差異將是工人的實際高度(h)。
- 如果高度h高於2米 - 發送蜂鳴器信號。如果h小於0,則再次計算h初始和h電流。
我已將TI CC2650 SensorTag連接到RPi的Node-red,並將測量結果作爲json對象發送給節點紅色,具體取決於您希望讀取多少個傳感器讀數。在我的情況下(溫度和壓力)我又接收兩個jsons:
{ "d": { "id": "b827ebb2b2bd.c4be84711c81.0", "tstamp": { "$date": 1469565713321 }, "json_data": { "object": 21.40625, "ambient": 27.125 } } }
{ "d": { "id": "b827ebb2b2bd.c4be84711c81.4", "tstamp": { "$date": 1469565713328 }, "json_data": { "pressure": 1016.36 } } }
我所面臨以下問題:
我不能養活多個數據節點紅色。想知道是否有人能指導我如何發送(溫度,壓力,機制的狀態[1或0]數據)到功能節點;
關於警報。基本上,要找到我需要進行兩次高度測量的實際高度。意思是,我需要以某種方式存儲兩個壓力/溫度測量值。我是否需要將測量數據存儲爲數組,或者有更好的方法來處理這個問題?
想知道是否有人可以指導/幫助我這個。
P.S.流量的剪貼板很長,所以我決定不要粘貼在這裏,但如果有人請求,可以發送它。
非常非常原始代碼
var hInit;
var hChecked;
var h;
//p0 is the hardcoded pressure on the level of the sea
//hardcoded for the current area
var p0 = 1019;
//extract the pressure value and the ambient temp from jsons
tagPressure = msg.payload.json_data.pressure;
tagTemp = msg.payload.json_data.ambient;
//the formula to convert a pressure to an altitude
//here it should measure the altitde (hInit) when the testbest is turned on
hInit = (((Math.pow((tagTemp/p0), (1/5.257)))-1)*(tagTemp + 273.15))/0.0065;
//hChecked is the measured altitude afterwards
hChecked = (((Math.pow((tagTemp/p0), (1/5.257)))-1)*(tagTemp + 273.15))/0.0065;
//h is the actual altitude the worker is working on
h = hChecked - hInit;
//in the case if a worker turned the testbed on
//when he was operating on the altitude he then
//might go down so altitude can reduce.
//therefore if the altitude h is < 0 we need to
//calculate a new reference
if (h < 0) {
hInit = (((Math.pow((tagTemp/p0), (1/5.257)))-1)*(tagTemp + 273.15))/0.0065;
hChecked = (((Math.pow((tagTemp/p0), (1/5.257)))-1)*(tagTemp + 273.15))/0.0065;
h = hChecked - hInit;
return h;
}
//check current altitude
while (h>0){
if (h>2){
if (lockerState == 1) {
msg.payload = "safe";
return msg;
}
else if (lockerState === 0) {
msg.payload = "lock your belt!";
//basically i want to send a 1 signal
//to the buzzer which is a pin on the RPI3
//so probably msg.payload = 1;
return msg;
}
}
}
//return msg;
謝謝!上下文幫助我! –