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. Development
  3. watchdog 2021

watchdog 2021

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 108 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.
  • skywatchS Offline
    skywatchS Offline
    skywatch
    wrote on last edited by skywatch
    #1

    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.

    1 Reply Last reply
    0
    • Melih KuligM Offline
      Melih KuligM Offline
      Melih Kulig
      wrote on last edited by
      #2

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

      skywatchS 1 Reply Last reply
      0
      • Melih KuligM Melih Kulig

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

        skywatchS Offline
        skywatchS Offline
        skywatch
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          virtualmkr
          wrote on last edited by
          #4

          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++
          
          skywatchS 1 Reply Last reply
          1
          • V virtualmkr

            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++
            
            skywatchS Offline
            skywatchS Offline
            skywatch
            wrote on last edited by skywatch
            #5

            @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 ;)

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


            31

            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