Good day All.
I am new to the node red system and i use openhab. as fisialatition of my home automation. now i am trying to use nano's as sensor breakouts on my server to monitor my server room the serial link via usb works and i get the date to node red. but now i want to split the date out to different mqtt topics to my openhab .
my problem comes in with the split out of data. this is what i get in the Serial monitor of my ide.
in node red it splits them in to strings. how do i get that in to the mqtt channels i want to use ?
If you have control of the s/w in the nano (as I presume you do) then a good solution may to send the data to node-red in the form of JSON, so the example you show would be a string containing something like
{"h": 58, "t": 28.1, "Heat Index": 23.34, ...}
Then in node-red you can feed that into a JSON node to convert it to a javascript object. Then the rest is easy.
I would do it as one json string probably. Alternatively if all you want to do is to send it straight to MQTT then send it as separate lines like
{"topic": "h", "value": 58}
{"topic": "t", "value": 28.1}
and so on. Then in node red you will receive the messages one at a time and in a Change node can 'Set msg.topic To msg.payload.topic' and 'Move msg.payload.value To msg.payload' and send that direct to the MQTT node.
var h = parseFloat(output[0]);
var t = parseFloat(output[1]);
var heat = parseFloat(output[2]);
var dew = parseFloat(output[3]);
var door = parseFloat(output[3]);
var msg0 = {payload:h};
var msg1 = {payload:t};
var msg2 = {payload:heat};
var msg3 = {payload:dew};
var msg4 = {payload:door};
Thanks .
I actual used both the only issue i picked up with the function now is that i lose one value .
i lost the dew value. and cant seem to get it sorted. but both are winners. not sure what is the best way. but will run both as i have 2 setups like this and will monitor them.