Blynk.connect(timeout)
does not work correctly when the Internet connection is broken - the real timeout is always approximately 18 seconds.
Blynk.connect(timeout)
works correctly - real timeout is set - when the wifi connection is broken.
But with a good Wi-Fi connection, but a broken Internet connection, the timeout does not match the setting, my measurements always show about 18 seconds, although the setting is 3 seconds.
It is very important for me that when the Internet connection is broken, my controller is not blocked, but continues to perform important functions, except for Blynk.
In fact, it turns out that if the Wi-Fi connection is working, but there is no Internet, then the controller is blocked for 18 seconds., every time I try to connect to the server…
If you want all the code, here it is:
#define BLYNK_TEMPLATE_ID "--"
#define BLYNK_DEVICE_NAME "--"
#define BLYNK_AUTH_TOKEN "--"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer; // timer for Blynk Connection Function
bool WiFiok = false; // connection wifi
bool BlynkCon = false; // connection Blynk
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "--";
char pass[] = "--";
void setup()
{
Serial.begin(9600);
WiFi.begin(ssid, pass);
Blynk.config(auth);
timer.setInterval(35 * 1000, BlynkConFunction);// connection to the server - period 35 sec
}
void loop()
{
timer.run();
if (BlynkCon) {
Blynk.run();
}
}
void BlynkConFunction() // Blynk Connection Function
{
if (WiFi.status() == WL_CONNECTED) {
WiFiok = true;
Serial.println("Wifi_OK");
if (!Blynk.connected()) {
Serial.println("Connecting_to_Blynk...");
BlynkCon = Blynk.connect(5000);
Serial.println("Connecting_attempt_ended.");
if (BlynkCon) {
Serial.println("Blynk_connected");
}
else {
Serial.println("Blynk_FAIL");
}
}
else {
Serial.println("Blynk_OK");
}
}
else {
WiFiok = false;
BlynkCon = false;
Serial.println("Wifi_FAIL");
}
}