ESP32 going offline every few min

Hello,

I have 2 ESP32 devices running on stock edgent sketch with indicator attached on pin 5.

If the ISP is down or the Wifi goes down, the indicator still breaths indicating the ESP32 is connected to the cloud. Whereas the app shows the device is offline. Only then i get to know that the device has lost connection.

To check this behaviour, I unplugged the incoming connection from ISP to create a scene of No internet.

The indicator breath normally indicating it’s connected to the cloud. Even after the internet is back it doesn’t come online, because it never knew it has lost connection and doesn’t try to reconnect back.

And very randomly every 1 out of 100 times it starts blinking saying no internet and connects back when the ISP is Up.

This is really strange. There is no changes made in the .h files or .ino

And the loop is absolutely clean. No delays.

Even the serial monitor shows no signs of connection. If I restart the esp32 manually, it will connect and stay connected for a while and then again goes offline. But the ESP32 doesn’t know that. Until I reboot seeing the offline status on the app.

Can you guys point me on how to solve this issue.

Posting your code might help .

Bare minimum sketch that is given in arduino examples. No changes made. Uncommented LED pin and defined pin 5 as indicator LED. No more changes or additions made.

EDIT:

Is there any way to force check connection status and reconnect to the cloud? This is already there in the Edgent sketch. But its not working now.

Downgrading the lib version will help? Is it a good idea to do so? I am now on the latest version. And latest ESP32 core.

I’d start by adding some debug info into void runBlynkWithChecks() in BlynkEdgent.h

Pete.

void runBlynkWithChecks() {
  Blynk.run();
  if (BlynkState::get() == MODE_RUNNING) {
    if (!Blynk.connected()) {
      if (WiFi.status() == WL_CONNECTED) {
        BlynkState::set(MODE_CONNECTING_CLOUD);
        Serial.println("MODE_CONNECTING_CLOUD"); // added
      } else {
        BlynkState::set(MODE_CONNECTING_NET);
        Serial.println("MODE_CONNECTING_NET");  // added
      }
    }
  }
}

Just tried. But there is no output. Because it never checks for the wifi connection or internet. It just executes Blynk.run. Serial monitor is empty. After it shows the Blynk banner on boot with connection status.

Also tried two different approachs

void check_conn() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

And

void check_conn() {
  if (Blynk.connected()) {
    runBlynkWithChecks();
  } else {
    enterConnectNet();
  }
}

The above function is called by a timer (tried with 15sec, 30sec, 60sec). But no luck. If i restart the device manually then it connects back as usual and stays online for few min. Later goes offline and stays there. No change in the indicator pattern. The app shows offline.

once in a while very randomly it reconnects with the following output on serial monitor

[878621] Connecting to 0.0.0.0   ////////////// turned off wifi for testing
[878621] Secure connection failed
[883622] Connecting to 0.0.0.0
[883622] Secure connection failed
[888623] Connecting to 0.0.0.0
[888623] Secure connection failed
[891620] Not reconnected
[906620] Connecting to 0.0.0.0
[906620] Secure connection failed
[911621] Connecting to 0.0.0.0
[911621] Secure connection failed
[916622] Connecting to 0.0.0.0
[916622] Secure connection failed
[921623] Connecting to 0.0.0.0
[921623] Secure connection failed
[924620] Not reconnected
[924620] Using Dynamic IP: 192.168.43.60   ////////////// turned on wifi for testing
[924620] CONNECTING_NET => CONNECTING_CLOUD
[924630] Connecting to blynk.cloud:443
[925677] Certificate OK
[925879] Ready (ping: 200ms).
[926058] Time sync: OK
Connected
[926151] CONNECTING_CLOUD => RUNNING
[926185] Time sync: OK

The above output is printed only if the device is working normally. If it hangs then, there will be no output on serial monitor related to blynk.

i have an switch connected that turns on a led when pressed(to see if the board is still working[testing]) and yes the led responds to the button presses. This proves that only the Blynk part is hanging.

I don’t think the couple of lines of code you’ve added prove very much. I’d add a serial print after each if statement to understand which ones are evaluating as true and which as false.

Pete.

Agreed. But when it hangs, there is no output whatsoever. Serial monitor stays blank.

I added serial print along with the button presses and that prints when button is pressed.

But serial prints related to blynk stuff never prints. Like the once i added above.

As per my understanding, the runBlynkWithChecks hangs and never runs again. Thats the reason the led indicator breath normally stating the connection is successful.

I’m not really following what you’re saying here.

Pete.

Blynk part of the code hangs. Rest all works. That is what i got to know.

Because even after the internet is back, it doesn’t try to reconnect.

EDIT:

I have the same code running on other ESP32’s fine. But only these 2 particular ones are giving issues.

Not sure is it something to do with the hardware. Let me change the modules and see if this solves the issue. I will update her.

Hello,

It seems like its something to do with the hardware. The same exact code is working fine on other ESP32.

The two modules i mentioned earlier must have gone bad. Not sure.

But non blynk sketch and normal wifi connections works fine on these (bad onces).

I couldn’t come to an conclusion on what was wrong.

But there seems to be no problem in the code.