Blynk.delay() function

What is already available, the Blynk_Delay ? PLease expalin.
Thanks!

@vshymanskyy is there a place I can find documentation for the experimental functions?

Actually no problem to get documentations right from the code: https://github.com/blynkkk/blynk-library/blob/master/src/Blynk/BlynkApi.h

In this file all Blynk functions are documented using Doxygen notation. Connection-specifc functions (like begin() are not included).

@vshymanskyy, thanks

Hello,

I am using ESP8266 and this function (Blynk_Delay) works better.
I have added definitions:

#define BLYNK_PRINT Serial
#define BLYNK_EXPERIMENTAL

but it seems not to work.
So I have changed all my delay like this.

//delay(1000);
Blynk_Delay(1000);

void Blynk_Delay(int milli){
   int end_time = millis() + milli;
   while(millis() < end_time){
       Blynk.run();
       yield();
   }
}

Got any idea how to troubleshoot?

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();
  }
}
1 Like

@mikekgr Just wondering, what is the function of yield() do? I can’t find it in Blynk documentation. Thanks

yield() is an ESP function to stop the software WDT kicking in.

1 Like

@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.

Best Regards,
Mike Kranidis

5 Likes

DOG not DOC. Feed the dog.

1 Like

Yes, I corrected my typo. Thanks Costas. ( you know all of us, the non native English speakers… )

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?

There is software hanging and hardware hanging. The WDT is more hardware related while Blynk is more of the software side.

In b4 getting called out…

Necromancer here!

Just a quick question Costas, I see plenty of code examples with the loop constisting of
Blynk.run();
Timer.run();

but rarely a yield(), is this mostly done in the timer or blynk.run? Or just not needed somehow?

@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.

What count’s as “well designed”, is it the amount of time it takes to perform a loop? Keeping it as low as possible?
If there is no need to call yield() with a well designed code, just out of curiosity, when does an “auto-yield” occur?

The ESP handles any pending events each time the loop() function completes, OR when delay() is called.

I wonder if we can put equal sign between “well designed” and “fluent program flow” :wink:

2 Likes

I read a detailed article on GitHub some months ago about the ESP’s WDT but I’m struggling to find it.

Having searched I believe the contributor was possibly @pasko-zh and he / she has an open pull request for updates to the ESP8266 Arduino readme.md including this graphical presentation


The full details of the pull request are at https://github.com/esp8266/Arduino/pull/2533/files
Useful WDT information, although not that easy to follow in a pull request.

1 Like

change
int end_time = millis() + milli;
to
long end_time = millis() + milli;

1 Like

Hi , I am using a ESP 32 and a ultrasonic sensor to activate a doll if some one comes near by. I also would like to activate from Iphone and Google Home. The doll activation needs a delay function between the activation and sensing due to mechanical stability. Blynk gets disconnected with the delay. I understand why. I am using python for the whole project. Do we have a code to incorporate delay function while stay connected with the Blynk. Once sensed or activated through blynk, I need about 2 mins of delay before the next activation. That is the time doll takes to come back to rest. If there is no sensing , the void loop can be run without delay. The issue comes when there is a sensing and the doll need to be activated.