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. Watchdog on 2.0

Watchdog on 2.0

Scheduled Pinned Locked Moved General Discussion
2.0mqttwatchdog
19 Posts 6 Posters 9.7k Views 6 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.
  • CrankyCoderC Online
    CrankyCoderC Online
    CrankyCoder
    wrote on last edited by
    #1

    Does anyone have any info/examples on watch dog in 2.0? What are the requirements? I have a mqttclientgateway running 2.0. Periodically it stops working. I can still ping it, but the radio send/receive seems to have stopped. All is fine if I power cycle it.

    Now, I am not 100% certain it's related to the mysensors firmware. I realized that the last time i show activity from anything on the mysensors side was around the same time that I had to reset the mqtt server. Does 2.0 have code to reconnect? Any software watch dog for that?

    Thanks

    Home Automation Tinkerer
    www.CrankyCoder.net

    Controller: HomeAssistant in Kubernetes
    Gateway: MQTTClientGateway
    MySensors: 2.3

    1 Reply Last reply
    0
    • CrankyCoderC Online
      CrankyCoderC Online
      CrankyCoder
      wrote on last edited by
      #2

      I plan on rebooting the mqtt again today and see if that is the case. Anyone have any reference material on internal watchdog for the gateway module?

      Home Automation Tinkerer
      www.CrankyCoder.net

      Controller: HomeAssistant in Kubernetes
      Gateway: MQTTClientGateway
      MySensors: 2.3

      1 Reply Last reply
      0
      • hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by
        #3

        It should try to reconnect (at least if the MQTT client used is working as expected).

        https://github.com/mysensors/MySensors/blob/development/core/MyGatewayTransportMQTTClient.cpp#L141

        1 Reply Last reply
        0
        • CrankyCoderC Online
          CrankyCoderC Online
          CrankyCoder
          wrote on last edited by
          #4

          hmmmm. Are there any retry max values or will it try forever? any watchdog stuff I can throw in just in case?

          Home Automation Tinkerer
          www.CrankyCoder.net

          Controller: HomeAssistant in Kubernetes
          Gateway: MQTTClientGateway
          MySensors: 2.3

          1 Reply Last reply
          0
          • cimba007C Offline
            cimba007C Offline
            cimba007
            wrote on last edited by cimba007
            #5

            Are you using the ESP8266 as your mqtt-client? If so this might help you.

            https://github.com/esp8266/Arduino/issues/1532

            If you are using an Atmega328 this is the code I am currently using.

            #include <avr/wdt.h>
            
            void before()
            {
              wdt_disable(); // Might be redundant as the bootloader should have done this already
              wdt_enable(WDTO_8S);
            ....
            
            void loop()
            {
              wdt_reset();
            
            CrankyCoderC 1 Reply Last reply
            0
            • cimba007C cimba007

              Are you using the ESP8266 as your mqtt-client? If so this might help you.

              https://github.com/esp8266/Arduino/issues/1532

              If you are using an Atmega328 this is the code I am currently using.

              #include <avr/wdt.h>
              
              void before()
              {
                wdt_disable(); // Might be redundant as the bootloader should have done this already
                wdt_enable(WDTO_8S);
              ....
              
              void loop()
              {
                wdt_reset();
              
              CrankyCoderC Online
              CrankyCoderC Online
              CrankyCoder
              wrote on last edited by
              #6

              @cimba007 pro mini with a 5100. pings seem to stay active, not sure it that's the 5100 taking over that. But radio send/receive seems to go away.

              Home Automation Tinkerer
              www.CrankyCoder.net

              Controller: HomeAssistant in Kubernetes
              Gateway: MQTTClientGateway
              MySensors: 2.3

              1 Reply Last reply
              0
              • cimba007C Offline
                cimba007C Offline
                cimba007
                wrote on last edited by
                #7

                Have you tried to enable #define MY_DEBUG and have a Serial terminal opened all the time?

                Maybe you can get some clues on where the sketch "hangs up"

                1 Reply Last reply
                1
                • CrankyCoderC Online
                  CrankyCoderC Online
                  CrankyCoder
                  wrote on last edited by
                  #8

                  I don't have a serial connection on it at the moment. But oddly enough, the power went out at home long enough to take down my mqtt and the gateway. The mqtt came back up on it's own. But my gateway has not recovered. Ill run a cable over to it tonight and try to monitor it on serial.

                  The gateway I am assuming will loop forever trying to connect to mqtt right?

                  Home Automation Tinkerer
                  www.CrankyCoder.net

                  Controller: HomeAssistant in Kubernetes
                  Gateway: MQTTClientGateway
                  MySensors: 2.3

                  1 Reply Last reply
                  0
                  • treborjm87T Offline
                    treborjm87T Offline
                    treborjm87
                    wrote on last edited by
                    #9

                    Not that I know anything... About anything... Yeah, I'm new here...

                    What about using a hardware WDT? For instance the freetronics one?

                    http://www.freetronics.com.au/collections/modules/products/watchdog-timer-module

                    I have sensors up in my attic and have been thinking about using a hardware WDT.

                    During the summer, it gets really hot up my attic, and I hate going up there.

                    Rob

                    </end first post>

                    cimba007C CrankyCoderC 3 Replies Last reply
                    0
                    • treborjm87T treborjm87

                      Not that I know anything... About anything... Yeah, I'm new here...

                      What about using a hardware WDT? For instance the freetronics one?

                      http://www.freetronics.com.au/collections/modules/products/watchdog-timer-module

                      I have sensors up in my attic and have been thinking about using a hardware WDT.

                      During the summer, it gets really hot up my attic, and I hate going up there.

                      Rob

                      </end first post>

                      cimba007C Offline
                      cimba007C Offline
                      cimba007
                      wrote on last edited by cimba007
                      #10
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      IP: 192.168.178.87<\r><\n>
                      0;255;3;0;9;Attempting MQTT connection...<\n>
                      
                      

                      So yeah .. the mqttclient will try to reconnect until .. like ever I just tested it for like 30 seconds but I don't think there will be a "timeout".

                      CrankyCoderC 1 Reply Last reply
                      0
                      • treborjm87T treborjm87

                        Not that I know anything... About anything... Yeah, I'm new here...

                        What about using a hardware WDT? For instance the freetronics one?

                        http://www.freetronics.com.au/collections/modules/products/watchdog-timer-module

                        I have sensors up in my attic and have been thinking about using a hardware WDT.

                        During the summer, it gets really hot up my attic, and I hate going up there.

                        Rob

                        </end first post>

                        cimba007C Offline
                        cimba007C Offline
                        cimba007
                        wrote on last edited by
                        #11

                        @treborjm87 The Atmega328P has already an buildin hardware watchdog. It will reset your node if you don't feed it via

                        wdt_reset();
                        
                        treborjm87T 1 Reply Last reply
                        0
                        • cimba007C cimba007

                          @treborjm87 The Atmega328P has already an buildin hardware watchdog. It will reset your node if you don't feed it via

                          wdt_reset();
                          
                          treborjm87T Offline
                          treborjm87T Offline
                          treborjm87
                          wrote on last edited by
                          #12

                          @cimba007 -- I really didn't know that the Arduino already had a WDT... But, what if it is the Atmega that is locked up? I suspect that my clone Arduinos are susceptible to heat and are unable to reset themselves... (Yeah, a bigger issue that what this topic is about). Thanks for the information!

                          Rob

                          1 Reply Last reply
                          0
                          • cimba007C Offline
                            cimba007C Offline
                            cimba007
                            wrote on last edited by
                            #13

                            @treborjm87 The fault is not with your cloes but .. well .. how should I put it .. the Watchdog on almost all "Arduino pro mini" clones from china is broken. Normally the watchdog gets disabled during bootloader (just after the reset) but on these clones the default bootloader dosn't do this .. leading to an infinite boot loop.

                            This issue can be solved by connecting an Arduino set up as ISP-Programmer and burning the current Arduino bootloader.

                            As the pro minis come unsoldered I made myself a little adapter consisting only of male pin headers where I can put the pro mini in. The pins are not connected very good but pressing the pro mini in place I can very easylie reflash the bootloader before I put them into my projects.

                            treborjm87T 1 Reply Last reply
                            0
                            • cimba007C cimba007

                              @treborjm87 The fault is not with your cloes but .. well .. how should I put it .. the Watchdog on almost all "Arduino pro mini" clones from china is broken. Normally the watchdog gets disabled during bootloader (just after the reset) but on these clones the default bootloader dosn't do this .. leading to an infinite boot loop.

                              This issue can be solved by connecting an Arduino set up as ISP-Programmer and burning the current Arduino bootloader.

                              As the pro minis come unsoldered I made myself a little adapter consisting only of male pin headers where I can put the pro mini in. The pins are not connected very good but pressing the pro mini in place I can very easylie reflash the bootloader before I put them into my projects.

                              treborjm87T Offline
                              treborjm87T Offline
                              treborjm87
                              wrote on last edited by
                              #14

                              @cimba007 --- That's great information!

                              I'll try this out!

                              Thanks for letting me butt into your topic...

                              Rob

                              1 Reply Last reply
                              0
                              • treborjm87T treborjm87

                                Not that I know anything... About anything... Yeah, I'm new here...

                                What about using a hardware WDT? For instance the freetronics one?

                                http://www.freetronics.com.au/collections/modules/products/watchdog-timer-module

                                I have sensors up in my attic and have been thinking about using a hardware WDT.

                                During the summer, it gets really hot up my attic, and I hate going up there.

                                Rob

                                </end first post>

                                CrankyCoderC Online
                                CrankyCoderC Online
                                CrankyCoder
                                wrote on last edited by
                                #15

                                @treborjm87 I have Jon Oxers page bookmarked. Looking into this is a possibility myself.

                                Home Automation Tinkerer
                                www.CrankyCoder.net

                                Controller: HomeAssistant in Kubernetes
                                Gateway: MQTTClientGateway
                                MySensors: 2.3

                                1 Reply Last reply
                                0
                                • cimba007C cimba007
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  IP: 192.168.178.87<\r><\n>
                                  0;255;3;0;9;Attempting MQTT connection...<\n>
                                  
                                  

                                  So yeah .. the mqttclient will try to reconnect until .. like ever I just tested it for like 30 seconds but I don't think there will be a "timeout".

                                  CrankyCoderC Online
                                  CrankyCoderC Online
                                  CrankyCoder
                                  wrote on last edited by
                                  #16

                                  @cimba007 That's kind of what I figured. When I got home I tested trying to send something from one of my nodes without power cycling my gateway. No luck. I setup a mock sensor and had it blasting out messages. Nothing. Power cycled the gateway, everything started responding. I disconnected power from gateway and turned off the mqtt server. Booted both back up and they recovered. So my next step is going to have to be to hook a serial connection up and hope I can catch it the next time it goes bad. Cause it looks like either the radio or the arduino is locking up. I may just flash the working watchdog bootloader to it and enabling the watchdog. I saw in the core that there is already the watchdog reset. So do I just need to enable it with something like

                                  wdt_enable(WDTO_8S); 
                                  

                                  in the setup?

                                  Thanks!

                                  Home Automation Tinkerer
                                  www.CrankyCoder.net

                                  Controller: HomeAssistant in Kubernetes
                                  Gateway: MQTTClientGateway
                                  MySensors: 2.3

                                  1 Reply Last reply
                                  0
                                  • cimba007C Offline
                                    cimba007C Offline
                                    cimba007
                                    wrote on last edited by
                                    #17

                                    I checked the sourcecode and it seems that only parts of the watchdog are implemented. I enabled the watchdog the following way:

                                    At the beginning of the sketch #include <avr/wdt.h>

                                    Later at

                                    void before()
                                    {
                                      wdt_disable(); // maybe redundant
                                      wdt_enable(WDTO_8S);
                                    

                                    And finally at the loop

                                    void loop()
                                    {
                                      wdt_reset();
                                    

                                    Advanced reading:

                                    The sleep() method on mysensors does something special with the watchdog. It enabled the interrupt flag and defines an empty

                                    // Watchdog Timer interrupt service routine. This routine is required
                                    // to allow automatic WDIF and WDIE bit clearance in hardware.
                                    ISR (WDT_vect)
                                    {
                                    
                                    }
                                    

                                    When the Atmega328p engages sleep mode the watchdog timeout is overwritten with your designated sleep period. The watchdog then times out and calles the service routine (ISR). After the ISR-routine finished the interrupt flag is disabled. This leeds to an reset at the next imeout of the watchdog.

                                    Normal reading again ;-)
                                    Luckyly the sleep() routine is smart enough to save and restore your custom watchdog settings. When the watchdog times out (as the interrupt flag is not set) the Atmega328p resets. In the bootloader the watchdog is disabled until you enable it in the before()-Method again.

                                    R 1 Reply Last reply
                                    0
                                    • cimba007C cimba007

                                      I checked the sourcecode and it seems that only parts of the watchdog are implemented. I enabled the watchdog the following way:

                                      At the beginning of the sketch #include <avr/wdt.h>

                                      Later at

                                      void before()
                                      {
                                        wdt_disable(); // maybe redundant
                                        wdt_enable(WDTO_8S);
                                      

                                      And finally at the loop

                                      void loop()
                                      {
                                        wdt_reset();
                                      

                                      Advanced reading:

                                      The sleep() method on mysensors does something special with the watchdog. It enabled the interrupt flag and defines an empty

                                      // Watchdog Timer interrupt service routine. This routine is required
                                      // to allow automatic WDIF and WDIE bit clearance in hardware.
                                      ISR (WDT_vect)
                                      {
                                      
                                      }
                                      

                                      When the Atmega328p engages sleep mode the watchdog timeout is overwritten with your designated sleep period. The watchdog then times out and calles the service routine (ISR). After the ISR-routine finished the interrupt flag is disabled. This leeds to an reset at the next imeout of the watchdog.

                                      Normal reading again ;-)
                                      Luckyly the sleep() routine is smart enough to save and restore your custom watchdog settings. When the watchdog times out (as the interrupt flag is not set) the Atmega328p resets. In the bootloader the watchdog is disabled until you enable it in the before()-Method again.

                                      R Offline
                                      R Offline
                                      Reza
                                      wrote on last edited by
                                      #18

                                      @cimba007

                                      hi
                                      where i can download this library : "#include <avr/wdt.h>" ?

                                      1 Reply Last reply
                                      0
                                      • Artemiy117A Offline
                                        Artemiy117A Offline
                                        Artemiy117
                                        wrote on last edited by
                                        #19

                                        wdt.h is included on Arduino IDE.
                                        This example show how it's work:

                                        #include <avr/wdt.h>
                                        
                                        int counter=0;
                                        void setup(){
                                           wdt_disable();
                                           
                                            Serial.begin(9600);
                                          Serial.println("Starting...");
                                          delay(1000);
                                         
                                          wdt_enable(WDTO_8S);
                                          
                                        }
                                        
                                        void loop(){
                                          wdt_reset();
                                          
                                           Serial.println(counter);
                                           counter++;
                                           
                                           if(counter==5){
                                              while(true){}
                                           }
                                           delay(500);
                                          
                                        }```
                                        1 Reply Last reply
                                        1
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        22

                                        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