Node Red to CSV File Data Collection

Hi All,

I am using NodeRed to Collect Data into a CSV File, but each time the data collection is triggered, it shifts the data to the right. Meaning, that the data por column changes on each row.

What options are there to always drop the value on the same column?



I use the CSV node a ton in my personal project (of tracking global aircraft movements) and have never seen this ‘shifting to the right’. Ever… weird.

Here is how my CSV node is set up:
This is when the node is right after the file in node.

In your case do you mean when reading or writing the file?

Here is how my CSV node is setup when writing OUT to a file:

Note the 5 columns and using a comma this time between fields.

Between those two options (read and write) you should be able to spot any differences with yours.

Lets know how you get on and what you find… super interested in this one.

Thanks, i tried setting it up as you have it but i still get the same problem. If you look to the photo, on the debug section, youll see that the values shifts place.

Each time i trigger the node, it started with the date, then with the value 140, then it moved to the next one.

Is it because of how i am gathering the data?

Screen Shots of the nodes

You asked if its because of how you are collecting the data… I am pretty sure the answer is yes.


Node-RED will NOT inject those in order, they will be all over the place. Thats why its moving about in your CSV is my bet.

Not sure what each function node is doing, but with a slight tweak, it should become a lot more reliable.
Rearrage it like this (cut down example) and change each PAC node to have it’s own unique property name for each value, i.e. msg.ppm_spoint, msg.scm_spooint, etc. ie a unique payload name).
Then reference each msg.unique_name for each part of the CSV and it should stay in order.

(You get the idea, clearly, you will need to ensure each of your PAC read nodes are included etc).

1 Like

Thanks Beno,

When you say reference each msg.unique_name for each aprt of the CSV, is to add each variable into the name area of the node?

When i did it that way, it didnt complete the flow.

Can you put a debug on the output of the join node and share what it’s sending out?
That would really help figure out what’s going on.

No, I mean you will need to (must) change each pac node or they will overwrite each msg.payload.
At the end of the string, you must have a different name for each pac nodes payload.


Sure, ill attach the Pac Read, the function node and the debug notification is on it.

I added the debug node to see if it ready anything, but says undefined. When using the debug at the Pacread, it works.

These are back to front.

You need to move msg.payload into msg.fl_PPM_SPoint

msg.fl_PPM_SPoint = msg.payload;
return msg;
1 Like

Thanks Beno,

I changed it as recommended, but I still can’t get the flow to continue at the Join Node.

Can you guys send over an example of multiple variables going into a join node?


Can you send a screenshot of the join node?
Not sure you need it with the ‘serial’ way of collecting each msg.payload into a unique msg.

I will try and find some time to show how to build a CSV file from different payloads, I think that will be of greater benefit in getting you going.

The attached screen shot.

That would be much appreciated. Even a screen video would do, if possible.


It’s important to keep in mind that there are many different ways to do the same thing in all programming languages, Node-RED is no different.

Here is what I had in mind when I first replied, sorry I was not able to explain it very well…

I have used the same analog input, but in your case, each pac node reads its value and puts the data into msg.payload.

The following function block then moves the msg.payload into a uniquely named msg.

While it works, its a bit double handling because the PAC node itself can put the data in a unique name.

Here is an example of using the pac node to do that:

The end result is you have the exact same CSV output and less nodes.

And here is the flow:

[{"id":"458778ba021a573a","type":"inject","z":"5f29e0bd7dba64d7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":820,"y":240,"wires":[["29b3bd14ece80cf8"]]},{"id":"ef92734ec479da70","type":"function","z":"5f29e0bd7dba64d7","name":"Build","func":"//Build the msg.payload\nmsg.payload = {\n    PPM: msg.fl_PPM_SPoint,\n    SCM: msg.fl_SCM_SetPoint,\n    UV: msg.fl_UV_Meter_2\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1670,"y":240,"wires":[["449e27f95c572ef5","b9b9e34101671791"]]},{"id":"449e27f95c572ef5","type":"debug","z":"5f29e0bd7dba64d7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1950,"y":160,"wires":[]},{"id":"b9b9e34101671791","type":"csv","z":"5f29e0bd7dba64d7","name":"","sep":",","hdrin":false,"hdrout":"none","multi":"one","ret":"\\n","temp":"PPM, SCM, UV","skip":"0","strings":false,"include_empty_strings":"","include_null_values":"","x":1870,"y":240,"wires":[["a5c3b5502e3b5f99"]]},{"id":"a5c3b5502e3b5f99","type":"debug","z":"5f29e0bd7dba64d7","name":"wire to file node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2000,"y":440,"wires":[]},{"id":"48a8901022b8bc8c","type":"pac-read","z":"5f29e0bd7dba64d7","device":"91968b30802a8360","dataType":"ana-input","tagName":"FuelLevelPot","tableStartIndex":"","tableLength":"","value":"fl_SCM_SetPoint","valueType":"msg","topic":"","topicType":"none","name":"msg.fl_SCM_SetPoint","x":1260,"y":240,"wires":[["5082c99c4fe0c966"]]},{"id":"29b3bd14ece80cf8","type":"pac-read","z":"5f29e0bd7dba64d7","device":"91968b30802a8360","dataType":"ana-input","tagName":"FuelLevelPot","tableStartIndex":"","tableLength":"","value":"fl_PPM_SPoint","valueType":"msg","topic":"","topicType":"none","name":"msg.fl_PPM_SPoint","x":1020,"y":240,"wires":[["48a8901022b8bc8c"]]},{"id":"5082c99c4fe0c966","type":"pac-read","z":"5f29e0bd7dba64d7","device":"91968b30802a8360","dataType":"ana-input","tagName":"FuelLevelPot","tableStartIndex":"","tableLength":"","value":"fl_UV_Meter_2","valueType":"msg","topic":"","topicType":"none","name":"msg.fl_UV_Meter_2","x":1500,"y":240,"wires":[["ef92734ec479da70"]]},{"id":"91968b30802a8360","type":"pac-device","address":"localhost","protocol":"https","msgQueueFullBehavior":"DROP_OLD"}]

You will need to change your PAC host and API key, but it will give you the jump start to get all the data in order.
No more jumping to the right as each PAC node is read one after the other.

1 Like

Thanks! Will be working with this!