Device lost in application

If both are running SSL then based on your comments and our tests then I don’t think SSL is an issue.

Sounds like you had some random WiFi issue for the ESP that crashed. For me I would guess that the reason for the ESP not automatically reconnecting is an ESP Core issue similar to this https://github.com/esp8266/Arduino/issues/4242

As you will see the dev’s are still trying to resolve an issue with WiFi.disconnect().

You need to run both devices hooked up to Terminal app’s like Serial Monitor and Termite to get a better understanding of what’s happening. In addition try to track down the reason for the WiFi disconnect like proximity to routers, microwaves etc.

Connection Management, as covered in the docs, might help but if it’s a problem with the Core then it may not fix the problem.

@Costas. the problem is not in WiFi connection, the problem is in connection to Blynk server. As my previous test shown (see the log in post 39) there was no WiFi connection lost, just the connection to Blynk cloud server was lost.
As for my second test, the WiFi connection lost was made by the purpose, just to check if the device will be able to reconnect to server. And it failed. WiFi connection was restored, but the connection to Blynk server wasn’t.
I’ll try to leave at least one of the devices connected to terminal for a long period of time to see the messages, but I don;t think, that there will be something new.

Perhaps you could clarify this statement.

I am going to write what I thought you had written and you can correct my statement.

Device A disconnected from the server but the WiFi connection was never dropped.
Device B lost WiFi connection and didn’t automatically reconnect to the Blynk server.
Manually rebooting devices A and B reconnected them to the Blynk server.

Device A presumably reconnected to the Blynk server automatically.

Device A and device B are both connecting via SSL.

@Costas, sorry, if my text was a bit confusing. Everything you wrote is absolutely right, Except this one:
“Device A presumably reconnected to the Blynk server automatically”. This problem lasts for a bit of time (more than a month, I believe) and it was just once, that one of the devices managed to reconnect to Blynk server after a couple of hours without a reboot. All other times I needed to reboot them by circling the power. The working period without disconnects is variable. Sometimes (especially in the evening) I need to reboot the devices each 10-30 minutes. But usually everything works properly for a 2-5 days and then it disconnects from the server. The longest period of working time was about two weeks. Am I really the one, who faces this problem?

I remember something similar. It that case reason was - neighbors. At evening they come to home and start to turn on devices that were interference with esp wi-fi signals that made them reconnect again and again.

Additional option to try would be turning off SSL connection and test without ssl.

Others have issues too and that is why Blynk provide connection management tools.

There are many, many reasons why a device might disconnect from a server and the problem is trying to establish the specific reason.

You state the problem is worse in the evening but are you actually monitoring the problem during the day?

There are code examples on this site to automatically reboot the ESP if the connection to the server is lost.

Yes, I quite often check the status on my smartphone and see, if the device is available.

Thank you, @Costas! Will try to find them, this probably will help me a lot.

Thanks @Dmitriy, that is actually the next step I wanna try.

I flashed one of the devices with non-SSL firmware, second one runs the same firmware, but with SSL. Just in case, both devices were rebooted. The SSL one is located directly near the router, so the singal strength is very high and shouldn’t be any problems with WiFi connection. The non SSL one is located quite far from the router (the signal strength is approximately -68 dBm), so, potencially may have some gaps (droppped packages). Will see how long will they work without disconnecting from the server.

I also added a third device yesterday with a test SSL firmware, which you can find some posts above.
Both SSL devices were disconnected almost simultaneously after an hour or so. Here is the serial log from the the test device:

[67811] Connected to WiFi
[67811] IP: 192.168.31.254
[67812] Got time: Thu Jan  1 08:00:04 1970

[67812] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino

