Simple if loop statement

Hello,
I'm very new to Node-Red, and I'm also very knew to programming. I'm currently using the function node to write the following:

if (msg.payload.pi/11 === 0){
msg.payload = 1;
} else {
msg.payload = 2;
}
return msg;

It appears the problem lies with the /11 part and it should be something like

if (msg.payload.match ( ) === 0){
msg.payload = 1;
} else {
msg.payload = 2;
}
return msg;

My problem is that I don't know what to write inside the ( ) of the match part. Does it have to be some sort of JSON expression?
I'm getting this output (msg.payload.pi/11) from a rpi gpio in node that outputs a digital signal out of pin 11 from a raspberry pi.
Thanks for your help.

If you look at the info tab of the rpi-gpio in node you will see the following

Outputs

payload number
the payload will be a 1 or a 0.

topic string
the topic will be set to
pi/{the pin number} .

so you want to test msg.payload. If you want to check what pin returned the message, then you would be looking at msg.topic.

You should take a few minutes to read thru the section in the documentation https://nodered.org/docs/user-guide/messages
which should help you understand how to work with the contents of messages.

And welcone to the forum :fireworks:

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