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

Esp8266 reconnection

#1

I want to report an issue that I have faced
There is one problem in blynk library
I am using esp8266 as shield on Arduino pro mini
The problem is that
If somehow my WiFi disconnect or my esp8266 modules resets then it is not automatically connected back to WiFi
The only way to make it connect back is by resetting Arduino
This problem should be fixed
I think the library should check if the esp8266 is. Connected to WiFi or not and then send the commands or communicate
Or there should be a command which one can put in his code to establish a connection to WiFi and server when the command is called

0 Likes

#2

It is already… use the non-blocking Blynk.config() and your own WiFi setup.

It is not as seamless when using a ESP as shield, but that is due the nature of the shield use (as the ESP becomes a simple Serial to WiFi transceiver, then not directly programmable), not really a Blynk issue.

http://docs.blynk.cc/#blynk-firmware-configuration-blynkconfig

Many topics and examples already exist in this forum about how to use devices, with or without internet.

For example (again, primarily for ESP standalone, but try it with your arduino and see)…

I use similar connection with my Mega and ESP-01 as shield…

  wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
  Blynk.config(wifi, auth, server, port);
  if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
  }
void loop() {
  timer.run();

  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and not already trying to reconnect, set timer to try to reconnect in 60 seconds
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
      Blynk.config(wifi, auth, server, port);
      Blynk.connect();  // Try to reconnect to the server
      if (Blynk.connectWiFi(ssid, pass)) {
        Blynk.connect();
      }
    });  // END Timer Function
  }
}
0 Likes