Blynk disconnects after one minute

Hi guys. The code is working properly, but after a minute Blynk app disconnects. The board continues working properly but for a connection to blynk I need to reboot.
Here is the code:
The board is Nodemcu

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "c81ada48e1xxcccccccccccccccxxx";
char ssid[] = "xxxxx"; 
char pass[] = "xxxxxxxxxx";

BlynkTimer timer;
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 2
#define RST_PIN 4
#define LED_G 15 //define green LED pin
#define LED_R 3 //define red LED
#define BUZZER 0 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name



void setup() 
{
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(5); //servo pin
  myServo.write(45); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();

}
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "XX XX XX XX" || content.substring(1) == "XX XX XX XX") 
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(135);
    delay(2000);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
    Blynk.virtualWrite(V1, HIGH);
    delay(2000);
    Blynk.virtualWrite(V1, LOW);
  }
 
 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
    Blynk.virtualWrite(V3, HIGH);
    delay(2000);
    Blynk.virtualWrite(V3, LOW);    
  }
 Blynk.run();
 timer.run();  
}


Pete.

So, you mean that I have to leave only blynk.run and timer.run in the loop? But how to configure the code to run continuesly running out of the loop function?

Should it looks like this:

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "c81ada48e1xxcccccccccccccccxxx";
char ssid[] = "xxxxx"; 
char pass[] = "xxxxxxxxxx";

BlynkTimer timer;
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 2
#define RST_PIN 4
#define LED_G 15 //define green LED pin
#define LED_R 3 //define red LED
#define BUZZER 0 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name



void setup() 
{
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(5); //servo pin
  myServo.write(45); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();

}

void repeatMe() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "8B 48 56 D3" || content.substring(1) == "71 15 84 08") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(135);
    delay(2000);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
    Blynk.virtualWrite(V1, HIGH);
    delay(2000);
    Blynk.virtualWrite(V1, LOW);
  }
 
 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
    Blynk.virtualWrite(V3, HIGH);
    delay(2000);
    Blynk.virtualWrite(V3, LOW);    

  }
timerId = timer.setInterval(1000, repeatMe);

void Loop()
{
 Blynk.run();
 timer.run();  
}

It depends if that code configuration works with your hardware and the library you are using. You’re calling the timer that looks for an RFID tag once every second, which may make the system seem sluggish, but you’ll need to experiment.

If possible, you’d be better using an interrupt driven RFID library for your RFID system, if one is available. This type of library doesn’t need constant checking to see if an RFID tag had been presented to the reader.

You will also find that the delays in the code will cause problems. You should use timeout timers there instead of delay(). Look at the coding examples from @Gunner if you don’t know how to do this.

Pete.

Thanks for the advises, Pete.