TCP input convert

Hi All

I am trying to get my head around Nodered syntax but I am not yet understanding most of how things work. :frowning_face:

I have a light system which communicates over RS232 and I 'listen' to it over LAN via a TCP connection.

What I what to do is listen for certain messages and when they appear on the TCP, switch a hue lamp. I am OK for the hue side but what is stumping me is how to set up a flow to do it.

The TCP gives me a msg.payload of [3,97,153,16] which can also be viewed in debug as:-

msg.payload : buffer[4]

buffer[4]raw

0: 0x3

1: 0x61

2: 0x99

3: 0x2e

So the question is what do I use to check the message and act if it is that particular message. I have tried switch, change etc but nothing seems to work. Do I need to use the function command?

Any advice or help is greatly appreciated, I have tried to find examples and have read the user manual but I think I am lacking the basics.

Thanks Fulltopuk

I couldn't immediately see how to do it in a switch node, but a Function node containing this should do the job, though I have not tested it.

if (msg.payload[0] == 0x03 && msg.payload[1] == 0x61 && msg.payload[2] == 0x99 && msg.payload[3] == 0x2e ) {
  return msg
}

That should pass on the message if the test matches and do nothing if not.

Hi Colin

Many thanks for your response.

I will give it a try

Thanks

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