Help how to work with `string` node

Problem:

Incoming message:
rgb,x,r,g,b

limits:
x 0 - 7
r,g,b 0 - 255

This is the base flow:

[{"id":"33f88dd62e9a1854","type":"string","z":"65c9b63cb09879a0","name":"","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"rgb,"}]},{"name":"left","params":[{"type":"num","value":"1"}]},{"name":"toInteger","params":[]}],"prop":"payload","propout":"pointer","object":"msg","objectout":"msg","x":2770,"y":160,"wires":[["9e72ba1e6e745ccf","d72327bb.0bc37"]]},{"id":"349b67738dfc8261","type":"inject","z":"65c9b63cb09879a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,4,0,0,0","payloadType":"str","x":2610,"y":160,"wires":[["33f88dd62e9a1854"]]},{"id":"9e72ba1e6e745ccf","type":"debug","z":"65c9b63cb09879a0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pointer","targetType":"msg","statusVal":"payload","statusType":"auto","x":2960,"y":160,"wires":[]},{"id":"d72327bb.0bc37","type":"string","z":"65c9b63cb09879a0","name":"0","methods":[{"name":"chompLeft","params":[{"type":"str","value":"rgb,4,"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2810,"y":220,"wires":[["ee603826871cfe95"]]},{"id":"ee603826871cfe95","type":"function","z":"65c9b63cb09879a0","name":"","func":"let pointer = msg.pointer;\n\n\nflow.set(\"test[\"+pointer+\"]\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2980,"y":220,"wires":[[]]}]

Needed:
To not need 8 nodes, I want to set an array depending on the RGB values.

Look in the function node.

let pointer = msg.pointer;
flow.set("test["+pointer+"]",msg.payload);

Doesn't work.

I need to get the second string node to remove the first 6 characters.

For reasons unknown I am at a loss what command (option?) I need to use in the string node.

I guess you're using node-red-contrib-string which I have not and I'll go out on a limb here because I'm not that experienced with NR but I think you want something like this in a function node instead of node-red-contrib-string.

Assuming that msg.payload contains "rgb,x,r,g,b" you can use ".split", because the values are comma-separated, like so:

var array = msg.payload.split(",");

// Which puts each element into the array thus:

array[0] will have the rgb value
array[1] will have the x value
array[2] will have the r value
array[3] will have the g value
array[4] will have the b value

HTH

Thanks.

I may do that.... I accept that I will then have to re-build the latter part of the message, but that isn't a deal breaker for this scenario.

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