In reference to both your topics about these libraries… This is part of your issue…
The ESP8266 in your case is ONLY acting as a Serial to WiFi transceiver (AKA as Shield), thus it uses different libraries and has different functions then a full standalone ESP8266.
I also use a Mega with ESP as shield… and am able to run without Blynk connection via this code…
This is for an auto reconnection routine…
#include <WiFi.h>
#include <ESP8266_Lib.h> // ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h> // ESP-01 Link
void setup() {
// stuff...
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();
}
// stuff...
}
void loop() {
timer.run();
if (Blynk.connected()) { // If connected run as normal
Blynk.run();
} else if (ReCnctFlag == 0) { // If NOT connected and not already tring to reconnect, set timer to try to reconnect in 30 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
ReCnctCount++; // Increment reconnection Counter
Serial.print("Attempting reconnection #");
Serial.println(ReCnctCount);
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
}
}
This is NOT drop in code… you will need to examine it and extrapolate what you need for your own projects…