Bulk serial port data and sending to a database

Hello,
I receive from a serial port a burst of data that obviously always ends with a line break.
If I send this data to a file it looks like this.

On the other hand I try to store each value visibly separated by a space in a database and stop when the linebreak character arrives.
Then start again with the next dataset that will arrive, send this again in the database but obvious to the next record.
Each value will obviously be written in a specific variable and then I will push these variables in the ad-oc fields of the database.
Do you have an idea how to proceed?
I hope I have been as clear as possible :thinking:
Thank you for your help.
/JL

Here's what comes out raw and bursting from the serial node with the debug node

How have you configured the serial port, have you tried telling it to split on new line?

Here is the port setting

Hi Jean Luc
Just a couple of questions. Is the number of the data values and format constant or can it vary? and what type of database are you using?

Regards
Andrew

Okay,
I changed a bit the entrance to wait 1000 ms and now it's better indeed

image

I don't know exactly yet because I just had my first conversation with my hybrid inverter today.
I have the impression that the data will be the same length for each type of question.
One question, answer always the same number of fields.
I will use influxDB and Grafana.

If each line ends in a newline then would it not be better to split on that? It would be \n or \r

okay, changed with:
image
i receive this, it's better than waiting !


I feel i'm now going to use the String Node to try splitting into an array, like that
image
But I don't know at the moment how to fill this node to tell it to cut on a separator which is a character which is a space ?

I would do that by writing some javascript in a Function node. First I would check that the first character is a ( and discard the message if not as that means something has got out of sync. Then I would (in javascript) split the rest on the space character to give an array, then assign the values to attributes of the payload.

Here it's works. Thanks to all.
Quick response and solution. It's cool!

If you know what each column is then you could use a csv node set to split on a space rather than a comma. That would then assign each value by a named property

1 Like

Thank you Colin,
I think I have my solution with this string knot.

I will be able to create beautiful graphs on the photovoltaic production as well as control certain relays and other alarms. Node red & Raspberry is too cool for that.
But... still... it should be sunny :wink:

All goes well !
I was able to store the inverter values in my database and start making graphs,
BUT for some unknown reason, sometimes the communication on the serial port gets blocked.
I have the feeling that the serial port is not responding anymore.
In order to make it work again I'll reboot the Pi and then it's OK.
I saw that it is possible to close and reopen the ttyUSB0 port in Linux.
On this one my inverter is seen via the cp210x chip.

If you have an idea how to fix this big flaw, it will be cool. :dizzy:

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