Write data from 2 directions in different columns of csv file

Hello. I want to write data from 2 directions in different columns of csv file. But my data was written in one column. I'm a little confused on this issue. and wanted to sort out this problem with you. I think this will be useful not only to me, but to all Node-red users. I have an example. Help with it.

[
    {
        "id": "3da047291d2d65d0",
        "type": "inject",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "tip",
                "v": "01",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "11714368",
        "payloadType": "num",
        "x": 380,
        "y": 140,
        "wires": [
            [
                "5dd965fe633160aa",
                "511192c5688aa4dc"
            ]
        ]
    },
    {
        "id": "5dd965fe633160aa",
        "type": "debug",
        "z": "9ee2cc1b247fc8f4",
        "name": "02",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 120,
        "wires": []
    },
    {
        "id": "0110c7af1cacd1f2",
        "type": "debug",
        "z": "9ee2cc1b247fc8f4",
        "name": "03",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 180,
        "wires": []
    },
    {
        "id": "9f0c382eb88ecd7c",
        "type": "file",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "filename": "C:\\Users\\aiovi\\Downloads\\Новая папка (2)\\control.csv",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 1040,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "e2a2f2dab63dd049",
        "type": "inject",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "tip",
                "v": "02",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "11999999",
        "payloadType": "num",
        "x": 380,
        "y": 240,
        "wires": [
            [
                "5dd965fe633160aa",
                "511192c5688aa4dc"
            ]
        ]
    },
    {
        "id": "89fe4c2a64df7480",
        "type": "debug",
        "z": "9ee2cc1b247fc8f4",
        "name": "01",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 300,
        "wires": []
    },
    {
        "id": "2266deadb6195e05",
        "type": "csv",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "01,02",
        "skip": "2",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 690,
        "y": 180,
        "wires": [
            [
                "9f0c382eb88ecd7c",
                "0110c7af1cacd1f2"
            ]
        ]
    },
    {
        "id": "511192c5688aa4dc",
        "type": "json",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "property": "payload",
        "action": "str",
        "pretty": false,
        "x": 550,
        "y": 200,
        "wires": [
            [
                "2266deadb6195e05",
                "89fe4c2a64df7480"
            ]
        ]
    }
]

Uploading: 10.png...

Hi again.

Sorry, but I am not understanding from 2 directions in different columns.

I can sort of see that this is back to what we did last time, but I am not understanding what you want to do.

The flow you posted doesn't help (me) understand what it is you are wanting to do.

Both inject nodes send their message (different payload) and you get.... something - I'm guessing msg.tip which is important to you.

But I'm stuck.

Looking at the CSV node, you are Skipping the first two lines.
If I'm not mistaken: with what you are sending into the node, you won't see an output.

I also think that the CSV node is not going to do what you want.
Those messages are NOT in a CSV format.
They are (I think) objeccts.

I need the data from the injection node #1 (11714368) to be written to the Data1 column, and the data from the injection node #2 (11999999 ) to be written to the Data2 column. Don't pay attention to (tip ) maybe this is not the right direction in solving the problem.
11

Ok....

But as much as that makes sense, it also doesn't.

As the data from 11714368 is always put in column 1 and the other in column 2 (AND) it is the numbers, it won't show anything useful - that I can see.

All you will have is a lot of lines where there is either the 11714368 in the first column or 11999999 in the second.

(By the way, the thread seems to be indicating that you are trying to upload a picture (10.png) and it is not working.)

This MAY help you.

I'm not sure, because I am not really understanding what you are wanting to do.

But it may be a start.

