Critical control timing with Blynk (1mS repeatable requirement)? WiFi + Sparkfun ESP8266 Blynk Board?


I have a critical control app and need to process inputs and time stamp them at no less than 1ms accuracy. Any WiFi or Blynk overhead cannot interfere with this normally.
I would like to include Blynk to the project but my simple test and code below shows intermittent scan time delays of over a second when processing a single heartbeat (1/sec) and a single integer .25/sec with Blynk.
Is this expected behavior or do I have some other problem?

Here are the typical symptoms from the serial monitor and code.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
WidgetLED led1(V7);
float TimerStart = 0.0;
float TimerEnd = 0.0;
float TimerScanTime = 0.0;
SimpleTimer timer;  // the timer object
#define LED_PIN 5
int sensorPin = A0; 
int sensorValue = 0; 

// 1 Sec Event//

void sendFastSeconds() {
  //Noticed at FastSeconds event between 100-250ms the Scantime timer goes between 32us - 1.7seconds.
  //Heartbeat LED is not stable.  Eventually the Blynk connection is cut and tries to reset.
  sensorValue = analogRead(sensorPin);  
  Blynk.virtualWrite(V2,sensorValue);  //V2 needs to be set to push.

void send1Seconds() {
 if (led1.getValue()) {;
    // Turn the Physical LED off
    //Turn pin 5 LOW (OFF)
    digitalWrite(LED_PIN, LOW); 
  } else {
    // Turn the Blynk LED on
    // Turn the Physical LED on
    //Turn pin 5 HIGH (ON)
    digitalWrite(LED_PIN, HIGH); 
  Serial.print("ScanTime = ");
  Serial.println(" mS");

void setup()
  // Initialize hardware
  Serial.begin(9600); // Serial
  pinMode(LED_PIN, OUTPUT); // LED output

  // Initialize Blynk
  Blynk.begin(BlynkAuth, WiFiNetwork, WiFiPassword);

 // Setup functions to be called on intervals
 timer.setInterval(250L, sendFastSeconds); //250 milliseconds
 timer.setInterval(1000L, send1Seconds); //1000 milliseconds
 // timer.setInterval(5000L, send5Seconds); //5000 milliseconds

  while (Blynk.connect() == false) {
    // Wait until connected

void loop()
  TimerStart = micros(); //4uS of precision for Arduino. 
  // Execute as often as possible during the loop;;
  TimerEnd = micros();  //4uS of precision for Arduino. 
  TimerScanTime = TimerEnd - TimerStart;  //4uS of precision for Arduino. 


You might manage this with a finely honed local server but not a cloud server.


on atmel boards there is a so called “comparison register”, which does the exact same thing what you need:

  // Timer0 is already used for millis() - we'll just interrupt somewhere
  // in the middle and call the "Compare A" function below
  OCR0A = 0xAF;
  TIMSK0 |= _BV(OCIE0A);

in every millisecond runs a special function, indifferently what is doing in the code. its kind of time triggered interrupt. (works even in delays, etc).

this way one can do multitasking on arduino. actually it is very easy to setup. just take care that the runtime of the special function has to be extremely short, orhervise will crash.

for further info read this great article:

i do not know if something similar is implemented on esp8266, and how to use it. you have to find out.

or use the esp32, which is already dualcore, and on one core you can do whatever you want, and the other core handles blynk. @Lichtsignaal had some succesful experiments regarding this.

ps: i changed the topic category, because i do not consider this issue or error. it is how the blynk work. i think :slight_smile:

Is this input processing Blynk related or totally independent of Blynk?
If it’s the latter then the interrupts suggested by @wanek should work. If it’s the former then the cloud can’t handle sub ms processing.

Thanks for the feedback.
Here are some comments on the posts:

  1. The use of interrupts to help with my critical control timing. Works great for digital inputs, unfortunately my variables and time stamps are based on Analog Inputs and I have not run across any decent solution yet to interrupt these.

  2. Agree that there is nothing wrong with the Blynk server and/or most cloud servers. - timing is running per spec / as expected although Blynk users should realize and workaround these critical control timing constraints.
    My strategy on this project is to use processors with RTC’s running NTP updates to get synced clocks within ~1ms accuracy for time stamped data. Then the cloud comms can go relatively slow (~1 sec) with no worries when comparing data between processors.

  3. With the 2 cores the ESP32 seems to be a good solution for WiFi / Blynk comms, and critical control timing. Really appreciate the cool link/article from @wanek and @Lichtsignaal on assigning cores to loops. I have a few Sparkfun ESP32 Thing boards though and have not had a reliable simple WiFi connection experience in general (to say the least) when compared side by side to an Sparkfun ESP8266 Thing. Before I give up on the ESP32 though I’ll try a few boards from other suppliers that have the external antenna option.

I had Sparkfun on the phone on Friday and they suggested a solution using something like (2) separate ESP8266 boards, 1 for WiFi and 1 for critical control timing with an I2C or SPI connection between them for passing variables as needed. This should be rock solid for prototyping but I hate all the extra complexity of (2) separate boards for a mobile (battery and charging) application that will have volume.

Anyone else have issues and found solutions with WiFi connections on SparkFun ESP32’s? My problems are repeatable with (1) SW Engineer and (1) controls engineer with multiple boards at multiple locations. FYI - This also results in repeatable connection issues with Blynk and WiFi on the SparkFun ESP32. Not an issue at all with Sparkfun ESP8266 Bylnk Board side by side on the same network.


Well, the ESP32 is still under development in the software department, so I guess it could be better along the way. For now I’ve found no problems running Blynk on one core and something else on the other, but it was a simple piece of code.

What flavor of ESP32 board are you using that works?
Have you played with external antenna’s on any ESP32’s?

No idea, I just ordered the cheapest on ebay… I don’t have any external antenna’s or connectors for that. It’s this one: