Problem of executing the program correctely again inside an exec node

hello everyone. i have made an MQTT connection between my raspberry pi3 and ESP8266. My aim is to send the actual data generated by my soil sensor to the raspberry pi3 and if the value is below to 30 it execute the python program wich make the led lighting up for 5 seconds and when the value is above 30 (after putting the sensor in water) the led switch off. the programm work well. the problem is when i take out the sensor from water the led light up for 5 seconds and then without puting the sensor in water normaly the led should switch off and then light up for 5 seconds again isnt ? but instead of that the led keep blinking for 1 seconds of delay until i put the sensor in water again to switch it off

how can i solve this problem ?

Take a look at the w3 schools page on if statements ( also it's always useful to have debug nodes to see what is being passed along the flow)
https://www.w3schools.com/js/js_if_else.asp

But you could do the same thing with a switch node.

You also shouldn't be able to use sudo in an exec node as it's an escalation of privileges which is a big no, no.

As suggested, put a debug node showing what is coming from mqtt and another showing what is being passed on by your function node and work out why it is misbehaving.

Rather than use a python program to drive the output you could use a GPIO Out node driven by a Trigger node, to give the 5 seconds on.

1 Like

I would suggest you lose the python and experiment with node red. The 5s light up and 1s blinking, the setting of GPIO can all be achieved with the built in nodes. Give it a try, then post your flow with screen shots when you get stuck. If people can see you have tried, they will help you.

Ps. As others have said, use the debug node to understand what is happening.

1 Like

Dry the sensor after you take it out of the water :rofl: