wemosD1 Soft WDT reset.

I have this project where a pushbutton pressed for over 7 seconds would open my NC relay.
I designed this with arduino UNO and it worked well.

As I’m trying to pass the project on wemos D1 mini, I’m encountering many issues, especially a soft reset as soon as the pushbutton reaches the trigger state for relay control.

This is my code:

#include <SimpleTimer.h>
#include <SPI.h>
#include <Wire.h>
#include <ESP8266WiFi.h>


int door = D5; // the input to the relay pin
const int buttonPin = D2;  // The number of the Pushbutton pin


// Variables will change:
int buttonState = 0;  // Variable for reading the pushbutton status
long previousMillis = 0;        // will store last time LED was updated
long interval = 7000;           // interval at which to blink (milliseconds)
long currentValue;
float Dtemp;


void setup() {
 // Debug console
 Serial.begin(74880);
 

 pinMode(door, OUTPUT); // initialize pin as OUTPUT
 pinMode(buttonPin, INPUT); // initialize pin as OUTPUT
 digitalWrite(door, LOW);
 

}

void loop() {

  //REDBUTTON EMERGENCY
 previousMillis = millis();
 
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  
  //The button is pushed
  while (buttonState == HIGH) {

     Serial.println(buttonState);
     
    currentValue = millis() - previousMillis;
    
    if (currentValue > interval)  //If the button has been pressed for over 7 secs, open it
    {
    
    
     // save the last time relays has been turned on
     previousMillis = millis();   
     digitalWrite(door, HIGH);      //opendoor
     delay(4000);     //give time to get in
     digitalWrite(door, LOW);    //close it
     
     
    }
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  }



}

Try a yield() statement after your while statement.

Yes, needs a yield().
After the while statement - as in, within the while loop!

Technically speaking a delay(1); is enough to reset the WDT, but yeah, you may as well get all background processes taken care off.

yield() is equivalent to delay(0) in the ESP.
No need to have an actual delay as not always there are background processed that need attention, nor will they always take this long.

wvmarle:
yield() is equivalent to delay(0) in the ESP.

equivalent it is not ! delay(); only resets the WDT but no background processes are taken care of (if there aren't any to be taken care of then it comes down to the same thing)

Deva_Rishi:
equivalent it is not ! delay(); only resets the WDT but no background processes are taken care of (if there aren't any to be taken care of then it comes down to the same thing)

void delay(unsigned long ms) {
    if(ms) {
        os_timer_setfn(&delay_timer, (os_timer_func_t*) &delay_end, 0);
        os_timer_arm(&delay_timer, ms, ONCE);
    } else {
        esp_schedule();
    }
    esp_yield();
    if(ms) {
        os_timer_disarm(&delay_timer);
    }
}