Delay() issue in Blynk 2.0

I have to say that I was extremely sceptical about this, but decided to do some tests and I can confirm that there is a problem, which seems to be connected with the ticker.h library.

If you comment-out the #define USE_TICKER line in Settings.h of the Edgent_ESP8266 example sketch then delays work as normal.
With this line enabled, delays complete in around 20ms, regardless of their duration.

The problem is worse when using the latest ESP8266 core (v3.0.1).
I thought it might be connected with having an old version of the Ticker library installed, but when I compile the Edgent example sketch, it’s the ESP 3.0.1 library that’s providing the Ticker library:

Using library Ticker at version 1.0 in folder: C:\Users\Pete Knight\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\Ticker

To re-create the problem, add these lines to Edgent_ESP8266.ino

void loop() {
  BlynkEdgent.run();
  random_delay();
}


void random_delay()
{
  long delay_time = random(50,6000);
  long start_millis = millis();
  Serial.print("Starting ");
  Serial.print(delay_time);
  Serial.println(" milleseconds delay...");
  delay(delay_time);
  long duration = millis() - start_millis;
  Serial.print("Delay completed - time taken = ");
  Serial.print(duration);
  if (duration < delay_time)
  {
    Serial.print(" <<<<< ERROR!!");
  }
  Serial.println();
  Serial.println(); 
}

With ESP Core 3.0.1 I get results like this, with a NodeMCU…

Starting 486 milleseconds delay...
Delay completed - time taken = 20 <<<<< ERROR!!

Starting 3796 milleseconds delay...
Delay completed - time taken = 19 <<<<< ERROR!!

Starting 2080 milleseconds delay...
Delay completed - time taken = 20 <<<<< ERROR!!

Starting 2855 milleseconds delay...
Delay completed - time taken = 20 <<<<< ERROR!!

Starting 5064 milleseconds delay...
Delay completed - time taken = 20 <<<<< ERROR!!

Starting 1447 milleseconds delay...
Delay completed - time taken = 20 <<<<< ERROR!!

Starting 2018 milleseconds delay...
Delay completed - time taken = 19 <<<<< ERROR!!

If I comment-out #define USE_TICKER (still using ESP Core 3.0.1) then I get results like this…

Starting 4070 milleseconds delay...
Delay completed - time taken = 4070

Starting 5041 milleseconds delay...
Delay completed - time taken = 5041

Starting 2156 milleseconds delay...
Delay completed - time taken = 2156

Starting 5790 milleseconds delay...
Delay completed - time taken = 5790

Starting 3834 milleseconds delay...
Delay completed - time taken = 3834

If I downgrade to ESP core 2.6.3 and re-run the sketch with #define USE_TICKER enabled then I sill get some odd results, but much less so…

Starting 4979 milleseconds delay...
Delay completed - time taken = 4881 <<<<< ERROR!!

Starting 3819 milleseconds delay...
Delay completed - time taken = 3820

Starting 1635 milleseconds delay...
Delay completed - time taken = 1055 <<<<< ERROR!!

Starting 2919 milleseconds delay...
Delay completed - time taken = 2919

Starting 931 milleseconds delay...
Delay completed - time taken = 932

Starting 2296 milleseconds delay...
Delay completed - time taken = 1025 <<<<< ERROR!!

Pete.

4 Likes