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.
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.
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.
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;