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. Why watchdog not working with MySensors?

Why watchdog not working with MySensors?

Scheduled Pinned Locked Moved Development
6 Posts 2 Posters 1.3k Views 2 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.
  • D Offline
    D Offline
    Dmytro Zadvornov
    wrote on last edited by
    #1

    Hello,

    I faced with the same issue like https://forum.mysensors.org/topic/9946/watchdog-not-watchdogging/1
    MySensor ver 2.3.1
    Optiboot ver 8.0
    atmega328, 8MHz
    I have tested two codes on the one board and the result is bellow.
    This test code works well. Watchdog is working and Atmega is rebooting.

    #include <Arduino.h>
    #include <avr/wdt.h>
      
    #define STATUS_LED_PIN        A2
    
    void setup() {
      wdt_disable();
      Serial.begin(9600);
      Serial.println("Setup..");
      pinMode(STATUS_LED_PIN, OUTPUT);
      digitalWrite(STATUS_LED_PIN, 0);
      
      Serial.println("Wait 5 sec..");
      delay(5000);
      wdt_enable (WDTO_8S);
      Serial.println("Watchdog enabled.");
    }
    
    int timer = 0;
    
    void loop(){
      if(!(millis()%1000)){
        timer++;
        Serial.println(timer);
        digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
      }
      //wdt_reset();
    }
    

    But this code is not working. Watchdog is not working.

    #include <Arduino.h>
    #include <avr/wdt.h>
      
    // RFM95
      #define MY_RADIO_RFM95
      //#define MY_DEBUG_VERBOSE_RFM95
      #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
      #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
    
      #define MY_NODE_ID 10
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
    
    #include <MySensors.h>
    
    #define STATUS_LED_PIN        A2
    
    void setup() {
      wdt_disable();
      Serial.begin(9600);
      Serial.println("Setup..");
      pinMode(STATUS_LED_PIN, OUTPUT);
      digitalWrite(STATUS_LED_PIN, 0);
      
      Serial.println("Wait 5 sec..");
      delay(5000);
      wdt_enable (WDTO_8S);
      Serial.println("Watchdog enabled.");
    }
    
    int timer = 0;
    
    void loop(){
      if(!(millis()%1000)){
        timer++;
        Serial.println(timer);
        digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
      }
      //wdt_reset();
    }
    

    What I am doing wrong?

    mfalkviddM 1 Reply Last reply
    0
    • D Dmytro Zadvornov

      Hello,

      I faced with the same issue like https://forum.mysensors.org/topic/9946/watchdog-not-watchdogging/1
      MySensor ver 2.3.1
      Optiboot ver 8.0
      atmega328, 8MHz
      I have tested two codes on the one board and the result is bellow.
      This test code works well. Watchdog is working and Atmega is rebooting.

      #include <Arduino.h>
      #include <avr/wdt.h>
        
      #define STATUS_LED_PIN        A2
      
      void setup() {
        wdt_disable();
        Serial.begin(9600);
        Serial.println("Setup..");
        pinMode(STATUS_LED_PIN, OUTPUT);
        digitalWrite(STATUS_LED_PIN, 0);
        
        Serial.println("Wait 5 sec..");
        delay(5000);
        wdt_enable (WDTO_8S);
        Serial.println("Watchdog enabled.");
      }
      
      int timer = 0;
      
      void loop(){
        if(!(millis()%1000)){
          timer++;
          Serial.println(timer);
          digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
        }
        //wdt_reset();
      }
      

      But this code is not working. Watchdog is not working.

      #include <Arduino.h>
      #include <avr/wdt.h>
        
      // RFM95
        #define MY_RADIO_RFM95
        //#define MY_DEBUG_VERBOSE_RFM95
        #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
        #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
      
        #define MY_NODE_ID 10
        #define MY_PARENT_NODE_ID 0
        #define MY_PARENT_NODE_IS_STATIC
      
      #include <MySensors.h>
      
      #define STATUS_LED_PIN        A2
      
      void setup() {
        wdt_disable();
        Serial.begin(9600);
        Serial.println("Setup..");
        pinMode(STATUS_LED_PIN, OUTPUT);
        digitalWrite(STATUS_LED_PIN, 0);
        
        Serial.println("Wait 5 sec..");
        delay(5000);
        wdt_enable (WDTO_8S);
        Serial.println("Watchdog enabled.");
      }
      
      int timer = 0;
      
      void loop(){
        if(!(millis()%1000)){
          timer++;
          Serial.println(timer);
          digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
        }
        //wdt_reset();
      }
      

      What I am doing wrong?

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @dmytro-zadvornov MySensors will automatically reset the watchdog every time loop is exited.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dmytro Zadvornov
        wrote on last edited by Dmytro Zadvornov
        #3

        @mfalkvidd Thx for you answer.
        If I understand you right MySensor has implicit call wdt_reset()?
        And in this case this new code will reboot.

        #include <Arduino.h>
        #include <avr/wdt.h>
          
        // RFM95
          #define MY_RADIO_RFM95
          //#define MY_DEBUG_VERBOSE_RFM95
          #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
          #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
        
          #define MY_NODE_ID 10
          #define MY_PARENT_NODE_ID 0
          #define MY_PARENT_NODE_IS_STATIC
        
        #include <MySensors.h>
        
        #define STATUS_LED_PIN        A2
        
        void setup() {
          wdt_disable();
          Serial.begin(9600);
          Serial.println("Setup..");
          pinMode(STATUS_LED_PIN, OUTPUT);
          digitalWrite(STATUS_LED_PIN, 0);
          
          Serial.println("Wait 5 sec..");
          delay(5000);
          wdt_enable (WDTO_8S);
          Serial.println("Watchdog enabled.");
        }
        
        int timer = 0;
        
        void loop(){
          if(!(millis()%1000)){
            timer++;
            Serial.println(timer);
            digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
          }
          delay(20000);
          //wdt_reset();
        }
        

        I will try it later

        mfalkviddM 1 Reply Last reply
        0
        • D Dmytro Zadvornov

          @mfalkvidd Thx for you answer.
          If I understand you right MySensor has implicit call wdt_reset()?
          And in this case this new code will reboot.

          #include <Arduino.h>
          #include <avr/wdt.h>
            
          // RFM95
            #define MY_RADIO_RFM95
            //#define MY_DEBUG_VERBOSE_RFM95
            #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
            #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
          
            #define MY_NODE_ID 10
            #define MY_PARENT_NODE_ID 0
            #define MY_PARENT_NODE_IS_STATIC
          
          #include <MySensors.h>
          
          #define STATUS_LED_PIN        A2
          
          void setup() {
            wdt_disable();
            Serial.begin(9600);
            Serial.println("Setup..");
            pinMode(STATUS_LED_PIN, OUTPUT);
            digitalWrite(STATUS_LED_PIN, 0);
            
            Serial.println("Wait 5 sec..");
            delay(5000);
            wdt_enable (WDTO_8S);
            Serial.println("Watchdog enabled.");
          }
          
          int timer = 0;
          
          void loop(){
            if(!(millis()%1000)){
              timer++;
              Serial.println(timer);
              digitalWrite(STATUS_LED_PIN, digitalRead(STATUS_LED_PIN)==1?0:1); delay(1);
            }
            delay(20000);
            //wdt_reset();
          }
          

          I will try it later

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          @dmytro-zadvornov delay will also reset the watchdog

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dmytro Zadvornov
            wrote on last edited by
            #5

            Hi,
            I have tried last code, and it works - the watchdog reboot MC. As expected.

            @mfalkvidd Why you think delay() should reset the watchdog?

            mfalkviddM 1 Reply Last reply
            0
            • D Dmytro Zadvornov

              Hi,
              I have tried last code, and it works - the watchdog reboot MC. As expected.

              @mfalkvidd Why you think delay() should reset the watchdog?

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #6

              @dmytro-zadvornov thanks for reporting back.

              Sorry for my mistake. I thought most platforms called yield() inside delay(), and yield() usually resets the watchdog. Example https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/wiring.c#L106
              But since your test shows that the watchdog is tripped, the watchdog is not reset inside delay().

              https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/Arduino.h#L38 shows that avr does not reset watchdog in yield().

              1 Reply Last reply
              0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              20

              Online

              12.1k

              Users

              11.2k

              Topics

              113.4k

              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