ESP8266 Freeze



When the connection to the internet is lost in my network(happens quite often) the ESP8266 just freezes in 99% cases.
To be honest Im not quite sure if this is a blynk-specific problem or if this
problem is related to the arduino core for the esp8266.

I hope you can help!


I’ve seen a number of examples that happily check-wait-check forever until some condition is met, not good in a networked environment.

You’ll need to narrow down the culprit. Flashy LEDs, serial prints, something to indicate where you code is (or at least just was) before the ‘hang’.


Which exactly ESP8266 do you use? What is your wiring?


I am using a ESP-01.
Wiring is pretty basic. It is connected directly to a FTDI Breakout Board like this:
3.3V ->VCC
TX -> RX
RX -> TX

Today I have tested it with a really basic and lightweight sketch.
I modified the ESP8266_Standalone a little bit like this:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MYTOKEN";

void setup()


void loop()
       Serial.println("not connected");

I also tested it with other ESP-01 and ESP-12 Modules and they all freeze whenever the connection to the WIFI is lost.
But I dont think the problem lies within the BLYNK software.
I also restarted the server software on my server and the ESP-01 just reconnected and continued to stay connected. It just freezes when the connection the WIFI is lost. Maybe the problem is somewhere in the arduino environment for the esp8266?


I don’t think your wirings correct. CH_PD is not connected…


Sorry i forgot to add this. I have CH_PD directly connected to VCC and a 100nF capacitor between GND AND VCC.


3.3V to VCC
CH_PD to 3.3V
Rx to Tx
Tx to Rx

It worked to me… No more than those connections (no capacitors or others)


by debugging BlynkProtocol.h I found out, that the ESP8266 gets trapped in a while loop in the sendCmd(…) function. I will look further into it in the next days.
Specifically this loop here:

    while (wlen < len2s) {
        const size_t chunk = BlynkMin(size_t(BLYNK_SEND_CHUNK), len2s - wlen);
        wlen += conn.write(buff + wlen, chunk);


I think its because the sendCmd(…)-function does not actually end here when the connection is lost.

    if (!conn.connected()) {
        BLYNK_LOG("Cmd not sent");

Maybe there is still unread data in the buffer?
Then the connected() function will return true, although the Connection might be lost.
Maybe call conn.flush() first?
Will test tomorrow


Hi, I was also facing same problem. The following code seems to solve it.
What do you think about this code?

while (wlen < len2s) {
    const size_t chunk = BlynkMin(size_t(BLYNK_SEND_CHUNK), len2s - wlen);
    wlen += conn.write(buff + wlen, chunk);
    if (chunk > 0 && wlen <= 0) {
        state = CONNECTING;


There was an update to the library that fixed the problem.
Thanks anyway!


Hmm, I just checked the master branch. Surely the problem was fixed in the latest BlynkProtocol.h at Aug 31 2015 after v0.3.0 released.
“Do not hang on write”
It works fine!


We will release new version of the library soon… hold on :slight_smile:


I’m looking forward to it! :blush:




Thank you for new version!