Beginer help, parse and convert a CSV payload

Hello all,
im brand new to Node-Red and I already have a project where im talking to a external device over serial, upon connection, i get the following repeating pattern. each item, separated by comma - is a engine variable with 2 asci digits defining it....im looking for guidance on parse them out to individual integers, by removing the acsi digits after identification.
any help is appreciated

"TM3,RM0,MP91,VS0,VL121,KY0,FW4,A10,A51,AC0,AD0,AE0,AF0,AG0,X10,XA15,XB0,XC15,XD1,XE1,XF0,XG0,XH0,XX0,ZZ249,TN1~!

TM3,RM0,MP91,VS0,VL121,KY0,FW4,A10,A51,AC0,AD0,AE0,AF0,AG0,X10,XA15,XB0,XC15,XD1,XE1,XF0,XG0,XH0,XX0,ZZ249,TN2~!

TM3,RM0,MP91,VS0,VL121,KY0,FW4,A10,A51,AC0,AD0,AE0,AF0,AG0,X10,XA15,XB0,XC15,XD1,XE1,XF0,XG0,XH0,XX0,ZZ249,TN3~!"

This will need JSONata or javascript
here is a JSONata example

[{"id":"f7b2df3185229486","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TM3,RM0,MP91,VS0,VL121,KY0,FW4,A10,A51,AC0,AD0,AE0,AF0,AG0,X10,XA15,XB0,XC15,XD1,XE1,XF0,XG0,XH0,XX0,ZZ249,TN1~!","payloadType":"str","x":110,"y":3840,"wires":[["24d016049605dea6"]]},{"id":"24d016049605dea6","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$substringBefore($$.payload, \"~\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":3780,"wires":[["1091a349318519c3"]]},{"id":"1091a349318519c3","type":"csv","z":"b9860b4b9de8c8da","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":270,"y":3840,"wires":[["e672a35e933f7b16"]]},{"id":"e672a35e933f7b16","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.*.${$substring(0,2):$number( $substring(2))}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3900,"wires":[["d4e5d4d783d24c39"]]},{"id":"d4e5d4d783d24c39","type":"debug","z":"b9860b4b9de8c8da","name":"debug 315","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":3820,"wires":[]}]

output

{"TM":3,"RM":0,"MP":91,"VS":0,"VL":121,"KY":0,"FW":4,"A1":0,"A5":1,"AC":0,"AD":0,"AE":0,"AF":0,"AG":0,"X1":0,"XA":15,"XB":0,"XC":15,"XD":1,"XE":1,"XF":0,"XG":0,"XH":0,"XX":0,"ZZ":249,"TN":1}
2 Likes

E1cid, THANK so much! it works perfect! now how do i extract the individual number for 1 item?

I think you need to watch the essentials videos
You may get some benifit and learn how to find paths and target individual properties

msg.payload.TM would return 3

1 Like

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