Set payload message with function node

Hello,

first, sorry for my bad English and for my noob questions (I just started with node red). I have data I want to save in a .csv file. The problem ist, that the data quantity changes, so I don't need some time 3 data blocks of my input buffer and sometimes I need 10 data blocks of my input buffer.

To solve that I tried to make a small function, where I puzzle me the payload message as string. But it doesn't work.

Do anybody know how I can solve that problem?
attached the debug of the bad payload and one of a good payload.

Best regards,
Bob

Hi and welcome to the forum.

It is good to see you are trying.

I am not going to be able to answer the question as I am not good with that sort of thing, but it would seem you are going through a problem I once went through.

Line 4 and 12.
Delete them and put a JSON node after the function node.

That may fix the problem.

Hey

thank you for the answer, but it doesn't work.

Best regards,
Bob

Yeah, sorry. Open the function node, copy the code and paste it here.

It is not that easy reading it in the screen shot.

Use the </> button to enter the code.
(Or: press the key (one to the left of the1`) THREE times, press enter, paste the code, press enter and press the key another three times)

Oh and post what you want the message to look like at the end.

I have the solution:

var i = 0
var csvDaten = {} 
var csvDatenObj = ""

for (i ; i < global.get("S7Input.iAnzahlWerte"); i++) {
    csvDatenObj             = global.get("S7Input.sTitel"+i.toString());
    csvDaten[csvDatenObj]   = global.get("S7Input.rWert"+i.toString());
}

msg.payload = csvDaten;

return msg;

Thanks for the help.
Bildschirmfoto 2021-01-04 um 23.30.04

1 Like

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