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. The wait function does not trigger the watchdog?

The wait function does not trigger the watchdog?

Scheduled Pinned Locked Moved General Discussion
2 Posts 2 Posters 184 Views 2 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.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by alowhum
    #1

    I wanted to do a quick test of the watchdog function on the serial gateway.

    So originally I had a variable that would increment, and then make a wait() function take increasingly long. But to my surprise, this didn't trigger the watchdog.

    #include <MySensors.h>                              // The MySensors library, which takes care of creating the wireless network.
    #include <avr/wdt.h>                                // The watchdog timer - if the device becomes unresponsive and doesn't periodically reset the timer, then it will automatically reset once the timer reaches 0.
    
    // Clock for the watchdog
    #define INTERVAL 1000                               // Every second we reset the watchdog timer. If the device freezes, the watchdog will not re reset, and the device will reboot.
    unsigned long previousMillis = 0;                   // Used to run the internal clock
    
    int boogyman = 0;
    
    void setup()
    {
      Serial.begin(115200);                             // For serial debugging over USB.
      Serial.println(F("Hello, I am a Candle receiver"));
    
      wdt_enable(WDTO_2S);                              // Starts the watchdog timer. If it is not reset once every 2 seconds, then the entire device will automatically restart.                                 
    }
    
    void presentation()
    {
    	// The receiver does not have any extra children itself.
    }
    
    void loop()
    {
      if(millis() - previousMillis >= INTERVAL){        // Main loop, runs every second.
        previousMillis = millis();                      // Store the current time as the previous measurement start time.
        Serial.print("resetting watchdog. Boogyman:"); Serial.println(boogyman);
        wdt_reset();                                    // Reset the watchdog timer
        wait(boogyman);
        boogyman = boogyman + 300;
      }
                                  
      //delay(boogyman);
    }
    

    Even if the increasing variable would theoretically call the wait function for more than 2 seconds (the watchdog timeout), it just kept on increasing.

    if I changed the wait() into a delay(), it would actually trigger the watchdog.

    So, I'm curious: how does the wait function work? The Arduino can't do multi-tasking, right? So how is it possible that the loop that runs every second is still able to keep the watchdog at bay?

    While I'm at it, I am also curious how the MySensors library integrates itself into the Arduino. It seems to manage the messages in the background perfectly well. Is that because the 'interupt' acts like a very basic multi-tasking?

    I was under the assuption that using the loop above, this loop would never run 'paralel'. Is that assumption still correct?

    mfalkviddM 1 Reply Last reply
    0
    • alowhumA alowhum

      I wanted to do a quick test of the watchdog function on the serial gateway.

      So originally I had a variable that would increment, and then make a wait() function take increasingly long. But to my surprise, this didn't trigger the watchdog.

      #include <MySensors.h>                              // The MySensors library, which takes care of creating the wireless network.
      #include <avr/wdt.h>                                // The watchdog timer - if the device becomes unresponsive and doesn't periodically reset the timer, then it will automatically reset once the timer reaches 0.
      
      // Clock for the watchdog
      #define INTERVAL 1000                               // Every second we reset the watchdog timer. If the device freezes, the watchdog will not re reset, and the device will reboot.
      unsigned long previousMillis = 0;                   // Used to run the internal clock
      
      int boogyman = 0;
      
      void setup()
      {
        Serial.begin(115200);                             // For serial debugging over USB.
        Serial.println(F("Hello, I am a Candle receiver"));
      
        wdt_enable(WDTO_2S);                              // Starts the watchdog timer. If it is not reset once every 2 seconds, then the entire device will automatically restart.                                 
      }
      
      void presentation()
      {
      	// The receiver does not have any extra children itself.
      }
      
      void loop()
      {
        if(millis() - previousMillis >= INTERVAL){        // Main loop, runs every second.
          previousMillis = millis();                      // Store the current time as the previous measurement start time.
          Serial.print("resetting watchdog. Boogyman:"); Serial.println(boogyman);
          wdt_reset();                                    // Reset the watchdog timer
          wait(boogyman);
          boogyman = boogyman + 300;
        }
                                    
        //delay(boogyman);
      }
      

      Even if the increasing variable would theoretically call the wait function for more than 2 seconds (the watchdog timeout), it just kept on increasing.

      if I changed the wait() into a delay(), it would actually trigger the watchdog.

      So, I'm curious: how does the wait function work? The Arduino can't do multi-tasking, right? So how is it possible that the loop that runs every second is still able to keep the watchdog at bay?

      While I'm at it, I am also curious how the MySensors library integrates itself into the Arduino. It seems to manage the messages in the background perfectly well. Is that because the 'interupt' acts like a very basic multi-tasking?

      I was under the assuption that using the loop above, this loop would never run 'paralel'. Is that assumption still correct?

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

      @alowhum most of these questions are way too advanced for me to answer, but I know that wait() calls _process() which processes messages and kicks the watchdog (through doYield()). See https://github.com/mysensors/MySensors/blob/development/core/MySensorsCore.cpp#L565

      while (hwMillis() - enteringMS < waitingMS) {
      _process();
      }

      By default, nrf24-based nodes do not use interrupts for message handling.

      There is nothing done in parallell.

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


      11

      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