However, the ManualAction function keeps getting called even when the pinA value remains constant. It is not being called from anywhere else in the program. Suggestions are welcome!
If you don’t have a pull-up resistor on, you can enable one inside the Impee instead. If no pull-up or pull-down resistor is present, the pin can float and trigger randomly.
Thanks for the prompt responses! The issue is still present; so as a quick and lousy fix, I have started polling the pin instead of having a callback function!
The issue is not with bouncing of the switch as far as I can see. If I keep a callback function (ManualAction), it keeps getting called mostly seconds after there is a TurnOn() and TurnOff() call in the device code; even when the switch has not been touched for a few seconds. Sometimes, ManualAction is called for no reason at all.
The TurnOn/TurnOff call can be due to motion, from an mobile app etc. Pulling down the pin is also not helping.
I am not able to figure out the connection between a write on the relay pin and call of the ManualAction function.
function rainPulse() { local state = hardware.pin2.read(); if (state == 1) { agent.send("sensorRainfallPulse", 0); } } hardware.pin2.configure(DIGITAL_IN, rainPulse);
Works without any problems for me, and all the rain gauge does, is to close a reed switch which pulls the pin down to GND.