For my Mega and ESP-01, I use the following… It may not be perfect, but it works (I think I got it all here… … very tired )
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
//char server[] = "xxx.xxx.xxx.xxx"; // For Local Server
//Blynk.begin(auth, wifi, ssid, pass, server, 8442); // For Local Server
Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442); // For Cloud Server
BLYNK_CONNECTED() {
Blynk.syncAll(); // runs whenever Blynk reconnects to server.
}
void loop()
{
timer.run();
if (Blynk.connected()) {
Blynk.run();
} else { // if not connected
reconnectBlynk();
}
}
void reconnectBlynk() {
Blynk.connect(60); // reconnect to server
if (Blynk.connected()) {
} else {
softReset(); // Should? work with most Arduinos.
}
}
void softReset() {
asm volatile (" jmp 0"); // resets Arduino
}
I also tie my Arduino reset pin to the ESP reset… not sure how much that is required… but I do it.