728x90
A Node-RED UI widget node which displays data as a table.
데이터를 테이블 리스트 형태로 보여줍니다.
MongoDB에서 비콘정보를 읽어들여 Node-red에서 리스트 형태로 표시합니다.
Function Node find.toArray
msg.collection = 'CL_DEVICE_DATA_2';
msg.operation = 'find.toArray';
msg.payload = { };
// msg.payload = { "DE_MAC" : "AC:23:3F:50:1B:60", "GW_MAC" : "B8:27:EB:20:EA:17" };
return msg;
Function node - return array
일정시간내 데이터를 json 형태로 변환하여 테이블 노드에 전달한다.
var today = new Date(Date.now() - 1000*4);
var aJsonArray = new Array();
for(var i = 0; i < msg.payload.length; i++)
{
var d = new Date(msg.payload[i].GW_DT_UTC);
if(today < d) {
var aJson = new Object();
aJson.DE_MAC = msg.payload[i].DE_MAC;
aJson.GW_MAC = msg.payload[i].GW_MAC;
aJson.RSSI = msg.payload[i].RSSI;
aJson.GW_DT = msg.payload[i].GW_DT;
aJsonArray.push(aJson);
}
}
var text = JSON.stringify(aJsonArray);
var obj = JSON.parse(text); // JSON.parse( // JSON.parse(text);
msg.payload = obj;
return msg;
RSSI sort
RSSI 신호 세기에 따라 리트스를 정렬한다.
/ sort
function customSort(a, b)
{
if(a.RSSI == b.RSSI) return 0;
else if(a.RSSI > b.RSSI) return -1
else return 1;
}
aJsonArray.sort(customSort);
Reference
flows.nodered.org/node/node-red-node-ui-table
'DATABASE' 카테고리의 다른 글
Pymongo rest.py & Studio 3T (0) | 2020.10.03 |
---|---|
Beacon Scanner Test on Node-RED (0) | 2020.09.30 |
Node-RED on MongoDB (0) | 2020.09.30 |