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. Determine if pin interupt or awakens from sleep

Determine if pin interupt or awakens from sleep

Scheduled Pinned Locked Moved General Discussion
9 Posts 4 Posters 911 Views 4 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.
  • B Offline
    B Offline
    Blom
    wrote on last edited by
    #1

    Hi

    I have an magnetic door switch sensor with a DS18b20 conected. The sensor sends updates when the magnetic switch recieved updates(pin interupt) or 30min(awakens from sleep) has passed. It sends updates from both the magnetic switch and from the temperature sensor.

    Is it possible to determine which interupt that occured? I want to send temperature updates only when it awakens from sleep and send magnetic switch updates only when pin interupt happens.

    if (pin interupt)
    {do this}
    if (awkens from sleep)
    {do that}

    mfalkviddM 1 Reply Last reply
    0
    • B Blom

      Hi

      I have an magnetic door switch sensor with a DS18b20 conected. The sensor sends updates when the magnetic switch recieved updates(pin interupt) or 30min(awakens from sleep) has passed. It sends updates from both the magnetic switch and from the temperature sensor.

      Is it possible to determine which interupt that occured? I want to send temperature updates only when it awakens from sleep and send magnetic switch updates only when pin interupt happens.

      if (pin interupt)
      {do this}
      if (awkens from sleep)
      {do that}

      mfalkviddM Online
      mfalkviddM Online
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @blom yes, just look at the return value of the sleep function. Documentation: https://www.mysensors.org/download/sensor_api_20#sleeping

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Blom
        wrote on last edited by
        #3

        Thanks! Worked like a charm!

        uint8_t interruptReturn;
        
        void loop()  {
        if (interruptReturn == 1){do this}
        if (interruptReturn == MY_WAKE_UP_BY_TIMER){do that}
        interruptReturn = sleep(INTERRUPT,CHANGE,SLEEP_TIME);
        }
        

        Next question: Is it possible to retrive remaining sleep time when waking up on interrupt so sensor could resume on time
        left when it goes to sleep again?

        YveauxY 1 Reply Last reply
        1
        • B Blom

          Thanks! Worked like a charm!

          uint8_t interruptReturn;
          
          void loop()  {
          if (interruptReturn == 1){do this}
          if (interruptReturn == MY_WAKE_UP_BY_TIMER){do that}
          interruptReturn = sleep(INTERRUPT,CHANGE,SLEEP_TIME);
          }
          

          Next question: Is it possible to retrive remaining sleep time when waking up on interrupt so sensor could resume on time
          left when it goes to sleep again?

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @blom Currently not.
          When implemented on AVR this would be a very coarse indication anyway (around 8 seconds uncertainty), but this might be acceptible for your use case.

          http://yveaux.blogspot.nl

          B 1 Reply Last reply
          1
          • YveauxY Yveaux

            @blom Currently not.
            When implemented on AVR this would be a very coarse indication anyway (around 8 seconds uncertainty), but this might be acceptible for your use case.

            B Offline
            B Offline
            Blom
            wrote on last edited by
            #5

            @yveaux

            You wrote 8sec. Does the sensor wake up every 8sec and update a sleep count variable?

            YveauxY 1 Reply Last reply
            0
            • B Blom

              @yveaux

              You wrote 8sec. Does the sensor wake up every 8sec and update a sleep count variable?

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by
              #6

              @blom more or less... On avr sleeping is using the watchdog. Longest watchdog sleep time is 8 seconds. Every 8 seconds the node wakes up, checks if there is another 8 seconds to sleep and goes to sleep again. If less than 8 seconds remains it will sleep 4 seconds, or 2 etc until the complete sleep time has elapsed.
              If it wakes from interrupt and was told to sleep for 8 seconds, it doesn't know how far it was in this 8 seconds when it woke up, hence the maximum 8 seconds uncertainty.

              http://yveaux.blogspot.nl

              B 1 Reply Last reply
              0
              • K Offline
                K Offline
                kimot
                wrote on last edited by kimot
                #7

                Create a global variable and set to 0.
                In the interrupt handler subroutine, set it to 1.
                Check its status in the main program to determine if an interruption has occurred.

                if (my_global_variable == 1)
                    my_global_variable = 0;
                    {do this}   / Action if an interrupt has occurred
                if (awkens from sleep)
                {do that}```
                1 Reply Last reply
                0
                • YveauxY Yveaux

                  @blom more or less... On avr sleeping is using the watchdog. Longest watchdog sleep time is 8 seconds. Every 8 seconds the node wakes up, checks if there is another 8 seconds to sleep and goes to sleep again. If less than 8 seconds remains it will sleep 4 seconds, or 2 etc until the complete sleep time has elapsed.
                  If it wakes from interrupt and was told to sleep for 8 seconds, it doesn't know how far it was in this 8 seconds when it woke up, hence the maximum 8 seconds uncertainty.

                  B Offline
                  B Offline
                  Blom
                  wrote on last edited by
                  #8

                  @yveaux

                  Is it possible to retrive how much time left on the watchdog sleep time when it awakens on interupt?

                  mfalkviddM 1 Reply Last reply
                  0
                  • B Blom

                    @yveaux

                    Is it possible to retrive how much time left on the watchdog sleep time when it awakens on interupt?

                    mfalkviddM Online
                    mfalkviddM Online
                    mfalkvidd
                    Mod
                    wrote on last edited by mfalkvidd
                    #9

                    @blom yes, if you hack the library or use tekka's experimental version at https://github.com/tekka007/MySensors/tree/SleepTimeLeft

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


                    44

                    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