Code isn't working without connected Blynk

Looks like I’ve solved the problem using this code:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "auth";
const char* ssid = "ssid";
const char* password = "pass";

void setup()
{
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  Blynk.config(auth);
  if (WiFi.status() == WL_CONNECTED) {
    Blynk.connect(5);
  }
}

void loop()
{
  if (WiFi.status() == WL_CONNECTED) {
    if (Blynk.connected() == true) {
      Blynk.run();
    }
    else {
      Blynk.connect(5);
      Blynk.run();
    }
  }
}

It connects longer than usual if anything is working, but connecting and syncing. If I deny ESP8266 connecting to AP, my code is working after 10 seconds approx. If I’ll allow — it reconnects and works again.
My code working from the start, if I reboot ESP8266, no more pauses on Blynk connecting.

The code needs polishing, though.

2 Likes