At first i want to thanks the God because he is inspired me to fix this very difficult issue i was facing with my project, and i want to thanks Gunner because he is encouraged me to keep going and fix this issue.
Let’s start:
We know there are my projects facing problems with router interruptions specially when they use ESP8266 as Shield on Arduino. Now i want you to knew there are three interruptions we will counter and all these interruptions will stop your project completely and it was there is no way to get your project reconnect with your router, but a week ago i was able to fix and remove all these interruptions and make your project keep reset by himself until it get connect with your router when your router be ready to connect. Let’s talk about these interruptions and who we will solve them, also all this interruptions will happen at same time:
1 - This one we will face it when your project already connected with your router also with your blynk App, at this time if any interruption will happen with your router that will lead your project to stop completely and no way to reconnect again, so now to fix this problem we need to add this library on your sketch #include <avr/wdt.h> with timer to check if your project still connecting with your blynk, that will be timer.setInterval(6000L, checkBlynk); inside viod setup and you will need conditional statement code to check:
void checkBlynk(){
if(!Blynk.connected()){
Serial.println("Not connected to Blynk server");
wdt_enable(WDTO_1S);
}
}
2 - After first interruption we will face the second one, that will happen because when the first reset happened your monitor screen will stop with “Failed to connect WiFi” because your router at this time will not be ready to let any device connect with it, and it need time and that time different from router to router, so was my idea to keep the ESP8266 resetting until my router be ready then it will reconnect automatically. my solution is by update the BlynkSimpleShieldEsp8266.h library through add #include <avr/wdt.h> library inside the BlynkSimpleShieldEsp8266.h library. and add wdt_enable(WDTO_1S); to these lines as shown:
bool connectWiFi(const char* ssid, const char* pass)
{
::delay(500);
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
/*if (!wifi->restart()) {
BLYNK_LOG1(BLYNK_F("Failed to restart"));
return false;
}*/
if (!wifi->kick()) {
BLYNK_LOG1(BLYNK_F("ESP is not responding"));
wdt_enable(WDTO_1S);
//TODO: BLYNK_LOG_TROUBLE(BLYNK_F("esp8266-not-responding"));
return false;
}
if (!wifi->setEcho(0)) {
BLYNK_LOG1(BLYNK_F("Failed to disable Echo"));
return false;
}
String ver = wifi->ESP8266::getVersion();
BLYNK_LOG1(ver);
if (!wifi->enableMUX()) {
BLYNK_LOG1(BLYNK_F("Failed to enable MUX"));
}
if (!wifi->setOprToStation()) {
BLYNK_LOG1(BLYNK_F("Failed to set STA mode"));
return false;
}
if (wifi->joinAP(ssid, pass)) {
String my_ip = wifi->getLocalIP();
BLYNK_LOG1(my_ip);
} else {
BLYNK_LOG1(BLYNK_F("Failed to connect WiFi"));
wdt_enable(WDTO_1S);
return false;
3 - sometime you will get this message “ESP is not responding” and this will stop your device from reconnecting or reset himself, so I add wdt_enable(WDTO_1S); to this line inside the BlynkSimpleShieldEsp8266.h
if (!wifi->kick()) {
BLYNK_LOG1(BLYNK_F("ESP is not responding"));
wdt_enable(WDTO_1S);
Finally i want to ask the blynk manager or coder to do permanently update for his BlynkSimpleShieldEsp8266.h library with last two point to make these issues fix forever for any user and they will not need to go again with these issues.