[SOLVED] Connection lost at 50 seconds (controlling Stepper Motor)

Hi Blynkers,
I need help with blynk library.
Below is a pseudo code where a FOR structure executes a sample replay that lasts approximately 50 seconds.
I believe Blynk.virtualWite (V0, “example”) will not be properly executed.
During this time (approximately after + - 30 seconds) I receive notification in the app that the hardware has been disconnected.
How can I extend the time the hardware stays connected to the server (+ - 60sec) without changing anything in the void function FunctionExample () ??
Is it something on the side of the Blynk Server or on the side of the Blynk library?
I used this example to simplify because the actual use will be with a command library for stepper motor. That does something similar to the example function.
Thanks for all the help.

    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>

    char auth[] = "YourAuthToken";
    char ssid[] = "YourNetworkName";
    char pass[] = "YourPassword";

    void setup()
      Blynk.begin(auth, ssid, pass);
      pinMode(2, OUTPUT);

    void loop()

     void FunctionExample (){
      for (word i = 0; i > 50000; i++){ //time of exec. 50+ seconds
        digitalWrite(2, LOW);  
        delayMicroseconds(500); //500 µs = 0.0005 sec
        digitalWrite(2, HIGH);  
        delayMicroseconds(500); //500 µs = 0.0005 sec
      /*(0.0005 sec * 2) * 50000 = 50 seconds  + time functions digitalWrite and delayMicroseconds*/

      // lost connection here????   :o
      Blynk.virtualWrite(V0, "ok?"); // is send message here???

Basically you are using bad Blynk coding methods.

Calling a function from the void loop() is the same as trying to run everything in that function thousands of times a second… like your Blynk.virtualWrite() if it ever got around to running it.

Also bad is having long blocking loops like your for() that prevent Blynk functions from running… thus disconnecting.


Thanks for the answer.
As I said the code above is just an example. What actually happens is that I have a FOR () loop that takes about 50sec. to execute. When it starts I really can not perform any other activity together. Unless I know the execution time of a certain call to keep the blynk connected.
One call I use to avoid wdt.rst is the ESP.wdtFeed function which returns a feedback to whatchdog from esp8266. I need an idea to solve this. They are great loops for controlling a stepper motor. And sometimes it takes up to 50sec.
tks all

If you need to block everything you’ll be disconnected… what you can do is to check periodically if you’re connected and if not, reconnect to blynk.

Your original question was:

The simple answer is that it’s not possible. Your code will cause Blynk to disconnect.
If you’re prepared to modify the FunctionExample () by inserting a few Blynk.run commands in it then you may be able to prevent Blynk disconnections, but you’d need to experiment with this, and assess the impact of these on your function.


Hmmm, well I’m using delay in code because of the acceleration of the stepper motor I think any routine would take more time than the 20us interval. I think I will have to deal with disconnection or use dedicated hardware to control the motors. Which I think is impractical.

What 20us interval?


Time interval for switching between low high one digital pin generating the pulses required to the step motor drive

This might be of assistance… I have successfully driven stepper motors with BlynkTimer driven functions.

Thanks Gunner

But Blynk.timer works with time base in millis () and as I’m using micro step 1/32 the time drops to something close to 50 microseconds. I do not think it’s possible to use a timer with such a short interval.
But I appreciate all the help.

Not easily with Blynk… conflicting timing requirements between Stepper management and IoT communication.

I have been able to get around that with a dual MCU approach; One for the stepper and one for the Blynk interface/control…

Hi Gunner
Thanks for the topic.
I have already done another dual mcu application using these libraries in the I2C option.
But like I said, I think it’s too much to use an old arduino. My initial idea in this topic was to use ESP only. But with blynk it was kind of unfeasible.
I even got interesting results using yield () in the FOR () loop. However, the impact of this on the acceleration of the stepper motor is perceptible. RPM’s reduce considerably.
I’ll use ESP01 + Attiny13. :slight_smile: This will work good! Thank you all.

Not entirely…

You could use two ESP8266s linked via i2c/Serial/etc, one for stepper (more horsepower than AVR) and the other for Blynk.

Or even an ESP32 with it’s dual core option.

Even changing how Blynk is used/coded on the device, such has been done with Node-Red and Blynk using API

Lots of options that can allow full and fast control of complex devices with Blynk.