Separate CSV columns

Hello, I'm new to Node-RED. Having some trouble with sending data to CSV. I need two separate columns with different names and different data below for example but I'm getting everything in one line. Please tell me how to solve this.

Thank you

[{"id":"2f90ce8fb2a257e8","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"0ecfc4ef4d17d3e1","type":"inject","z":"2f90ce8fb2a257e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["d4254ce887f93f08"]]},{"id":"d4254ce887f93f08","type":"function","z":"2f90ce8fb2a257e8","name":"function 1","func":"msg.payload = {\n    \"Time\" : Math.random()*10,\n    \"Sensor\" : Math.random()*50\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":120,"wires":[["836b5d25ef304aa5","b9fdab2c3579f04f"]]},{"id":"b9fdab2c3579f04f","type":"debug","z":"2f90ce8fb2a257e8","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":60,"wires":[]},{"id":"836b5d25ef304aa5","type":"csv","z":"2f90ce8fb2a257e8","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"one","ret":"\\r\\n","temp":"Time,Sensor","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":450,"y":140,"wires":[["e8717b2e16748674","b9fdab2c3579f04f"]]},{"id":"e8717b2e16748674","type":"file","z":"2f90ce8fb2a257e8","name":"","filename":"C:\\Users\\Dell\\Documents\\Test.csv","filenameType":"str","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":720,"y":180,"wires":[[]]}]

We cannot use that code, please replace by pasting the code into a preformatted text blog.

Looking at your function code you are sending a single object into the csv node. If you require multiple lines then you would need to send an array of objects, an object for each line.
e.g.

[
  {
    "Time": 10,
    "Sensor": 50
  },
  {
    "Time": 15,
    "Sensor": 20
  }
]

Yes. I see a single object on a debug node - (time with value and sensor with value). I want to get -
(1 column - Time with value below), (2 column - Sensor with value below).

That is what you get.
it is the followed by a carriage return \r and a new line \n. This is a text csv format.

As image shows

Attach the file that is created after you click inject several times, as i see no errors.

Here - https://file.io/mguUlmI1rhfL

As said all working correct

Unless you want one header row and only one value row, if so set csv node to always send header and file write node to overwrite and not append.

Hmm, maybe is something wrong with my Excel or something else, have no idea.

This is what I want to achieve -
test

When I open test,csv in my spreadsheet I get

Must be an issue on your device/spreadsheet program if it is not opening like above.

So I achieved what I wanted just not for myself yet :smiley:
I'll try to check my software settings later, whats wrong with my MS Excel.

Not a windows user, so can not help you there, sorry.

The other thing to check is the Properties of your CSV node and make sure the boxes concerned with writing the column headers are checked.

Sometimes I want to delete my CSV file, so I have an inject node that I can manually trigger to send a msg.reset to the CSV node to force it to write the header row again when it next writes.

A post was split to a new topic: Send csv to a line chart

Sorry for bothering you with so basic stuff, I'm still playing around with those .csv exports and got a problem again. Somehow it just stopped working correctly and passing I guess empty string after each value line, can't figure it out whats wrong with the flow. Tried everything I could think of, even reinstalled Node-RED. I did not changed any settings, parameters or regional settings on my windows that could impact csv. Can anyone please help me get rid of that empty string after each value?

[{"id":"2264aaaad0fa21d2","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"14a01548145009e3","type":"inject","z":"2264aaaad0fa21d2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":120,"wires":[["2cd8ca29e301798b"]]},{"id":"2cd8ca29e301798b","type":"function","z":"2264aaaad0fa21d2","name":"function 1","func":"// Generate timestamp\nvar timestamp = new Date().getTime();\n\n// Generate random value between 0 and 1\nvar value1 = Math.random()*30;\n\n// Create payload object with timestamp and random value\nmsg.payload = {\n    Timestamp: timestamp,\n    Value1: value1\n}\n\n// Return the message\nreturn msg;\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":120,"wires":[["6412650615254c06","0cc2f16661a1127b"]]},{"id":"1d1e4cdc9cf055cf","type":"file","z":"2264aaaad0fa21d2","name":"","filename":"C:\\Users\\Dell\\Desktop\\Test1.csv","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":730,"y":120,"wires":[[]]},{"id":"6412650615254c06","type":"debug","z":"2264aaaad0fa21d2","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":80,"wires":[]},{"id":"0cc2f16661a1127b","type":"csv","z":"2264aaaad0fa21d2","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"one","ret":"\\n","temp":"Timestamp,Value1","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":490,"y":120,"wires":[["1d1e4cdc9cf055cf"]]}]

ES

You are adding a \n in csv node, and also appending one in file write node.

Either add one in csv node, or file write node, but not both nodes.

Thanks a lot.

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