Switch node with HEX input

Hi

I am new to NodeRED and I am trying to use the switcher node to filter a HEX code coming from a TCP in node

I receive this HEX 0x1c,0x64,0xa,0x0,0x0,0x0,0xff,0x77 I'd like to split the code up in to 8
separate numbers, so I can react on each of the numbers.

so the switch should work like this.

Hi - the switch node is generally for comparisons, not in the way you are thinking.
You have asked it to match the input to a long string - "if no.0 ...." which of course it won't match.
Realistically for multiple matches in a single go you are probably better off using a function node a small piece of javascript.

Thanks

Can you help me setting up the function node,

How about using the switch like this, but i cant get it working

I am not sure why you are using the Switcher node, You can use the function node to access each of the elements in your buffer array. For example, replace the Switcher node with a function node and add the following:

if (msg.payload[0] == 0x1c && msg.payload[1] == 0x64)
return msg;

This will filter the messages if I understood what you're trying to do.

1 Like

Thanks

if i then make two outputs, so i one condition is met go to output 1 and if another is met output 2

if (msg.payload[0] == 0x1c && msg.payload[1] == 0x64)
return msg; //Output 1
if (msg.payload[0] == 0x1c && msg.payload[1] == 0x63)
return msg; //Output 2

You can do it with switches if prepared to calculate the numbers in decimal

[{"id":"cc1275cb.344bd8","type":"inject","z":"55400b8b.4f5704","name":"","topic":"","payload":"[28,100,65,66,67]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["9bbc9359.2faf8"]]},{"id":"9bbc9359.2faf8","type":"switch","z":"55400b8b.4f5704","name":"","property":"payload[0]","propertyType":"msg","rules":[{"t":"eq","v":"28","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":140,"wires":[["f23fdff5.4782"]]},{"id":"177cf4e.6e5b80b","type":"debug","z":"55400b8b.4f5704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":140,"wires":[]},{"id":"f23fdff5.4782","type":"switch","z":"55400b8b.4f5704","name":"","property":"payload[1]","propertyType":"msg","rules":[{"t":"eq","v":"100","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":140,"wires":[["177cf4e.6e5b80b"]]},{"id":"3a51dfd5.10543","type":"inject","z":"55400b8b.4f5704","name":"","topic":"","payload":"[28,99,65,66,67]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["9bbc9359.2faf8"]]}]

For multiple outputs from a function node see the docs
https://nodered.org/docs/user-guide/writing-functions#multiple-outputs
and increase the number of outputs to 2 (or whatever you need)

Great thanks