[67945] Connecting to blynk-cloud.com:8441
[68359] Certificate not validated
[69946] Login timeout
[72946] Connecting to blynk-cloud.com:8441
[73340] Certificate not validated
[77947] Connecting to blynk-cloud.com:8441
[78340] Certificate not validated
[82948] Connecting to blynk-cloud.com:8441
[83351] Certificate not validated
[84949] Login timeout
[87949] Connecting to blynk-cloud.com:8441
[88326] Certificate not validated
[89950] Login timeout
[92950] Connecting to blynk-cloud.com:8441
[93327] Certificate not validated
[94951] Login timeout
[97951] Connecting to blynk-cloud.com:8441
[98513] Certificate OK
[98549] Ready (ping: 34ms).
[1586] Blynk is connected
WiFi is Connected
[2186] Blynk is connected
WiFi is Connected
[2786] Blynk is connected
WiFi is Connected
.................................................
.................................................
[27386] Blynk is connected
WiFi is Connected
[27986] Blynk is connected
WiFi is Connected
[2827723] Connecting to blynk-cloud.com:8441
[2834681] Connecting to blynk-cloud.com:8441
[2835451] Certificate OK
[2835487] Ready (ping: 34ms).
[28586] Blynk is connected
WiFi Connection is lost
[2872739] Heartbeat timeout
[2876564] Connecting to blynk-cloud.com:8441

Exception (28):
epc1=0x40203e85 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000396 depc=0x00000000

ctx: cont 
sp: 3fff0db0 end: 3fff1030 offset: 01a0

>>>stack>>>
3fff0f50:  3ffefcb0 00000000 3fff215c 40203e7e  
3fff0f60:  85ce3b8b 00000004 3ffeff3c 3ffe8c44  
3fff0f70:  000020f9 3ffefcb0 3ffe8c44 3ffe8c44  
3fff0f80:  000020f9 3ffefcb0 3ffe8c44 40204dd3  
3fff0f90:  3ffe93e8 85ce3b8b 3ffe93e8 85ce3b8b  
3fff0fa0:  3ffe8a5c 3ffeff3c 3ffefc98 40202864  
3fff0fb0:  3ffe8ab4 3ffefc98 3ffefc74 40204e02  
3fff0fc0:  3ffe8a1c 00000000 3ffefc74 00000000  
3fff0fd0:  002be494 3ffefc98 3ffefc74 40202a33  
3fff0fe0:  00000000 3ffefccc 3ffefff4 40204e28  
3fff0ff0:  00000000 3ffefa30 3ffefa30 3ffefffc  
3fff1000:  3fffdad0 00000000 3ffefff4 402034c3  
3fff1010:  3fffdad0 00000000 3ffefff4 40205934  
3fff1020:  feefeffe feefeffe 3fff0010 40100710  
<<<stack<<<
c_⸮c_⸮

@shur1k what I have noticed with the sketch I posted previously is that it takes 48s from ESP reboot before it tries to connect to Blynk server. Some of my regular sketches are connected to the Blynk server within 500 to 600ms of a reboot. But unlike your sketch my code connects every time without any certificate errors etc.

[1064] Connected to WiFi
[1064] IP: 192.168.1.239
[48073] Got time: Fri Mar  2 16:17:48 2018

[48074] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino

[48093] Connecting to blynk-cloud.com:8441
[48807] Certificate OK
[48876] Ready (ping: 67ms).
[59] Blynk is connected
WiFi is Connected
[69] Blynk is connected
WiFi is Connected
[79] Blynk is connected
WiFi is Connected
[89] Blynk is connected
WiFi is Connected

Those certificate errors look strange for me also. I can’t understand, why the same certificate may be not validated and then validated.

@shur1k remind me which MCU you are using and which one you are selecting in the IDE.

I am using WeMos D1 Mini but I always run with Generic in the IDE.

Going to add full Core debugging and check what’s happening in the delayed bootup period.

@Costas, I use NodeMCU (my main devices) and a ESP12E Module. (a test device).
I select NodeMCU V1.0 for ModeMCU and a Generic ESP8266 Module for a ESP12E Module, otherwise it can’t be flashed at all.

If you are saying NodeMCU will not flash as Generic you are mistaken. All you need to do is set the reset method from ck to nodemcu. Just flashed a NodeMCU here as Generic.

I think I know why you are getting the certificate errors.

If I compile with the default lwIP for 2.4.0 i.e. (v2 MSS=536) it gives cert errors, if I compile with lwIP v1.4 there are no cert errors.

The default lwIP is certainly more buggy than v1.4 and there are lots of fixes due to be released for the default lwIP.
Unfortunately lwIP v1.4 has an issue with sntp. It can take up to 60s to pick up the time from the Espressif server in China when using SSL. The hacks in the following sketch allow you to use the v2 default lwIP without cert errors.

