Blynk.begin enters endless loop

Hello everyone

I did a door security project to use rfid and esp8266 Nodemcu . My code is good working but i have a problem.

My problem:

If there is no internet connection and esp has just started, the code goes into an infinite loop within the Blynk.begin function. But if there is no connection, I want it to continue offline and only try to connect to the internet every 20 seconds.

My code:

void setup() {
  Serial.begin(9600);  // Seri haberleşmeyi başlatıyoruz.                                         
  SPI.begin();         // Spi haberleşme başlatıldı.                                       
  mfrc522.PCD_Init();  // Rfid modül başlatıldı.
  // röle,ledler,ve buton için giriş çıkış atandı.

  pinMode(relay,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(button,INPUT);
  Blynk.begin(auth,ssid,pass);  //Blynk başlatıldı.
}

i am so sorry for my bad english

@Musakucuk please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

#include <SPI.h>

#include <MFRC522.h>

#include <WiFiClient.h>

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

//***** KABLOSUZ AYARLARI ******* 

char auth[] = "auth";

const char* ssid = "wifiname";

const char* pass = "pass";

//*********IFTTT****************

const char* server = "maker.ifttt.com";

// Kişiye özel IFTTT Url'i

const char* resource = "/trigger/logger/with/key/auth";

//*********** RFID **************

#define RST_PIN         D8           

#define SS_PIN          D4          

#define relay           D3

#define button          D8

MFRC522 mfrc522(SS_PIN, RST_PIN);   

String readCardId = ""; // okunan kart idsi

String tempid = "";     // değişken kart idsi

//******** Led Pins and Button Pin *************

#define green           D1

#define red             D0

#define yellow          D2

unsigned long lastTime = 0;

unsigned long lastTime1 = 0;

unsigned long lastTime2 = 0;

unsigned long delayTime = 10000; 

unsigned long delayTime1 = 2000;  

unsigned long delayTime2 = 10000;

bool find = false;  

WiFiClient client;

//***** ANAHTAR LİSTESİ ***********

String Key_list[11][2] =          // Anahtar Listesi

  {

  {"name","cardid"},

  {"name","cardid"},

  {"name", "cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"},

  {"name","cardid"}

  };

// Google tablolar ile bağlantı sağlayan fonksiyon 

void connectGoogleSheets()

{

  int retries = 8;

  while(!!!client.connect(server, 80) && (retries-- > 0)) {

    Serial.print(".");

  }

} 

// IFTTT web servisine bir http isteği gönderir.

void makeIFTTTRequest(String name_surname,String kart_id,String durum) {

  digitalWrite(red,HIGH);

  Serial.print("Connecting to "); 

  Serial.print(server);

  

  int retries = 5;

  while(!!!client.connect(server, 80) && (retries-- > 0)) {

    Serial.print(".");

  }

  Serial.println();

  if(!!!client.connected()) {

    Serial.println("Failed to connect...");

  }

  

  Serial.print("Request resource: "); 

  Serial.println(resource);

  

  String jsonObject = String("{\"value1\":\"") + name_surname + "\",\"value2\":\"" + kart_id

                      + "\",\"value3\":\"" + durum + "\"}";

                                  

  client.println(String("POST ") + resource + " HTTP/1.1");

  client.println(String("Host: ") + server); 

  client.println("Connection: close\r\nContent-Type: application/json");

  client.print("Content-Length: ");

  client.println(jsonObject.length());

  client.println();

  client.println(jsonObject);

        

  int timeout = 5 * 10; // 5 seconds             

  while(!!!client.available() && (timeout-- > 0)){

    delay(100);

  }

  if(!!!client.available()) {

    Serial.println("No response...");

  }

  while(client.available()){

    Serial.write(client.read());

  }

  

  Serial.println("\nclosing connection");

  client.stop(); 

  digitalWrite(red,LOW);

}

String getID()  

{

  digitalWrite(green,HIGH);

  delay(200);

  readCardId = "";

  if(!mfrc522.PICC_IsNewCardPresent())

    {

      return "";

    }

    if(!mfrc522.PICC_ReadCardSerial())

    {

      return "";

    }

    for(int i = 0; i < mfrc522.uid.size;i++)

    {

      readCardId += String(mfrc522.uid.uidByte[i],HEX);

    }

    Serial.println(readCardId);

    digitalWrite(green,LOW);

    return readCardId;

}

void openDoor()   // Kapı aç metodu kapı otomatiğini 200 milisaniye açıyor ve kapatıyor.

{

  digitalWrite(relay,HIGH);

  delay(200);

  digitalWrite(relay,LOW);

}

void decision()   //Karar fonksiyonu ile gelen kart id'nin kararı verilir.

{

  

  for(int count=0;count<11;count++)

    {

      if(Key_list[count][1] == tempid)

      {

        digitalWrite(red,HIGH);

        digitalWrite(green,LOW);

        

        Serial.print(Key_list[count][0]);

       // Serial.println(" Adli kisi giris yapti.");

        openDoor();

        if(Blynk.connected()) makeIFTTTRequest(Key_list[count][0],Key_list[count][1],"Açıldı.");

        

        digitalWrite(red,LOW);

        digitalWrite(green,HIGH);

        tempid = "";

        break;

      }

    }

     if(tempid != "")

      {

        if(Blynk.connected()) makeIFTTTRequest("Bilinmeyen Kullanici",tempid,"Açılmadı.");

        digitalWrite(red,HIGH);

        delay(250);

        digitalWrite(red,LOW);

      }

}

BLYNK_WRITE(V2) 

{

  digitalWrite(green,LOW);

  int pinData = param.asInt(); 

  if(pinData == 1){

    openDoor();

    makeIFTTTRequest("Google Asistan","Kartız","Açıldı.");

  }

  digitalWrite(green,HIGH);

}

void setup() {

  Serial.begin(9600);  // Seri haberleşmeyi başlatıyoruz.                                         

  SPI.begin();         // Spi haberleşme başlatıldı.                                       

  mfrc522.PCD_Init();  // Rfid modül başlatıldı.

  

  // röle,ledler,ve buton için giriş çıkış atandı.

  pinMode(relay,OUTPUT);

  pinMode(green,OUTPUT);

  pinMode(red,OUTPUT);

  pinMode(yellow,OUTPUT);

  pinMode(button,INPUT);

  Blynk.begin(auth,ssid,pass);  //Blynk başlatıldı.

      

}

void loop() {

  unsigned long nowTime = millis(); 

  unsigned long nowTime1 = millis();

  unsigned long nowTime2 = millis();

  

  if (nowTime - lastTime >= delayTime) 

  {

    lastTime = nowTime;    

    if(WiFi.status() != WL_CONNECTED) digitalWrite(yellow,LOW);

    else digitalWrite(yellow,HIGH);

  }

  if(nowTime1 - lastTime1 >= delayTime1)

  {

    lastTime1 = nowTime1;

    if(digitalRead(button) == true){

      digitalWrite(red,HIGH);

      Blynk.notify("Bina içersindeki kapıdan bir kişi kapı açma isteği gönderdi."); 

    }

    else digitalWrite(red,LOW);

  }

  if(nowTime2 - lastTime2 >= delayTime2)  // 30 dakikada bir google tablolar ile bağlantı sağlanıyor.

  {

    lastTime2 = nowTime2;

    connectGoogleSheets();

  }

  

  tempid = getID(); //kart üzerinde okunan kart id tempid değişkenine atılır.

  decision();  // karar metodu ile kapının açılıp açılmayacağı kararı verilir.

  

  Blynk.run();
}

My full codes

Blynk.begin is a blocking function.
If it can’t establish a WiFi connection or a connection to the Blynk server then it will block all code execution beyond that point.

The solution is to change your sketch so that you manage your own WiFi connection, then use Blynk.config and Blynk.connect to try to establish the Blynk connection. if either of these connections cannot be established then you continue in “standalone” mode and probably re-try the WiFi, and if successful the Blynk connections, after a a suitable amount of time has passed.

If you search the forum for Blynk.config you will see this issue discussed in detail.

Also, I’d recommend that you try to clean your void loop up as much as possible. I realise that this is difficult when using RFID readers, but you should at least be using a timer rather than doing all of the millis comparisons.

Pete.

Thank you very much for your response, Pete.
But the Blynk.config topics in the forum are very complex. I wonder if there is a quick source where I can reach results

Hello in the void setup replace Blynk.begin with

Blynk.config (wifi, auth);
Blynk.connectWiFi (ssid, pass);

in this way it does not block