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

ESP32 secure connection failed after a while

Im using an ESP32 with local server.

After booting, the ESP32 connects to my wifi and connects to the local blynk server.
Everything works good and I sync the time every 15min.
But after about 60min the ESP32 looses connection to the blynk server and cant reconnect until I restart the ESP32 manually.

Connected to the Serial Monitor of the Arduino IDE gives me this:

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:928
ho 0 tail 12 room 4
load:0x40078000,len:8424
ho 0 tail 12 room 4
load:0x40080400,len:5868
entry 0x4008069c
[35] Connecting to MyWifi
[1176] Connected to WiFi
[1176] IP: 192.168.1.100
[1176] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP32

[1182] Connecting to my.url.com:9443
[2140] Certificate OK
[2146] Ready (ping: 5ms).
[2286] Time sync: OK
[902386] Time sync: OK
[1802512] Time sync: OK
[2702620] Time sync: OK
[3602681] Time sync: OK
[3908910] Connecting to my.url.com:9443
[3912911] Secure connection failed
[3913911] Connecting to my.url.com:9443
[3915830] Secure connection failed
[3918912] Connecting to my.url.com:9443
[3922912] Secure connection failed
[.....] 

Does anyone have an idea what I can do to locate the source of this problem?

You could try Googling this reset reason.

And this is probably something in your code, or due to SSL, or somthing else… but with no visible code or ESP32 Core version details, no idea :wink:

Thanks gunner for your reply.

Well the start of the serial output is just the normal hardware reset that was initiated after the successfull uploading of the sketch.
So just the stuff after

[35] Connecting to MyWifi

is important.

The code is this one:

#define BLYNK_SSL_USE_LETSENCRYPT

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <BlynkSimpleEsp32_SSL.h>

#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA

char auth[] = "MyAuthToken....";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MyWifi";
char pass[] = "MyWifiPassword";

char wiFiHostname[] = "ESP32";
char OTAHostname[] = "ESP32";

//RTC
#include <WidgetRTC.h>
WidgetRTC rtc;
BLYNK_CONNECTED()
{
  // Synchronize time on connection
  rtc.begin();

  //after booting up, read the values from the server
  Blynk.syncAll();
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass, "my.url.com", 9443);
  
  WiFi.setHostname(wiFiHostname);

    //OTA update
  ArduinoOTA.onError([](ota_error_t error) {
    ESP.restart();
  });
  ArduinoOTA.setHostname(OTAHostname);
  ArduinoOTA.begin();


  //RTC
  setSyncInterval(15 * 60); // Sync interval in seconds (15 minutes)  
}

void loop()
{
  Blynk.run();
  ArduinoOTA.handle();  // For OTA updates
}

Your code doesn’t seem to do anything… perhaps it just gets bored :stuck_out_tongue:

Have you tried without SSL?

I have never used this… perhaps there is some networking issue that trips the OTA error and does what it is told to do… although I am unsure ESP.restart(); is a true clean reboot with an ESP32 as it is on an ESP8266 :thinking:

oh that typo costed me a few seconds :smiley:
In another sketch with some work to do, it doesn’t gets bored, but also disconnects.

Server problems are definitely not an issue, as different hardware stays connected (on ESP8266… but also just for one day… but it reconnects quickly)

I will check without the OTA thing.
After that the SSL.

But for me SSL is a must, as the device is on a mobile hotspot.

Thanks for the ideas.
Feel free to drop more if they come to your mind :wink:

Edit:
Without OTA it still loses connection about every hour.

Turning off SSL will be a bit tricky as I have to do some server changes.

I will report back with the results…

So I have set up 3 devices:

  1. ESP8266 connected via SSL to my local server via public domain
  2. ESP32 connected via SSL to my local server via public domain
  3. ESP32 connected directly to my local via local IP adress

Started all devices this morning at 08:54.
ESP32 devices loses connection randomly at times between 30~200min

No OTA no nothing, just the bare blynk code.
Here the sketch for my local (via local IP) connection:

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

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


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";
char pass[] = "XXX";

char wiFiHostname[] = "ESP32noSSL";
char OTAHostname[] = "ESP32noSSL";

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  
  WiFi.setHostname(wiFiHostname);
}

void loop()
{
  Blynk.run();
}

Looks like the ESP32 is not supported for Blynk.

It is (it is working isn’t it :wink: ) buty just as mentioned in your other similar topic (why two topics anyhow?) the ESP32 is relatively new and still under it’s own development (Arduino Core) with espressif… thus changes…

Add to that the current Blynk version is undergoing some droppage of support in lew of a newer version… and we end up with what we gots :stuck_out_tongue:

1 Like

Well… its working somehow, but as its not stable right now, its not really “working”…

This topic here is about the gerneral problem of an unstable usage of the ESP32.
I get disconnects at best every 200min - worst case it doesnt reconnect after that.

The other topic is about the very slow speed of the ESP32 compared to its little brother the ESP8266.
I dont want to mix these topics.

And “relatively new” is somehow strange… I got mine sind 1st september 2017. This is almost 2 years -> so almost ages in electronics :smiley:

By the way… is there a common method to show devices up-time?
I mean… I can send a value of each device every minute to V1 (or similar) and show it in a superchart to track if the device was connected to the server, but maybe there is a smarter solution :slight_smile:

I will keep the 3 devices online for a time and evaluate how stable they are.

The ESP8266 that I am using right now with blynk in a sonoff S26 reconnects also every day, but this is not as important as for my current project (and it always reconnected).

Maybe I have to switch to an ESP8266 for this project and use an I/O expansion module to control everything…

Oh, the hardware has been around… but the development of the Arduino compatible core software (from espressif) is still ongoing… and Blynk library support relies on that.

