electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

ESP8266 Stops Working if I don't provide Wifi during specifc step #71

Closed brnyza closed 5 years ago

brnyza commented 5 years ago

To test the WiFi connection I'm sharing the WiFi of my cellphone.

If I stop the WiFi sharing during the command below, the ESP8266 stops working. It only works if I do a hardware reset.

If I don't stop the WiFi it works normally.

if(client->POST(urlCal, host, payload)) { RetornoPost = client->getResponseBody(); }

Does anyone know why ESP8266 stops working?

pierangelof commented 5 years ago

Hi, it is difficult to say what is happening in your specific case without having detailed information. Anyway I can share my experience: I have a similar problem when the client tries to connect and internet is not available. In my case, the ESP8266 does not crash but just waits for the internet connection. In order to make the code more robust, you can check for the wifi status (WiFi.status() == WL_CONNECTED) to be sure that at least the wifi client is connected to the AP. This will not solve the problem in the case there is a wifi connection but internet is not available. I solve this specific problem with a ping but so far the code is buggy and the esp8266 crashes. Bye and happy Xmas time.

electronicsguy commented 5 years ago

Updated for compatibility with latest version of esp8266 library (2.5.0-beta2). Please use this and report back.

brnyza commented 5 years ago

Thank you! Now is working!

brnyza commented 5 years ago

Sorry for the wrong information, but unfortunately, the error keeps occurring with "2.5.0-beta2". Sometimes ESP8826 restart when there is an error and is OK. But other times ESP88266 breaks, and I have to do a Hardware Reset.

brnyza commented 5 years ago

If I stops 3G(internet), or only the Wifi, during this command, from my cellphone, the ESP8266 stops working

pierangelof commented 5 years ago

Hi, I had a similar problem. In my case the problem arose when the internet connection was interrupted and the http client was still in use. I have solved the problem by creating a new client every time a send request is performed. In this case, if there is no internet connection, the client is not created and the system does not hang waiting for the internet connection. I hope it helps.

brnyza commented 5 years ago

Hi pierangelof! Just to be clear, for each command you: 1st - Clear the client like this:

delete client;
client = nullptr;

2nd - After, you create the client again?

client = new HTTPSRedirect(httpsPort);
client->setInsecure();
client->setPrintResponseBody(true);
client->setContentTypeHeader("application/json");
client->connect(host, httpsPort);
electronicsguy commented 5 years ago

@brnyza Could you list out the exact steps for me to reproduce the issue?

brnyza commented 5 years ago

Dear @electronicsguy

It occurs in the step below: The POST command is taking about 3 sec. During this time, if I turn off the provided Wifi from cellphone, the ESP breaks.

Serial.println(millis());
Serial.println("BEGIN");
if(client->POST(urlCal, host, payload, true)) { 
RetornoPost = client->getResponseBody(); 
} 
else {
++error_count;
}
Serial.println("END");
Serial.println(millis());

image

pierangelof commented 5 years ago

Hi pierangelof! Just to be clear, for each command you: 1st - Clear the client like this:

delete client;
client = nullptr;

2nd - After, you create the client again?

client = new HTTPSRedirect(httpsPort);
client->setInsecure();
client->setPrintResponseBody(true);
client->setContentTypeHeader("application/json");
client->connect(host, httpsPort);

Hi, correct, what you wrote is more or less what I meant. You could also think to write the code to post the data in a function and to use a local variable for the client.

brnyza commented 5 years ago

Hi @pierangelof, I've modified the code to POST the data in a function, using local variable, but ESP8266 still breaks, if I don't provide WiFi.

pierangelof commented 5 years ago

Hi @brnyza , in my case, the problem was generated by an interruption of the communication on the WAN side but the WLAN connection was still available. In your case, you could use a conditional clause in order to be sure that the data are sent only if there is a WLAN connection. Something like: if (WiFi.status() == WL_CONNECTED) { _[post the data to gcloud]_ } I hope it helps.