Hello, I have run into a lot of times that i need a delay. Yes, i know it’s better to use a timer but in some cases that just doesn’t work. I have made my own work around currently but think that it would be nice to have it within the library.
Hello, I came into trouble when the device is not connected, thus the delays became longer.
You may check if the device is connected to the server.
I have modified a bit. Please comment.
void Blynk_Delay(int milli)
{
int end_time = millis() + milli;
while (millis() < end_time)
{
if (Blynk.connected())
{
Blynk.run();
}
yield();
}
}
@Costas already gave answer on this, but let me to explain you with my way…
ESP8266 implement Watch Dog Timer that is, an auto increasing timer that IF pass a certain value -overflows- ( that means your sketch is stuck some how or there are big delay… ) then ESP8266 do restart itself like you have push hardware reset button.
yield() call internal ESP8266 functions ( like WiFi IP Stack etc ) in order to get run all pending internal system functions and at the same time take care WDT not to overflows and auto reset the ESP8266.
Is the above ok to you? If you have any other related question dont hesitate to ask me.
Thanks @mikekgr & @Costas for the good explanation, so it’s a mechism to avoid so called “hang” issue on ESP, but yet come for the following question, isn’t Blynk.run function already has this function within its code?
@Fettkeewl if your code is well designed there shouldn’t be any need for yield() but you will see it from time to time. You will also see delay(1) and it is acceptable up to perhaps 200 but ideally no higher, above this then SimpleTimer (or Photon equivalent etc) is recommended.