Convert serial messages into object


I have an MPPT Solar controller that sends me on serial port, every second, this three separated messages:

CS: 5
VPV: 12
HDS: 11

Node red treats them as separated messages, because they force me to split them by "\n" How could I join them and get an object like {"CS": 5, "VPV": 12, "HDS": 11} ?

That doesn't make sense. First you say the device sends you three messages, then you say you had to split it, which suggests they come in one message.

Sorry if not explained well. The MPPT Solar controller sends the message not splitted but

This node forces me to split by "\n". If I remove "\n", it splits every char... I don't want to split the message.

If you want to join them back up again then I suggest not splitting in the serial node. Can you use a timeout of, maybe 500ms to give you the messages? If so then in a function node you can use the split("\n") to give you an array of three elements, then split each one of those using : and then you can build the object from those.

If you want to go down that route but the javascript is too complex then get the serial node going first to give you the complete message. Then feed that to a debug node and you can use the little Copy button that pops up when you hover over it to capture one of the strings exactly. Paste that here and it can be used in an Inject node to simulate your data and can be used to test the code.

1 Like

I did something similar, I found a character that "more or less" limits the entire message and with some regex I parsed it to a json object.

Thank you for your inspiration

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.