Hi guys! I wrote recently about a blink reconnection error when the internet connection lost and resume.
https://community.blynk.cc/t/esp8266-and-blynk-reconnect/44536
Now I maked simple sketch to localize problem.
We have esp8266 (Wemos D1 mini), only board is connected to usb.
Code:
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <WiFiClient.h>
BlynkTimer mainTimer;
char ssid[] = "xxx";
char password[] = "xxx";
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_AP_STA);
IPAddress staticIPAP(192, 168, 4, 30);
IPAddress staticIP(192, 168, 0, 30);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 0, 1);
WiFi.softAP("UberDevice", "xxx");
WiFi.softAPConfig(staticIPAP, gateway, subnet);
Serial.print("Soft-AP IP address: ");
Serial.println(WiFi.softAPIP());
Serial.printf("SoftAP MAC address: %s\n", WiFi.softAPmacAddress().c_str());
WiFi.config(staticIP, gateway, subnet);
WiFi.begin(ssid, password);
Serial.printf("Connecting to: %s\n", ssid);
// Wait for connection
int iWaitWifi = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (++iWaitWifi > 50) {
//Serial.println("Error connection to Wifi %s", ssid);
break;
}
}
Serial.println("");
if (WiFi.status() == WL_CONNECTED) {
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("Not connected to Wifi!");
}
char auth[] = "xxx";
Blynk.config(auth, "139.59.206.133", 8080);
if (Blynk.connect())
Serial.println("Blynk ESP8288 connected.");
else
Serial.println("Blynk NOT connected!!");
mainTimer.setInterval(3000, ProcessTimer);
}
void ProcessTimer()
{
if (WiFi.status() != WL_CONNECTED)
Serial.println("Wifi NOT connected!");
CheckConnections();
}
int iBlynkRF = 0;
void CheckConnections()
{
if (!Blynk.connected()) {
//try reconnect every 10-th timer iteration
if(iBlynkRF++ < 10)
return;
iBlynkRF = 0;
Serial.println("Blynk NOT connected. Trying to reconnect...");
if (Blynk.connect())
Serial.println("Blynk reconnected.");
else
Serial.println("Blynk reconnection error!");
}
else{
Serial.println("Blynk connected.");
iBlynkRF = 0;
}
}
void loop()
{
if(Blynk.connected())
Blynk.run();
mainTimer.run();
}
Output:
Blynk connected.
Blynk connected.
Blynk connected.
Blynk connected.
Blynk connected.
Blynk connected. ****************************Here I disable Internet on router
Wifi NOT connected!
Wifi NOT connected!
Blynk NOT connected. Trying to reconnectâŚ
[202487] Connecting to 139.59.206.133:8080
[207488] Connecting to 139.59.206.133:8080
Blynk reconnection error!
Blynk NOT connected. Trying to reconnectâŚ
[238487] Connecting to 139.59.206.133:8080
[243488] Connecting to 139.59.206.133:8080
Blynk reconnection error! ****************************Here enable it again
Blynk NOT connected. Trying to reconnectâŚ
[274487] Connecting to 139.59.206.133:8080
[279488] Connecting to 139.59.206.133:8080
Blynk reconnection error!
Blynk NOT connected. Trying to reconnectâŚ
[310487] Connecting to 139.59.206.133:8080
[315488] Connecting to 139.59.206.133:8080
Blynk reconnection error!
Blynk NOT connected. Trying to reconnectâŚ
[346487] Connecting to 139.59.206.133:8080
[351488] Connecting to 139.59.206.133:8080
Blynk reconnection error!
PS. After I enable connection on the router again all other devices were successfully connected.
PPS. Please note that WiFi in AP and Sta mode, but this issue is appear also in Sta mode.