Understandable… however the root of the ESP32 architectural difference between your compared “speed and reliability” of the ESP8266 is related in both topics… thus so likely is any “solution” or suggestions.

Basically, how to best run the Blynk library on an ESP32 (AKA like an ESP8266, or by taking advantage of the dual core) will determine both the speed and reliability. Thus both topics have the same root… Blynks ESP32 library and how best to utilise it.

Unfortunately, there doesn’t seem to be any forward action on what we currently have… thus short of you tweaking the library internals yourself… well… have fun :slight_smile:

FYI, I have an ESP32 running a Blynk/Virtuino/Nextion combo script 24/7. It seems sufficiently up to the speed task, but it does stall every once in awhile, sometime less than an hour, sometimes 2-3 days, then the main loop seems to stop and my “reboot/reconnection” routine never triggers… but as I tweak my codes timing, it seems to last longer between issues. I am NOT utilising any dual core operations, just treating it like I would an ESP8266.

I have another ESP32 running some LCD display and RGB colour changing routines, and it NEVER stalls out… but it is also NOT utilising any Blynk or even WiFi link (except OTA), so perhaps the constant WiFi link with Blynk is the issue?

I generally use a simple uptime increment counter every second or minute… output to a display widget and or Serial Monitor.

  // Timed Lambda Function - UpTime counter
  timer.setInterval(1000L, []() {  // Run every second
  // Display the UpTime in Minutes, or millis()/1000 for seconds
  Blynk.virtualWrite(V0, millis() / 60000);
  Serial.println(millis() / 60000)
  });  // END Timer Function

Hah… took me days to figure out which typo you ment :blush: Darn autocorrect… ya, that’s it :innocent:

1 Like

Thanks Gunner for your response.

I guess you are right with the developement state as sad as it is.

Yesterday evening I decided to do the project with and ESP8266 and an IO expander for that reason.

As I woke up, I saw this:


Both of the ESP32 devices are still rebooting almost at the same time (might be some buffer overrun or similar during runtime… as a rough guess).

But the ESP8266 is now also offline - since hours.
The device is of corse not changed since it worked about 14 hours constantly.

I even rebooted it, pluged it to the PC to see the serial output. And it shows this:

[569] Connected to WiFi
[570] IP: 192.168.1.XXX
[570] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[591] NTP time: Fri Jul 19 14:48:35 2019
[591] Connecting to XXX.com:9443
[5592] NTP time: Fri Jul 19 06:48:39 2019
[5592] Connecting to XXX.com:9443
[10592] NTP time: Fri Jul 19 06:48:44 2019
[10592] Connecting to XXX.com:9443
[....]

The server time is around 08:48 … Dont know if this is a problem here.

on the ESP8266 its still this code:

#define BLYNK_SSL_USE_LETSENCRYPT

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <BlynkSimpleEsp32_SSL.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";
char pass[] = "XXX";

char wiFiHostname[] = "ESP8266SSL";

//RTC (real time clock)
#include <WidgetRTC.h>
WidgetRTC rtc;
BLYNK_CONNECTED()
{
  // Synchronize time on connection
  rtc.begin();

  //after booting up, read the values from the server
  Blynk.syncAll();
}

void setup()
{
    // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass, "XXX.com", 9443);
  
  WiFi.setHostname(wiFiHostname);

  //RTC
  setSyncInterval(60); // Sync interval in seconds (15 minutes)
}

void loop()
{
  Blynk.run();
}

My other ESP8266 device, that was running inside the sonoff S26 (and has been working for ~3weeks now) also stopped this morning at 6am.
And its still not reconnected at 9am (and I never had this before).

This is pretty strange.
The server is still reachable as the ESP32’s connects to it (with its reconnection cycles every 30-200min).
I would also expect the ESPs disconnects at the same time if it is server related.
Right now I am having unstable connections with every device.
In the past it was just one reconnect of the remote sonoff S26 every night and I thoug it was because of new IP adresses given by the internet provider and the dynDNS chain…

Any thoughts?

Sounds like a local networking problem to me.

Pete.

I have a heavily congested WiFi network, but one that generally works solidly. However, I have just re-learned that silly little things can do strange stuff to otherwise solid connections.

Simply opening my motorhome door to let the cat in and out started a corresponding issue with a group of security cameras and probably one of my ESP8266 setups… something that happens all the time over the years, but I had not cognitively put the two action and reaction groups together until yesterday :blush: This brain fog has been fairly debilitating in day to day stuff, but even more notable so when it comes to my normally good technical thinking.

Turns out it was a simple case of the routers signal being partially blocked in one direction by the door (even though it is fiberglass), and probably reflecting off of same door in the other direction…likely canceling out some of the original signal to another device. So far, simply changing the routers antenna position resolved the issue.

1 Like

Next project - RDID cat flap!

Pete.

1 Like

did you mean RFID?

Yes, big fingers strike again!

Pete.

1 Like

That is really strange…
I tried to get my ESP8266 online again, but this device and my more then 3 weeks working esp8266 wont connect any more.

First I thougt, my test device is broken, so I took a new ESP8266 (Wemos D1), then another new one (NodeMCU) then another new one (Wemos D1 pro).
None worked.
Library not changed on my PC everything the same (not even rebooted since days).

So the case is clear. It must be a server problem right?

I took my server and took the snapshot from yesterday morning.
After finished - still not connection (always getting the “NTP time:” message from the serial).
Then I took a snapshot from 3 days ago - still not working.

Then I used the official blynk server (not my local one) and it does work.
So the question is, how can the device with exact the same sketch on a snapshot of my server not work, as it did yesterday?
Does anyone has an idea else then voodoo? :D:D

Your problem may be due to the DHCP router
try static IP

Tried that but no different reaction :frowning: