Watchdog on 2.0



  • 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



  • 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?


  • Admin

    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



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



  • 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();
    


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



  • 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"



  • 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?



  • 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>



  • 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".



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

    wdt_reset();
    


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



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



  • @cimba007 --- That's great information!

    I'll try this out!

    Thanks for letting me butt into your topic...

    Rob



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



  • @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!



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



  • @cimba007

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



  • 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);
      
    }```

Log in to reply
 

Suggested Topics

51
Online

11.4k
Users

11.1k
Topics

112.6k
Posts