BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP8266 Freeze


#1

Hey,

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!
Thanks.


#2

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


#3

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


#4

I am using a ESP-01.
Wiring is pretty basic. It is connected directly to a FTDI Breakout Board like this:
3.3V ->VCC
GND ->GND
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()
{
  Serial.begin(9600);
  Blynk.begin(auth, "MYWIFISSID", "MYWIFIPASSWORD","MYSERVER");

}

void loop()
{
  Blynk.run();
  if(Blynk.connected())
    {
       Serial.println("connected");
    }
  else
    {
       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?


#5

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


#6

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


#7

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

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


#8

Hey,
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);
#ifdef BLYNK_SEND_THROTTLE
        delay(BLYNK_SEND_THROTTLE);
#endif
    }

#9

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

    if (!conn.connected()) {
#ifdef BLYNK_DEBUG
        BLYNK_LOG("Cmd not sent");
#endif
        return;
    }

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


#10

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) {
        conn.disconnect();
        state = CONNECTING;
        return;
    }

#11

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


#12

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!


#13

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


#14

I’m looking forward to it! :blush:


#15

Released: https://github.com/blynkkk/blynk-library/releases/latest


#16

Thank you for new version!