Data extracting question 2

Hello,

I am totally new to Node-RED.

I have a frame sent over UDP with the following format:

#+21/07/2023+01:03:13+25.19+27.31+25.90+0+0+20+0+0+0+0+11011111+%

I have start “#” and end “%”, as well as the separator “+”. I use it this way because in a VisualBasic APP of mine I use this beginning and end of the frame.

In Node-RED I manage to separate the data. What I don’t know is how to assign them to variables.

In the image there are a lot of tests, but you can see that the one used now is Split2.

How can I define variables, e.g. “Time” to the Array of the image (2: “23:39:51”) and so on for each of the fields?

Thanks

jmarenav

Gracias

[{"id":"c4b6634048abce69","type":"change","z":"531844fd6e8e6b59","name":"","rules":[{"t":"set","p":"names","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"names.time","pt":"msg","to":"payload.2","tot":"msg","dc":true},{"t":"set","p":"names.date","pt":"msg","to":"payload.1","tot":"msg","dc":true},{"t":"move","p":"names","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1088,"y":96,"wires":[["a0bfe6a1bb6c2054"]]},{"id":"541787047559c4e5","type":"inject","z":"531844fd6e8e6b59","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"#\",\"04/08/2023\",\"23:39:51\",\"25.87\"]","payloadType":"json","x":906,"y":96,"wires":[["c4b6634048abce69"]]},{"id":"a0bfe6a1bb6c2054","type":"debug","z":"531844fd6e8e6b59","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1284,"y":96,"wires":[]}]

or you could just plug this in a function node and do something like


var payload ={
  "var1": msg.payload[0],
  "var2": msg.payload[1]
  ....
}
return msg;

Thank you very much.
Something so simple and I didn’t see it. It has helped me a lot.

Thank you

1 Like