[{"id":"511192c5688aa4dc","type":"json","z":"0918ee609bf69fc7","name":"","property":"payload","action":"str","pretty":false,"x":3760,"y":1810,"wires":[["2266deadb6195e05","89fe4c2a64df7480","04bf24eeafe703e9"]]},{"id":"3da047291d2d65d0","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"tip","v":"01","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"11714368","payloadType":"num","x":3590,"y":1750,"wires":[["5dd965fe633160aa","511192c5688aa4dc"]]},{"id":"e2a2f2dab63dd049","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"tip","v":"02","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"11999999","payloadType":"num","x":3590,"y":1850,"wires":[["5dd965fe633160aa","511192c5688aa4dc"]]},{"id":"2266deadb6195e05","type":"csv","z":"0918ee609bf69fc7","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\r\\n","temp":"01,02","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":3910,"y":1730,"wires":[["0110c7af1cacd1f2"]]},{"id":"89fe4c2a64df7480","type":"debug","z":"0918ee609bf69fc7","name":"01","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3910,"y":1770,"wires":[]},{"id":"04bf24eeafe703e9","type":"function","z":"0918ee609bf69fc7","name":"","func":"let a = msg.payload;\nlet b = msg.tip;\nlet blank = ' ';\n\nif (msg.payload == 11714368)\n{\n    msg.payload = a + \",\" + blank;\n} else\n{\n    msg.payload = blank + \",\" + a;\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3920,"y":1810,"wires":[["492b84570ca803d6","cac2e04a19d175d1"]]},{"id":"5dd965fe633160aa","type":"debug","z":"0918ee609bf69fc7","name":"02","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3760,"y":1730,"wires":[]},{"id":"0110c7af1cacd1f2","type":"debug","z":"0918ee609bf69fc7","name":"03","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":4070,"y":1730,"wires":[]},{"id":"492b84570ca803d6","type":"debug","z":"0918ee609bf69fc7","name":"04","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":4070,"y":1770,"wires":[]},{"id":"cac2e04a19d175d1","type":"csv","z":"0918ee609bf69fc7","name":"name","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\r\\n","temp":"01,02","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":4070,"y":1810,"wires":[["546cbe35362d422c"]]},{"id":"546cbe35362d422c","type":"debug","z":"0918ee609bf69fc7","name":"05","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":4230,"y":1810,"wires":[]}]

While I was writing and translating the message, I will send the answer to the previous one. Instead of the data of the injection node No. 2 (11999999) and No. 1, there will be other given numbers and they will change. This is an example on which you need to understand how the method of outputting data from different inputs works and they are written in their own separate column in the csv file.

But writing what you show will only log the numbers..... be it 11999999 or 11714368...

Those message (I'm guessing) have more things you want to save and so want to save that to your (CSV) file and have them in different columns to indicate from where the value came.
(Fair enough)

The bit of code I posted should go a long way to helping you.
You will just have to expand the lines to keep adding the other pieces of data to the payload.
So if you hare wanting to get 4 pieces, you are going to have to expand on the lines to define stuff like:

let c = msg.something_else
let d = msg.another_thing

and then expand the line/s:
msg.payload = blank + "," + a;
to be
msg.payload = blank + "," + a + "," + c + "," + d;
and so on.

P.S.

I am not sure that putting the different values (from the different places) in different columns will be a good idea.

Why not have the first column indicating from where the reading came and (say) the second (and onwards) then being the values?

So the output could be something like:

A, 34, 18
B, 22, 20
B, 21, 11
B, 23, 16
A, 31, 19

And so on.

Just a thought.

If the program (spreadsheet?) needs them in different columns: no problem.

OK what you are wanting to do is to take two pieces of incoming information (you have not told us where it comes from) - and then combine them together and write them to a file

Think of it like this

  1. Data1 In
  2. Data2 In
  3. Combine Data1 and Data2 with a comma in between
  4. Write the data out to your CSV file

A CSV file is just a plain text file with the values seperated by COMMAS as such Andrews program above to take the values and turn them into strings and then combine them into a single message with a Comma in the middle is perfectly valid - you can then just write to a text file and append the message at the end

The trick is that you have two different messages coming in - and as such you need to connect them together into a single message - have a look at the JOIN node for the magic sauce

Craig

[
{
"id": "9f0c382eb88ecd7c",
"type": "file",
"z": "9ee2cc1b247fc8f4",
"name": "",
"filename": "C:\Users\aiovi\Downloads\Новая папка (2)\control.csv",
"appendNewline": true,
"createDir": true,
"overwriteFile": "false",
"encoding": "utf8",
"x": 860,
"y": 540,
"wires": [

]
},
{
"id": "dcae1299d62b8e40",
"type": "inject",
"z": "9ee2cc1b247fc8f4",
"name": "11714368",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "1",
"payload": "11714368",
"payloadType": "num",
"x": 300,
"y": 420,
"wires": [
[
"d569df18db756554",
"ca182c1a81cefb4d"
]
]
},
{
"id": "3fdc99796a485bb0",
"type": "inject",
"z": "9ee2cc1b247fc8f4",
"name": "11999999",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "2",
"payload": "11999999",
"payloadType": "num",
"x": 300,
"y": 520,
"wires": [
[
"d569df18db756554",
"ca182c1a81cefb4d"
]
]
},
{
"id": "f6cf2361c0f9000b",
"type": "csv",
"z": "9ee2cc1b247fc8f4",
"name": "",
"sep": ",",
"hdrin": true,
"hdrout": "none",
"multi": "mult",
"ret": "\r\n",
"temp": "a,b",
"skip": "1",
"strings": true,
"include_empty_strings": false,
"include_null_values": false,
"x": 670,
"y": 460,
"wires": [
[
"a9004335804d7ece",
"9f0c382eb88ecd7c"
]
]
},
{
"id": "d569df18db756554",
"type": "debug",
"z": "9ee2cc1b247fc8f4",
"name": "02",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 490,
"y": 540,
"wires":
},
{
"id": "a9004335804d7ece",
"type": "debug",
"z": "9ee2cc1b247fc8f4",
"name": "03",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 460,
"wires":
},
{
"id": "ca182c1a81cefb4d",
"type": "join",
"z": "9ee2cc1b247fc8f4",
"name": "",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 510,
"y": 460,
"wires": [
[
"f6cf2361c0f9000b"
]
]
}
Uploading: 13.png...
Uploading: 14.png...

]
that's what happened - it's not what I wanted

I dunno what you are doing in terms of uploading pictures - but it is not working

Also read the sticky on how to paste code

it needs to be between `` on a seperate line

Code Here

Just reading what you have posted it looks to me like you have done the join after the CSV node - you want to do it before the CSV node - and i would not use the CSV node i would use the file write node and Andrews progra snippet that he posted

Craig

[
    {
        "id": "9f0c382eb88ecd7c",
        "type": "file",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "filename": "C:\\Users\\aiovi\\Downloads\\Новая папка (2)\\control.csv",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 900,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "dcae1299d62b8e40",
        "type": "inject",
        "z": "9ee2cc1b247fc8f4",
        "name": "11714368",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "1",
        "payload": "11714368",
        "payloadType": "num",
        "x": 300,
        "y": 420,
        "wires": [
            [
                "d569df18db756554",
                "ca182c1a81cefb4d"
            ]
        ]
    },
    {
        "id": "3fdc99796a485bb0",
        "type": "inject",
        "z": "9ee2cc1b247fc8f4",
        "name": "11999999",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "2",
        "payload": "11999999",
        "payloadType": "num",
        "x": 300,
        "y": 520,
        "wires": [
            [
                "d569df18db756554",
                "ca182c1a81cefb4d"
            ]
        ]
    },
    {
        "id": "f6cf2361c0f9000b",
        "type": "csv",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "a,b",
        "skip": "1",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 670,
        "y": 460,
        "wires": [
            [
                "a9004335804d7ece",
                "9f0c382eb88ecd7c"
            ]
        ]
    },
    {
        "id": "d569df18db756554",
        "type": "debug",
        "z": "9ee2cc1b247fc8f4",
        "name": "02",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 540,
        "wires": []
    },
    {
        "id": "a9004335804d7ece",
        "type": "debug",
        "z": "9ee2cc1b247fc8f4",
        "name": "03",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 460,
        "wires": []
    },
    {
        "id": "ca182c1a81cefb4d",
        "type": "join",
        "z": "9ee2cc1b247fc8f4",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 510,
        "y": 460,
        "wires": [
            [
                "f6cf2361c0f9000b"
            ]
        ]
    }
]

Try this

[{"id":"f71140d8e13ce0a4","type":"join","z":"295a96171a24b772","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":930,"y":340,"wires":[["86226a157c5104aa","13380805a2092327"]]},{"id":"77b47f7f5b3dfcb4","type":"inject","z":"295a96171a24b772","name":"Inject 456","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"node2","payload":"456","payloadType":"num","x":680,"y":380,"wires":[["f71140d8e13ce0a4"]]},{"id":"3a238434f591120e","type":"inject","z":"295a96171a24b772","name":"Inject 123","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"node1","payload":"123","payloadType":"num","x":680,"y":300,"wires":[["f71140d8e13ce0a4"]]},{"id":"86226a157c5104aa","type":"debug","z":"295a96171a24b772","name":"Should be joined number","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1190,"y":340,"wires":[]},{"id":"13380805a2092327","type":"function","z":"295a96171a24b772","name":"function 1","func":"msg.payload = msg.payload.node1 + \",\" + msg.payload.node2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1100,"y":420,"wires":[["543a6fc9ab80b6d0"]]},{"id":"543a6fc9ab80b6d0","type":"debug","z":"295a96171a24b772","name":"Shoudl be CSV","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1220,"y":460,"wires":[]}]

Craig

{"_msgid":"f301807b0e920c27","payload":11999999,"topic":"2"}
{"_msgid":"73699768d815a9b1","payload":11714368,"topic":"1"}
11999999,11714368

сайт не грузит картинки. В общем получаю 11714368,1199999 в одной ячейке csv, а мне надо в разных. Я не программист. Не знаю как написать код.

попробовал, в строке exell получаю

22.07.2022, 12:55:16node: Shoudl be CSV
node2 : msg.payload : array[0]
[ empty ]

I have no idea what that Russian ? is meant to mean ?

here is the complete flow to write out to a file as well

[{"id":"f71140d8e13ce0a4","type":"join","z":"295a96171a24b772","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":930,"y":340,"wires":[["86226a157c5104aa","13380805a2092327"]]},{"id":"77b47f7f5b3dfcb4","type":"inject","z":"295a96171a24b772","name":"Inject 456","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"node2","payload":"456","payloadType":"num","x":680,"y":380,"wires":[["f71140d8e13ce0a4"]]},{"id":"3a238434f591120e","type":"inject","z":"295a96171a24b772","name":"Inject 123","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"node1","payload":"123","payloadType":"num","x":680,"y":300,"wires":[["f71140d8e13ce0a4"]]},{"id":"86226a157c5104aa","type":"debug","z":"295a96171a24b772","name":"Should be joined number","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":1190,"y":340,"wires":[]},{"id":"13380805a2092327","type":"function","z":"295a96171a24b772","name":"function 1","func":"msg.payload = msg.payload.node1 + \",\" + msg.payload.node2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1100,"y":420,"wires":[["543a6fc9ab80b6d0","1015555dba5d1c64"]]},{"id":"543a6fc9ab80b6d0","type":"debug","z":"295a96171a24b772","name":"Shoudl be CSV","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1280,"y":480,"wires":[]},{"id":"1015555dba5d1c64","type":"file","z":"295a96171a24b772","name":"test write","filename":"/home/pi/test-csv","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1080,"y":480,"wires":[[]]}]

i get 123,456 in one cell
and I need 123 to be in 1 cell (A2), 456 in another (B2). And on top was if it's easy heading. Okay, this is a long story...

What are you using to read that file ? If you open it in excel (for example) you can tell it to use the values in each cell not to treat them as a string

image

image

image