WDT by software in ESP8266

Hi, I am trying to implement the WDT by software in a ESP8266 and for this I am using this code:

String bufferStringTX = "";

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.printf("Reset reason: %s\n", ESP.getResetReason().c_str());

  ESP.wdtDisable();
  ESP.wdtEnable(2000);
}

void loop() {
  Serial.println("Hit any key to avoid a watchdog timeout");
  if (Serial.available() > 0) {
    bufferStringTX = Serial.readStringUntil('\n');
    Serial.println(bufferStringTX);

    ESP.wdtFeed();
  }
  delay(100);
}

but it seems that it does not work, can someone tell me what is missing?

Might be of interest to you,

According to that posting ESP.wdtDisable(); disables the software WDT.

Yes, but in the next line I re-enable it

delay() incurs a call to yield() which resets the wdt.
at the end of loop() there is also a call to yield()
The only way to do what you want is by using a millis() limited loop surrounding this

  if (Serial.available() > 0) {
    bufferStringTX = Serial.readStringUntil('\n');
    Serial.println(bufferStringTX);

    ESP.wdtFeed();
  }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.