Why watchdog not working with MySensors?
-
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?
-
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?
-
@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
-
@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
-
Hi,
I have tried last code, and it works - the watchdog reboot MC. As expected.@mfalkvidd Why you think delay() should reset the watchdog?
-
Hi,
I have tried last code, and it works - the watchdog reboot MC. As expected.@mfalkvidd Why you think delay() should reset the watchdog?
@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().
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