Dectect wake up source
-
Yes. sleep() gives a return code you can use. See the discussion in the API page here:
https://www.mysensors.org/download/sensor_api_20#sleeping -
Hi,
is it possible to dectect how my node wakes up? If the wake up cames form the button or by timer?
this is my sleep code:
sleep(digitalPinToInterrupt(reedswitch), CHANGE, SLEEP_TIME);I want to check something like this:
If (wakeUpByTime == 1) { Serial.println("Node wakes up by timer"); } else { Serial.println("Node wakes up by Button"); }if (interruptReturn == true) { // Woke up by changing pin if woken by interrupt code } if (interruptReturn == false) { // Woke up by timer (or it's the first run) 'if not by interrupt } interruptReturn = sleep(digitalPinToInterrupt(PIR_PIN), RISING, SLEEP_TIME);From my doorbell sensor: https://github.com/sundberg84/HomeAutomation/blob/master/Sketches MySensors Nrf24l01 radio/DoorBellDec1mhz/DoorBellDec1mhz.ino
Waiting for en external interrupt, or a timer.Im sure there are better/prettier code since thats not my stronge side. But its an example...
-
@nagelc Thank you.
@sundberg84 Thanks for the great example. It really helped me a lot. I will try it out the days. -
unfortunately it does not work with me so. I don't know whats wrong. At the first start of the node it works. But the wakeup by time shows wake up by interrupt and the wake by interrupt shows "wake up by interrupt" too.
if (interruptReturn == true) // Woke up by changing pin { wakeup= 1; Serial.println("wake up interrupt"); } if (interruptReturn == false) // Woke up by Timer { wakeup= 0; Serial.println("wake up timer"); } interruptReturn = sleep(digitalPinToInterrupt(reedswitch), CHANGE, SLEEP_TIME); -
unfortunately it does not work with me so. I don't know whats wrong. At the first start of the node it works. But the wakeup by time shows wake up by interrupt and the wake by interrupt shows "wake up by interrupt" too.
if (interruptReturn == true) // Woke up by changing pin { wakeup= 1; Serial.println("wake up interrupt"); } if (interruptReturn == false) // Woke up by Timer { wakeup= 0; Serial.println("wake up timer"); } interruptReturn = sleep(digitalPinToInterrupt(reedswitch), CHANGE, SLEEP_TIME);@geforcegamer what do you use as interrupt source?
If you use e.g. a hardware button then bouncing of the switch contacts can cause the node to wake up unexpectedly.
Also, you wake on CHANGE, meaning both a low high and high low transition will wake up your node (e.g. Button press and button release).
Can you describe your hardware setup? -
@Yveaux
I use an reedswitch as interrupt source. It is use in a bin to measure the level. I use the CHANGE command to always wake up the node. No matter if the lid is opened or closed. -
@Yveaux
I use an reedswitch as interrupt source. It is use in a bin to measure the level. I use the CHANGE command to always wake up the node. No matter if the lid is opened or closed. -
bool interruptReturn; void loop() { if (interruptReturn == true) // Woke up by changing pin { offen = 1; Serial.println("aufwachen durch Deckel"); } if (interruptReturn == false) // Woke up by Timer { offen = 0; Serial.println("aufwachen durch Timer"); } -
bool interruptReturn; void loop() { if (interruptReturn == true) // Woke up by changing pin { offen = 1; Serial.println("aufwachen durch Deckel"); } if (interruptReturn == false) // Woke up by Timer { offen = 0; Serial.println("aufwachen durch Timer"); }@geforcegamer I think I found the problem. Sleep returns an int, not a bool. Change
bool interruptReturn;to
int interruptReturn;and change
if (interruptReturn == true) // Woke up by changing pin { offen = 1; Serial.println("aufwachen durch Deckel"); } if (interruptReturn == false) // Woke up by Timer { offen = 0; Serial.println("aufwachen durch Timer"); }to
if (interruptReturn == MY_WAKE_UP_BY_TIMER) { offen = 0; Serial.println("aufwachen durch Timer"); } else { // Woke up by interrupt (or MY_SLEEP_NOT_POSSIBLE) offen = 1; Serial.println("aufwachen durch Deckel"); }Documentation: https://www.mysensors.org/download/sensor_api_20#sleeping
-
@mfalkvidd
Thanks alot. Now the wake-up detection works perfectly -
@mfalkvidd
Thanks alot. Now the wake-up detection works perfectly@geforcegamer great, thanks for reporting the result.
@sundberg84 next time you update your doorbell, maybe you should add the same changes.