watchdog 2021



  • I have been reading through the posts on watchdogging and still not sure about it, so here is a question that perhaps someone can answer.......

    Is the below code snippet the right way to use watchdog in 2.3.2? Do I need the #include <avr/wdt.h> is it already in the mysensors package?

    #include <avr/wdt.h>
    #include <MySensors.h>
    
    void setup()
    {
      // Setup locally attached sensors
      wdt_disable();
      wait(250);
      wdt_enable(WDTO_8S);
    }
    
    void presentation()
    {
      // Present locally attached sensors
    }
    
    void loop()
    {
      // Send locally attached sensor data here
      wdt_reset();
    }
    

    This is to use on a gateway but is the same method implemented on sleeping nodes?

    I will be using the minicore bootloaders which I believe are optiboot forks.

    Thanks.



  • @skywatch, I don't know if you're still looking for the answer, but in case you are, or anyone else who hits through google search, from what I understand reading this page: https://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html , you can set your watchdog timer with wdt_enable(time constant), time constant is typically in WDTO_XS format, where X is the seconds, however not all values are available for all processors, please see the link to check which values are supported.

    Next thing to do is including wdt_reset() on your loop. This will reset the timer. If the timer isn't reset by the time your counter expires, watchdog will trigger.



  • @Melih-Kulig Thanks - #i actually used the code above and it has been working OK for the last 10 days, so no bad effect. I don't know if the watchdog has had to kick in yet but it seems not.



  • Hi all,
    I'd like to add, there is no need to call wdt_reset() explicitly in loop().
    This already takes place before each loop() call in the MySensors library code behind function doYield():
    see: MySensorsCore.cpp#L619

    And hwWatchdogReset() is an HW abstraction of wdt_reset() for AVR architecture:
    /hal/architecture/AVR/MyHwAVR.h#L71

    My call stack from main() to doYield() is:

    >	MySensorsProject2.exe!doYield() Line 650	C++
     	MySensorsProject2.exe!_processInternal() Line 74	C++
     	MySensorsProject2.exe!_process() Line 91	C++
     	MySensorsProject2.exe!main(int argc, char * * argv) Line 343	C++
    


  • @virtualmkr That is useflul to know - thanks! - As it happens I think I had my first wdt 'kick' early this morning as the Gateway with the wdt on was showing as up for 3 hours instead of the 4 days I was expecting, so it restarted and all is still working 😉


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 2
  • 3
  • 2
  • 1

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts