javascript - Json - Node-RED Extract -
noob looking help...
i have json stream of data looks this..
{ "header" : { "content" : "telegram", "gateway" : "en-gw", "timestamp" : "2016-08-08t13:45:47.032+0100" }, "telegram" : { "deviceid" : "01864892", "friendlyid" : "boardroom-co2-sensor", "timestamp" : "2016-08-08t13:45:47.032+0100", "direction" : "from", "functions" : [ { "key" : "humidity", "value" : 39.00, "unit" : "%" }, { "key" : "concentration", "value" : 830.00, "unit" : "ppm" } ], "telegraminfo" : { "data" : "4e53820e", "status" : "0", "dbm" : -67, "rorg" : "a5" } } }
from in node-red have function node looks this...
return [msg.payload.telegram.functions];
which returns these
{ "key": "concentration", "value": 830, "unit": "ppm", "_msgid": "ff5b0f47.00a4f" } { "key": "humidity", "value": 39, "unit": "%", "_msgid": "ff5b0f47.00a4f" } { "key": "temperature", "value": 26.6, "unit": "°c", "_msgid": "ef2d6de7.10d29" }
from these single value each e.g. 830 concentration. have check against thresholds set me in node 2 outputs. example if more 1000 output 1, less 1000 output 2.
is i'm trying achieve possible in node-red??
sorry possible noob question appreciated.
the problem not returning formatted message object. while returning function json object not conforming node-red convention.
anything return function node should have payload field if want other nodes able handle easily.
so if change return this:
return { payload: msg.payload.telegram.functions }
then downstream nodes know in msg.payload useful content of message.
as comparing keys within message set values , outputting different values that's relatively simple. in new function node this:
//check concentration exists (var i=0;i<msg.payload.length; i++) { if (msg.payload[i].concentration) { //more 1000 if (msg.payload.conentration >= 1000) { return {payload: 1}; //less 1000 } else { return {payload: 0}; } } }
Comments
Post a Comment