The wait function does not trigger the watchdog?
-
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 adelay()
, 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?
-
@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 (throughdoYield()
). See https://github.com/mysensors/MySensors/blob/development/core/MySensorsCore.cpp#L565while (hwMillis() - enteringMS < waitingMS) {
_process();
}By default, nrf24-based nodes do not use interrupts for message handling.
There is nothing done in parallell.
Suggested Topics
-
Update RF24 library to latest version
Bug Reports • 23 Mar 2014, 23:37 • andriej 24 Mar 2014, 22:52 -
ESP-NOW
General Discussion • 22 Apr 2018, 05:58 • NeverDie 17 Feb 2025, 22:24 -
Running out of nodeId's
General Discussion • 3 Sept 2024, 07:33 • NielBierman 25 Jan 2025, 17:19 -
Email notifications received twice
General Discussion • 6 Feb 2023, 16:15 • Jodaille 3 days ago -
Combination of networks
General Discussion • 1 Feb 2025, 17:30 • Sniker 4 Feb 2025, 01:02 -
Code Garage to the rescue.
General Discussion • 11 Jan 2025, 11:25 • skywatch 23 Feb 2025, 14:57