(SOLVED) Problem (reconnecting) when restarting router

I am using sparkfun esp32 thing, if I restart my router while the esp32 is powered it will not be able to reconnect to blynk server! any help please.

Um, perhaps don’t restart your router when the ESP is powered then?

Seriously, this is a Blynk forum, not a general technology troubleshooting forum, and while we see some strange things here, I am fairly sure your issue doesn’t involve an overused BLYNK_WRITE() command or syntax error.

I don’t really see what we can we offer that would help in your situation? But let’s get a bit more detail anyhow…

Define the exact reason for restarting your router… as in why? On purpose? By accident? Feline CATastrophe?

Cloud Server or Local Server

By not reconnecting to the server, do you mean after the router boots up the ESP32 doesn’t automatically reconnect to the WiFi? or just not reconnecting to the Blynk Server?

Are you running DHCP or Static IP on the ESP32?

What DO you have to do to get it to reconnect?

Hello. What does serial output shows at that moment?

When I used to use nodemcu ESP8266 this issue was not exist. It is DHCP protocol and to reconnect by pressing RST button, power off then on or just click on serial monitor in arduino IDE.

Hmm, maybe I am misunderstanding the issue you originally described… how can a NodeMCU or ESP8266 stay connected when a router is reset, but the ESP32 loose connection (as would be expected… since the router is well, disconnected).

I think what you meant is that it doesn’t automatically reconnect to your WiFi like the others did. That could be something particular to the ESP32, it is a different architecture to the others. Perhaps a firmware setting or even how you have the WiFi management set up on it.

As @Dmitriy asked, can you show us what is displayed on the IDE serial monitor when this happens.

This is my serial monitor output.

Please any body instruct me how to do automatic reset for sparkfun esp32 thing when Blynk server disconnected i.e wdt reset?

Did you get up on the wrong side of the bed mate?

Seeing as this is a common issue - only affecting ESPs on Blynk (Personally i have 23 connected via MQTT around the house that never fall over) this may very well be the right place for the question.

[185565082] Connecting to 192.168.1.25:8442
[185565100] Ready (ping: 13ms).
[185691165] Connecting to 192.168.1.25:8442
[185696166] Connecting to 192.168.1.25:8442
[185696183] Ready (ping: 8ms).
[190524131] Connecting to 192.168.1.25:8442
[190529131] Connecting to 192.168.1.25:8442
[190529223] Ready (ping: 21ms).
[191202062] Connecting to 192.168.1.25:8442
[191203633] Ready (ping: 8ms).
[192125878] Connecting to 192.168.1.25:8442
[192130879] Connecting to 192.168.1.25:8442
[192131289] Ready (ping: 7ms).
[192137277] Connecting to 192.168.1.25:8442
[192142278] Connecting to 192.168.1.25:8442
[192142310] Ready (ping: 1ms).
[192158401] Connecting to 192.168.1.25:8442
[192158942] Ready (ping: 4ms).
[192193074] Connecting to 192.168.1.25:8442
[192198075] Connecting to 192.168.1.25:8442
[192199767] Ready (ping: 75ms).
[192219097] Connecting to 192.168.1.25:8442
[192224098] Connecting to 192.168.1.25:8442
[192224205] Ready (ping: 23ms).
[192229206] Connecting to 192.168.1.25:8442
[192229258] Ready (ping: 0ms).

Try add an additional check in the loop to confirm that the wifi connection is available:

void loop()
{
if (!client.connected()) {
client.disconnect();
reconnect();
}

if (WiFi.status() != WL_CONNECTED){
setup_wifi();
}

Blynk.run();
client.loop();
}

'WL_Connected" is not perfect as it only checks if the ESP has a IP address, the ESP will retain the IP address for sometime after the wifi has disconnected.

I add this code but error, what library should I include? please can you give me details about this sketch ( I am beginer)?
void loop()
{
if (!Client.connected()) {
Client.disconnect();
reconnect();

}
if (WiFi.status() != WL_CONNECTED){
setup_wifi();
}

Blynk.run();
Client.loop();
}
Error is:

ESP32_TMR_RTC_PB1.ino.ino: In function ‘void loop()’:
ESP32_TMR_RTC_PB1.ino:231: error: expected primary-expression before ‘.’ token
ESP32_TMR_RTC_PB1.ino:232: error: expected unqualified-id before ‘.’ token
ESP32_TMR_RTC_PB1.ino:233: error: ‘reconnect’ was not declared in this scope
ESP32_TMR_RTC_PB1.ino:237: error: ‘setup_wifi’ was not declared in this scope
ESP32_TMR_RTC_PB1.ino:241: error: expected unqualified-id before ‘.’ token
expected primary-expression before ‘.’ token

No, feeling just fine thank you :wink: But if someone asks a basic question like “after driving awhile, my car stalls”… but only later clarifies that they ran out of gas… then it is entirely possible to initially feel they are asking the wrong question or in the wrong area. But since the OP has revealed more info that you are clearly aware of, please feel free to continue resolving the question. Thank you :+1:

You will need to add a “setup_wifi” function into your code.

Something like:

const char* ssid = "<your own>";
const char* password = "<your own>";

 void setup_wifi() {
      delay(10);
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
      }
    }
1 Like

Ignore this part in my code:

if (!Client.connected()) {
Client.disconnect();
reconnect();
}

That is for my MQTT connection that you will not need.

Thanks Mr Bobbo_SA for you hint, now it is working as I want after adding these:


void setup_wifi1() {
      delay(10);
      WiFi.begin(ssid, pass);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
      }
    }

 void setup_wifi() {
      delay(10);
      WiFi.begin(ssid, pass);
      if (WiFi.status() != WL_CONNECTED) {
         Blynk.disconnect();
        delay(1000);
      }
      else {
        Blynk.connected();

      }
    }

 timer.setInterval(9000L, setup_wifi);

 void reconnectBlynk() {
    if (!Blynk.connected()) {
      digitalWrite(17,LOW);
   delay (2000);
   digitalWrite (17,HIGH);
    if(Blynk.connect())  {
   
   BLYNK_LOG("Reconnected");}
   
   else{
    digitalWrite(17,HIGH);
      BLYNK_LOG("Not connected");
    }
    }
  }

void loop()
 
  
    {

 if (Blynk.connected()) {
    Blynk.run();}

1 Like

A post was split to a new topic: After rebooting the router, esp32 does not join back to the router