Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Dectect wake up source

Dectect wake up source

Scheduled Pinned Locked Moved General Discussion
12 Posts 5 Posters 1.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GeforceGamerG GeforceGamer

    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");
      }
    
    sundberg84S Offline
    sundberg84S Offline
    sundberg84
    Hardware Contributor
    wrote on last edited by sundberg84
    #3

    @geforcegamer

    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...

    Controller: Proxmox VM - Home Assistant
    MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
    MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
    RFLink GW - Arduino Mega + RFLink Shield, 433mhz

    1 Reply Last reply
    0
    • GeforceGamerG Offline
      GeforceGamerG Offline
      GeforceGamer
      wrote on last edited by
      #4

      @nagelc Thank you.
      @sundberg84 Thanks for the great example. It really helped me a lot. I will try it out the days.

      1 Reply Last reply
      1
      • GeforceGamerG Offline
        GeforceGamerG Offline
        GeforceGamer
        wrote on last edited by
        #5

        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);
        
        YveauxY 1 Reply Last reply
        0
        • GeforceGamerG GeforceGamer

          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);
          
          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by Yveaux
          #6

          @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?

          http://yveaux.blogspot.nl

          1 Reply Last reply
          1
          • GeforceGamerG Offline
            GeforceGamerG Offline
            GeforceGamer
            wrote on last edited by
            #7

            @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.

            mfalkviddM 1 Reply Last reply
            0
            • GeforceGamerG GeforceGamer

              @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.

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #8

              @geforcegamer how is the interruptreturn variable declared? Is it scoped to survive (we can only see part of your code - maybe the value is lost at the end of loop()?

              1 Reply Last reply
              0
              • GeforceGamerG Offline
                GeforceGamerG Offline
                GeforceGamer
                wrote on last edited by GeforceGamer
                #9
                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");
                  }
                
                mfalkviddM 1 Reply Last reply
                0
                • GeforceGamerG GeforceGamer
                  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");
                    }
                  
                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by mfalkvidd
                  #10

                  @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

                  1 Reply Last reply
                  0
                  • GeforceGamerG Offline
                    GeforceGamerG Offline
                    GeforceGamer
                    wrote on last edited by
                    #11

                    @mfalkvidd
                    Thanks alot. Now the wake-up detection works perfectly

                    mfalkviddM 1 Reply Last reply
                    1
                    • GeforceGamerG GeforceGamer

                      @mfalkvidd
                      Thanks alot. Now the wake-up detection works perfectly

                      mfalkviddM Offline
                      mfalkviddM Offline
                      mfalkvidd
                      Mod
                      wrote on last edited by
                      #12

                      @geforcegamer great, thanks for reporting the result.

                      @sundberg84 next time you update your doorbell, maybe you should add the same changes.

                      1 Reply Last reply
                      1
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      19

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular