Avoiding continous connection to Blynk when router has no internet connection

Hello Blynk Community!

My question is - how I can avoid continuous Blynk connection when my router is offline. My NodeMCU module connects to WiFi, but sometimes my routers hasn’t got internet connection. What I have to do?

Thanks a lot!

Here is a sample code:

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, pass);
  int wifi_ctr = 0;
  while (WiFi.status() != WL_CONNECTED && attemps > 0) {
    delay(500);
    Serial.print(".");
    Serial.println(attemps);
    attemps--;
  }
  if (attemps <= 0) {
    Serial.println(F("Ops! Connection timeout :( Going sleep..."));
    ESP.deepSleep(10e6); // 10s
  }

  Blynk.begin(auth, ssid, pass, ipAddress, port);
}

Blynk.begin is a blocking function - your code will never progress beyond that line of code if a connection to the Blynk server can’t be established.

You should use Blynk.config and Blynk.connect
More info here:

Pete.