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

Device lost in application


#39

Ok, I have both devices disconnected. Here is the log from the second one, which was running the test firmware:

[121358] Blynk is connected
WiFi is Connected
[12138438] Heartbeat timeout
[12143311] Connecting to blynk-cloud.com:8441
[12143917] Certificate OK
[12143951] Ready (ping: 33ms).
[121958] Blynk is connected
WiFi is Connected
......
[127358] Blynk is connected
WiFi is Connected
[12784311] Heartbeat timeout
[12789148] Connecting to blynk-cloud.com:8441
[12794149] Connecting to blynk-cloud.com:8441
[12795768] Certificate not validated
[127958] Blynk is not Connected any more
WiFi is Connected
[12796150] Login timeout
[12799150] Connecting to blynk-cloud.com:8441
[12804151] Connecting to blynk-cloud.com:8441
[12809152] Connecting to blynk-cloud.com:8441
[12814153] Connecting to blynk-cloud.com:8441
[12814661] Certificate not validated
[12816154] Login timeout
[12819154] Connecting to blynk-cloud.com:8441
[12819534] Certificate not validated
[12821155] Login timeout
[12824155] Connecting to blynk-cloud.com:8441
[12824538] Certificate not validated
[12826156] Login timeout

So, after the second try it couldn’t reconnect any more to the server.


#40

So you are using SSL?


#41

Code snippets are not really going to help.

We need the minimum FULL sketch that exhibits your issue.


#42

@shur1k And please format them properly when posting here… as I have had to do for your last few…

Blynk - FTFC


#43

Yes, sorry for didn’t mention it before.
The sketch, actually, is a slightly modified example from a Blynk Code Builder. Here it is:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

char auth[] = "***************************9f7";

char ssid[] = "********";
char pass[] = "********";

BlynkTimer timer;

void myTimerEvent()
{
  if (Blynk.connected()) {
    Serial.print("[");
    Serial.print(millis()/100);
    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()/100);
    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");    
 }  
}

void setup()
{
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(60000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Besides, my device manage to reconnect in a few hours. It never happend before.


#44

Aside from the extra overhead, due the SSL, that could be causing the disconnection in the first place…

When using Blynk.begin() and no connection management, if WiFi or even just server connection is lost, your sketch will also stop running.

You need to look at some form of connection management that allows the sketch to keep running, and even reconnect when WiFi and Server is again available.

One example is here:


#45

@shur1k your sketch seems to be running fine here.

I have made a few changes like baud at 115200 as 9600 is only for super slow Arduino’s.
I have reduced the 60s timer to 10s and added a blinking Blynk LED on V0.

Providing your router doesn’t crash and that you manually reset your ESP after each local flash it should run forever without any connection management modifications.

I am using the following settings:

Blynk library v0.5.0 on their cloud server. Android app version 2.18.2
lwIP v1.4 Prebuilt and master Core as it was about 3 weeks ago (not 2.4.0 release).

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

char auth[] = "xxxxx";

char ssid[] = "xxxx";
char pass[] = "xxxx";

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(115200);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Please note the team behind the ESP8266 Core development are not entirely happy with their SSL implementation of axTLS. They are looking to switch to BearSSL. ESP8266’s really start to struggle with axTLS when you start to add complex libraries to your sketch so you would need to add functions one at a time and see if the ESP still runs OK. That is, don’t add 100 widgets and then test your project, build it up slowly.

This is Serial Monitor for your sketch:

[24006] Connecting to Myhomewifi-2797
[25009] Connected to WiFi
[25009] IP: 192.168.1.239
[25510] Got time: Wed Feb 28 15:02:19 2018

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

[25530] Connecting to blynk-cloud.com:8441
[26231] Certificate OK
[26295] Ready (ping: 62ms).
[36] Blynk is connected
WiFi is Connected
[46] Blynk is connected
WiFi is Connected
[56] Blynk is connected
WiFi is Connected
[66] Blynk is connected
WiFi is Connected

I will leave it running for a few hours but with the correct Core settings it looks OK.


#46

@shur1k looking back at one of your earlier posts I see you are missing the heartbeat with your “real” sketch.

This is exactly the same as covered in the link by @PeteKnight when using “bad Core” settings and DHT sensors.


#47

Thanks @Gunner, @Costas
Just a few remarks. It’s not my sketch, it’s an example from the Blynk Code Builder, just to show that the problem is not in my code. And it worked fine for a 2 or 3 hours, when I’d started it yesterday. And only after that time it started to face troubles with connection. Please, note, that the both devices were disconnected at approximately the same time, regardless the different firmware running. The second device was running a pure blynk I can say.
@Gunner, I can rewrite the code to use the manual reconnect, but I don’t think it will help, As can be seen from the log (serial port messages), there were endless attempts to reconnect, but with no luck.
I think, that the most probably reason (as @Costas described), the problems with SSL inside the ESP8266 core. I’ll probably switch off the SSL in one of my devices and will see if it helps.
Thanks to everybody once again.


#48

It’s not just SSL Core that is buggy it’s the official Core 2.4.0 release especially lwIP and combined with DHT sensors.

If you run a very basic Blynk sketch without any sensors the Core bugs might not be a problem but as soon as you start to add SSL, DHT, hostname, other lwIP functions you are likely to have problems.

Most of the Core bugs have been fixed and you need to pick up the master with Git until they release the new Core.


#49

Correct… the manual reconnect is more for specific scenarios, so far as I can tell, but doesn’t hurt to have it.

I just thought you were trying to have the serial prints run when not connected to the server… for that you will need the isolate the Blynk.run() command to only process when connected to the server.

@Costas I am still unclear about all these bugs that are supposed to be lurking due the bad core… perhaps you can take a look here… it just keeps running fine… even before connection management I have just added.


#50

@Gunner are you running with 2.4.0-rc2 or 2.4.0?


#51

2.4.0 Which should be the latest “release” as both rc1 & rc2 show as older versions in the IDE


#52

2.4.0-rc2 is the version before 2.4.0 and generally didn’t seem to have some of the issues found in 2.4.0.

I don’t know precisely why some users don’t experience the bugs and others do, but they are there along with the bug fixes.


#53

@Gunner why do you have the very long 60s hearbeat timeout in that particular sketch?


#54

I think I was experimenting due to various RGB Strip driver options I was using before I settled on Fast_LED. That sketch is doing a lot, all at once, so seemed wise to stretch out the heartbeat. And it works, so I never reset it :wink:


#55

@Gunner you are setting OTA hostnames whereas others are setting just hostnames. After the very first hard reset OTA sketches don’t need any further hard resets to keep running were sketches flashed locally require a hard reset after every flash. You don’t use Serial Monitor as you are using OTA and wouldn’t see if the ESP had a reset.

What is the current uptime for that project?


#56

Only 192 min… but that is becasue I am constantly fiddling around and testing that and other projects and resetting my router… but even when I leave things alone, they may reset due to whatever… but, they keep running.

My purpose for further inquiry in this topic was that I also always keep all other libraries updated (and eliminate any duplicates)… so I was just wondering if instead of always assuming the “buggy” core (although I agree, it is probably partially to blame… price of constant development), perhaps there are other library conflicts, corruption, version, etc. at play with many of these “common” disconnection issues?


#57

I don’t know who did the magic, but both of my devices work fine from the early morning. No disconnects can be seen. The temperature data is being sent each 15 seconds from each device and I don’t see any gaps on the graph. Will see what will be further.


#58

One of my devices disconnected from the server after a day and a half staying connected to WiFi . The second one couldn’t reconnect after the WiFi signal lost. Reboot solved the problem as usual. Didn’t try without SSL yet.