Reading Arduino serial data into node red via usb

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.

Screenshot 2021-02-22 at 11.25.04

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.

Hi thanks for reply.
this is out my nano : Must i change it to be a single line output

Serial.print("h: ");
Serial.println(" % ");
Serial.print("t: ");
Serial.println(" *c ");
Serial.print("Heat Index: ");
Serial.println(" *C ");
Serial.print("Dew ");
Serial.print("DOOR STAT : ");

then on node red what should my serial in be set on

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.

I would send the following


And then in a function node

var output = msg.payload.split(":");

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};

return [msg0 , msg1, msg2, msg3, msg4];


The serial setting are the same as on you nano

Does that have an advantage over my suggestion which uses a single Change node instead of a function node with four outputs?

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.

Sending JSON (instead of string splitting) is the better solution. Every time, any day of the week.