String cutting, in the middle

Hello everyone.

On the Raspberry Pi I connect to the USB input a module that has 8 A/D inputs.
The module sends to the serial port every 500 MS the reading of 8 channels in analog input.
I need a function that will filter the channel I use let's say ch1
Which function will do this?
this is a sample reading "
"CH1: 2004 > 1.645V"
"CH2: 2134 > 0.640V"
"CH3: 2304 > 1.145V"
''
"CH8: 3304 > 1.005V"
the debug window show
/25/2023, 8:54:43 AMnode: b15217b9f6a8af28msg.payload : string[17]

"CH6:2010→1.620V↵"

7/25/2023, 8:54:43 AMnode: b15217b9f6a8af28msg.payload : string[17]

string[17]

CH7:2184 1.759V

7/25/2023, 8:54:43 AMnode: b15217b9f6a8af28msg.payload : string[17]

"CH8:2010→1.619V↵"

I need to send just the "CH2: 0.640V"
thanks

Your post title suggests that the readings arrive in Node-red as a single, multiple line string, but the debug outputs look like each channel is a separate message.

If it is a single multi-line string you can use a split node to split on new lines (I think that's the default for the node) which will give one message per line.

Then a switch node can select only those messages which contain "CH2"

I am receiving messages with /n for each.
the lenegh of massage is 17.
but I just need the start of the message and the end.
I get this massage "CH1: 2004 > 1.645V"
and I want to change it to be look like that "CH1: 1.645V"

Are you sure that is what you want? What do you want to do with it?
Possible a javascript object would be better, something like
{ch1: 1.645}

[{"id":"e8198f13aa18b867","type":"inject","z":"67fbfce4b5946759","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"CH1: 2004 > 1.645V","payloadType":"str","x":390,"y":80,"wires":[["09913610d450badd","9d3afdf8a06f5275"]]},{"id":"c2fa3c699afc56ea","type":"debug","z":"67fbfce4b5946759","name":"Object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"09913610d450badd","type":"function","z":"67fbfce4b5946759","name":"Output as object","func":"const myarray = msg.payload.split(\" \")\nconst channel = myarray[0].split(\":\")[0]\nconst value = parseFloat(myarray[3])\nmsg.payload = {}\nmsg.payload[channel] = value\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":80,"wires":[["c2fa3c699afc56ea"]]},{"id":"9d3afdf8a06f5275","type":"function","z":"67fbfce4b5946759","name":"Output as string","func":"const myarray = msg.payload.split(\" \")\nconst channel = myarray[0]\nconst value = myarray[3]\nmsg.payload = channel + \" \" + value\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":140,"wires":[["3ed3ae26512a3eb6"]]},{"id":"3ed3ae26512a3eb6","type":"debug","z":"67fbfce4b5946759","name":"String","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":140,"wires":[]}]

I tried at first to do it with neither function nodes nor Jsonata.
While I can convert the input string to an array with split and join nodes, I don't know enough about change node syntax (dollar signs? curly brackets?) to rejoin array elements [0] and [3] in the desired format.

Edit:

[{"id":"c3c8be7bb8325ba3","type":"inject","z":"67fbfce4b5946759","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"CH1: 2004 > 1.645V","payloadType":"str","x":290,"y":220,"wires":[["e3414a4622f30570"]]},{"id":"e3414a4622f30570","type":"split","z":"67fbfce4b5946759","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":220,"wires":[["7344af38956f2bc8"]]},{"id":"9110bfa30f919d0f","type":"join","z":"67fbfce4b5946759","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":" ","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":220,"wires":[["28e42d691b227f29"]]},{"id":"28e42d691b227f29","type":"debug","z":"67fbfce4b5946759","name":"String","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":220,"wires":[]},{"id":"7344af38956f2bc8","type":"switch","z":"67fbfce4b5946759","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":570,"y":220,"wires":[["9110bfa30f919d0f"],["9110bfa30f919d0f"]]}]

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