I want to share my decision. I use this code if, for example, I take the device from home to work where there are different wi-fi networks, or if I want to connect on the street, I simply distribute wi-fi from a mobile access point on my phone.
Please note that if none of the listed networks is still connected, the program will still work offline, unlike the standard Blynk.begin (auth, ssid, pass);
If there is a solution easier and more interesting I will be glad to discuss.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "your_token";
char* ssid[] = {"ssid_1","ssid_2","ssid_Mobil"}; //list a necessary wifi networks
char* pass[] = {"pass_1","pass_2","pass_Mobil"}; //list a passwords
void setup()
{
Serial.begin(9600);
MultyWiFiBlynkBegin(); //instead Blynk.begin(auth, ssid, pass);
}
void MultyWiFiBlynkBegin() {
int ssid_count=0;
int ssid_mas_size = sizeof(ssid) / sizeof(ssid[0]);
do {
Serial.println("Trying to connect to wi-fi " + String(ssid[ssid_count]));
WiFi.begin(ssid[ssid_count], pass[ssid_count]);
int WiFi_timeout_count=0;
while (WiFi.status() != WL_CONNECTED && WiFi_timeout_count<50) { //waiting 10 sec
delay(200);
Serial.print(".");
++WiFi_timeout_count;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Connected to WiFi! Now I will check the connection to the Blynk server");
Blynk.config(auth);
Blynk.connect(5000); //waiting 5 sec
}
++ssid_count;
}
while (!Blynk.connected() && ssid_count<ssid_mas_size);
if (!Blynk.connected() && ssid_count==ssid_mas_size) {
Serial.println("I could not connect to blynk =( Ignore and move on. but still I will try to connect to wi-fi " + String(ssid[ssid_count-1]));
}
}
void loop()
{
Blynk.run();
}
То же самое на родном русском языке. Код для проверки и подключению к нескольким wi-fi сетям. Я использую этот код, если устройство к примеру уношу из дома на работу где разные wi-fi сети, или если хочу подключиться на улице просто раздаю wi-fi с мобильной точки доступа на своем телефоне.
Обратите внимание, что если ни одна из перечисленных сетей все таки не будет подключена, программа все равно будет работать в офлайн, в отличии от стандартного Blynk.begin(auth, ssid, pass);