// SSLconnectionV2.ino testing lwIP for https://community.blynk.cc/t/device-lost-in-application/22718
// hack to make SSL work with default lwIP
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

extern "C"  // to get sntp
{
  #include "sntp.h"
}

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx"; 

BlynkTimer timer;

void myTimerEvent()
{
  Blynk.virtualWrite(V0, 0);
  delay(100);
  if (Blynk.connected()) {
    Serial.print("[");
    Serial.print(millis()/1000);
    Serial.print("]");
    Serial.println(" Blynk is connected");
    if (WiFi.status() == WL_CONNECTED) Serial.println("WiFi is Connected"); 
    else Serial.println("WiFi Connection is lost");
  }
 else { 
    Serial.print("[");
    Serial.print(millis()/1000);
    Serial.print("]");
    Serial.println(" Blynk is not Connected any more");
    if (WiFi.status() == WL_CONNECTED) Serial.println("WiFi is Connected"); 
    else Serial.println("WiFi Connection is lost");    
 }
 delay(100);  
 Blynk.virtualWrite(V0, 255);
}

void setup()
{
  Serial.begin(74880);                    // ESP default debug
  Serial.println("Setup(): " + String(millis()));
 
  sntp_stop();
  sntp_setservername(0, "de.pool.ntp.org");
  sntp_setservername(1, "fr.pool.ntp.org");
  sntp_set_timezone(0);
  sntp_init();
  
  WiFi.persistent(1);                     // true 1 or false 0
  WiFi.mode(WIFI_STA);  
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) delay(1);
  Serial.println("WiFi connected: " + String(millis()));  
  Blynk.config(auth, "blynk-cloud.com", 8441);
  Blynk.connect();
  timer.setInterval(20013L, myTimerEvent);
}


void loop()
{
  yield();
  Blynk.run();
  timer.run();
}
1 Like

Sorry, I meant the opposite, ESP12E won’t flash if set NodeMCU.
Thanks a lot @Costas, really appreciate your help! Will try to flash yours hacked version to see, what will be.
Besides, there were no disconnections for SSL devices from this morning and for non SSL device - sonce the last evening.

Hi All,
@Costas, tried your workaround, but, unfortunately, the result is the same:

[73430] Blynk is not Connected any more
WiFi Connection is lost
[73430795] Connecting to blynk-cloud.com:8441
[73431167] Certificate not validated
[73432796] Login timeout
[73435796] Connecting to blynk-cloud.com:8441
[73436169] Certificate not validated
[73437797] Login timeout
[73440797] Connecting to blynk-cloud.com:8441
[73441160] Certificate not validated
[73442798] Login timeout

But yesterday I’ve updated the Blynk library to the latest version and seems, that now SSL device is able to reconnect to the Blynk server. Will monitor it a bit more.

1 Like

It will probably have been the ESP8266 Arduino Core update to 2.4.1 that fixed everything. I have SSL with 2.4.1 and the default lwIP, all OK.

I have now four devices connected to Blynk: one is without SSL and three with SSL (NodeMCU with the old firmware (before the latest update), ESP12E module with the Costas’s test firmware and a Wemos D1 with the latest update of library). All three SSL devices were disconnected this night and were unable to reconnect to Blynk server, just a non-SSL device was connected at the morning. I have restarted all the SSL devices. Monitoring further…

I have an SSL connection running to Blynk server. Been running for about 24 hours. It’s very basic though, just blinks a physical LED and a Blynk LED. It’s with latest Core of 2.4.1 and latest app / libraries etc.

SSL encrypts each passing communication doesn’t it? I guess that it can become more susceptible to wireless issues, unless it also has error checking (does it??), the more data flow, the better the chances of dropped connection?

EDIT… a little Googleing later (very little :blush: … too confusing for me right now)… it seems SSL is actually old but it’s predecessor does have data integrity? or perhaps they both do, but is still just too much processing for a little MCU to keep up with if doing anything else meaningful in the background.

This is why I stay away from SSL :stuck_out_tongue: … don’t know enough yet to fully utilise it.