Invalid token in Blynk 2.0

#define BLYNK_TEMPLATE_ID "TMPLFcXvLUyH"
#define BLYNK_TEMPLATE_NAME "Cửa thông minh"
#define BLYNK_PRINT Serial


#include <Wire.h>   //thu vien giao tiep i2c
#include <LiquidCrystal_I2C.h> //thu vien lcd
#include <Adafruit_Fingerprint.h> //thu vien van tay
#include <Keypad.h> //thu vien ban phim
#include <EEPROM.h> //tu vien cho eeprom
#include <SPI.h> //thu vien giao tiep spi
#include <MFRC522.h> //thu vien mfrc522
#include <WiFi.h> 
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h> //thu vien cho blynk

#define RELAY   32
#define BUZZ    33
#define BUTTON  34
#define RST_PIN 4
#define SS_PIN  5

#define MODE_FIRST_FINGER 1
#define MODE_SECOND_FINGER 2
#define MODE_ID_FINGER_ADD 3
#define MODE_ID_FINGER_CLEAR 4

#define NOT_OK  0
#define OK      1
#define SOS     2

char auth[] = "Bhes-KHpZUo8GP6J3JOgDDXcgAbIvjo8"; // ma xac nhan tk blynk
char ssid[] = "HaThanh"; // ten wifi
char pass[] = "12345678"; // mat khau wifi

char password[6] = "12345"; // mat khau 
char mode_changePass[6] = "*090#"; // doi mat khau
char mode_addFinger[6] = "*101#"; // them van tay
char mode_delFinger[6] = "*102#"; // xoa van tay
char confirm_access[6] = "*900#"; //mat khau master

String name_wifi;
String pass_wifi;
String newpass;
int leng_name = 0;
int leng_pass = 0;
char c_name_wifi[20];
char c_pass_wifi[20];

int id = 0;
int error_in = 0;
char p = FINGERPRINT_PACKETRECIEVEERR;
unsigned char MODE = MODE_ID_FINGER_ADD;

int rfid_fail_card = 0;
char incomingByte;
String inputString;
unsigned char index_t = 0;
int count = 0;
bool is_connected = true;
bool is_add_finger = false;
bool is_change_pass = false;
bool connect_first_time = true;

bool is_data_ok = false;
const byte ROWS = 4;
const byte COLS = 3;

char hexaKeys[ROWS][COLS] = {
  {'0', '#', '*'},
  {'8', '9', '7'},
  {'5', '6', '4'},
  {'2', '3', '1'}
};
byte rowPins[ROWS] = {25, 26, 27, 14};
byte colPins[COLS] = {12, 13, 15};

unsigned long time_run = 0;
char data_input[6];
char new_pass1[6];
char new_pass2[6];
unsigned char in_num = 0, error_pass = 0, error_finger = 0;
int config_wifi = 0;

MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

BLYNK_WRITE(V0)
{
  int blynk_open_door = param.asInt();
  if (blynk_open_door) {
    index_t = 3;
  }
}

BLYNK_WRITE(V1)
{
  int blynk_add_finger = param.asInt();
  if (blynk_add_finger) {
    index_t = 6;
    is_add_finger = true;
  }
}

BLYNK_WRITE(V2)
{
  int blynk_del_finger = param.asInt();
  if (blynk_del_finger) {
    index_t = 6;
    is_add_finger = false;
  }
}

BLYNK_WRITE(V3)
{
  config_wifi = param.asInt();
}

BLYNK_WRITE(V4)
{
  name_wifi = param.asStr();
  Serial.println(name_wifi);
}

BLYNK_WRITE(V5)
{
  pass_wifi = param.asStr();
  Serial.println(pass_wifi);
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  EEPROM.begin(512);
  pinMode(RELAY, OUTPUT);
  pinMode(BUZZ, OUTPUT);
  pinMode(BUTTON, INPUT);
  digitalWrite(RELAY, HIGH);
  digitalWrite(BUZZ, LOW);
  finger.begin(57600);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    finger.begin(57600);
    Serial.println("Don't find fingerprint sensor!");
  }
  //writeEpprom(password);
  lcd.begin();
  lcd.backlight();
  lcd.print("  SYSTEM INIT   ");
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println(F(": "));
  mfrc522.PCD_DumpVersionToSerial();
  readEpprom();
  leng_name = EEPROM.read(40) - 48;
  leng_pass = EEPROM.read(41) - 48;
  readEeprom(leng_name, 10, c_name_wifi);
  readEeprom(leng_pass, 30, c_pass_wifi);
  Serial.println("c_name_wifi = " + String(c_name_wifi));
  Serial.println("c_pass_wifi = " + String(c_pass_wifi));
  WiFi.begin(c_name_wifi, c_pass_wifi);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    count++;
    if (count == 20) {
      connect_first_time = false;
      Serial.println("");
      Serial.println("Connect wifi " + String(c_name_wifi) + " fail");
      Serial.println("Reconnect with wifi " + String(ssid));
      WiFi.begin(ssid, pass);
    } else if (count >= 40) {
      lcd.clear();
      lcd.print(" INIT WIFI FAIL ");
      is_connected = false;
      break;
    }
  }
  Serial.println("");
  if(connect_first_time){
    if (c_name_wifi != NULL && c_pass_wifi != NULL) {
      sprintf(ssid, "%s", c_name_wifi);
      sprintf(pass, "%s", c_pass_wifi);
    }
    connect_first_time = false;
  }
  if (is_connected) {
    Blynk.begin(auth, ssid, pass);
    Blynk.virtualWrite(V0, LOW);
    Blynk.virtualWrite(V1, LOW);
    Blynk.virtualWrite(V2, LOW);
    Blynk.virtualWrite(V3, LOW);
    lcd.clear();
    lcd.print(" INIT WIFI DONE ");
  }
  //lcd.print("   INIT DONE!   ");
  delay(3000);
  time_run = millis();
  lcd.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  if (is_connected) {
    if ((unsigned long) (millis() - time_run) > 1000) {
      Blynk.run();
      time_run = millis();
    }
  }
  lcd.setCursor(0, 0);
  lcd.print(" Enter Password ");
  read_button();
  checkPass();
  rfid_card();
  getWifi();
  checkFingerPrinter();
  while (index_t == 1)
  {
    changePass();
  }
  while (index_t == 3)
  {
    openDoor();
    error_pass = 0;
    rfid_fail_card = 0;
    error_finger = 0;
  }
  while (index_t == 6)
  {
    confirm_pass();
  }
  while (index_t == 7)
  {
    addFingerPrinter();
  }
  while (index_t == 8)
  {
    delFingerID();
  }
  if (index_t == 2)
  {
    error();
  }
  else if (index_t == 4)
  {
    sos_screen();
    error_pass = 0;
    rfid_fail_card = 0;
    error_finger = 0;
  }
  else if (index_t == 5)
  {
    lcd_wrong_card();
  }
  else if (index_t == 9)
  {
    lcd_finger_wrong();
  }
}

void checkFingerPrinter()
{
  p = finger.getImage();
  if (p == FINGERPRINT_OK)
  {
    p = finger.image2Tz();
    if (p == FINGERPRINT_OK)
    {
      p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK)
      {
        Serial.print(finger.fingerID);
        index_t = 3;
        error_finger = 0;
      }
      else
      {
        if (error_finger == 2) {
          index_t = 4;
        } else {
          index_t = 9;
          error_finger++;
        }
      }
    }
  }
}

void delFingerID() {
  if (is_connected) {
    Blynk.run();
    Blynk.virtualWrite(V2, LOW);
  }
  lcd.setCursor(1, 0);
  lcd.print("Delete Finger");
  lcd.setCursor(6, 1);
  lcd.print("ID:");
  id = numberInput();
  //lcd.print(id);
  delay(3000);
  p = finger.deleteModel(id); // ham xoa van tay theo id
  if (p == FINGERPRINT_OK) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("Delete Success");
    delay(3000);
  } else {
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("Delete Error");
    delay(3000);
  }
  index_t = 0;
  lcd.clear();
}

void addFingerPrinter()
{
  if (is_connected) {
    Blynk.run();
    Blynk.virtualWrite(V1, LOW);
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("ADD NEW FINGERPRINT");
  //delay(2000);
  switch (MODE) {
    case (MODE_ID_FINGER_ADD):
      Serial.println("ADD_IN");
      lcd.setCursor(0, 1);
      lcd.print("Input Id: ");
      id = numberInput();
      if (id == 0) {// ID #0 not allowed, try again!
        lcd.setCursor(3, 1);
        lcd.print("ID ERROR");
        break;
      }
      delay(2000);
      MODE = MODE_FIRST_FINGER;
      break;
    case (MODE_FIRST_FINGER):
      lcd.setCursor(0, 1);
      lcd.print("   Put Finger    ");
      p = finger.getImage();
      if (p == FINGERPRINT_OK)
      {
        p = finger.image2Tz(1);
        if (p == FINGERPRINT_OK)
        {
          lcd.setCursor(0, 1);
          lcd.print("   Put Again    ");
          delay(500);
          MODE = MODE_SECOND_FINGER;
        }
      }
      if (p == FINGERPRINT_NOFINGER)
      {
        Serial.println("==========> No finger ");
        delay(100);
      }
      if (p == FINGERPRINT_PACKETRECIEVEERR)
      {
        lcd.setCursor(0, 1);
        lcd.print("Communication error");
        delay(1000);
      }
      break;
    case MODE_SECOND_FINGER:
      p = finger.getImage();
      if (p == FINGERPRINT_OK)
      {
        p = finger.image2Tz(2);
        if (p == FINGERPRINT_OK)
        {
          p = finger.createModel();
          if (p == FINGERPRINT_OK)
          {
            p = finger.storeModel(id);
            if (p == FINGERPRINT_OK)
            {
              Serial.println("OK");
              lcd.setCursor(0, 1);
              lcd.print("Add Finger Done");
              delay(2000);
              index_t = 0;
              Serial.println("ADD_OUT");
              lcd.clear();
              MODE = MODE_ID_FINGER_ADD;
            }
          }
          else if (p == FINGERPRINT_ENROLLMISMATCH)
          {
            lcd.setCursor(0, 1);
            lcd.print("   Mismatched   ");
            //
            if (error_in == 2)
            {
              index_t = 0;
              Serial.println("ADD_OUT");
              MODE = MODE_SECOND_FINGER;
            }
            error_in++;
            delay(2000);
            lcd.clear();
            MODE = MODE_SECOND_FINGER;
          }
          else
          {

          }
          id = 0;
        }
      }
      break;
  }
}

unsigned char numberInput() {
  char number[5];
  char count_i = 0;
  while (count_i < 2) {
    char key = keypad.getKey();
    if (key && key != 'A' && key != 'B' && key != 'C' && key != 'D' && key != '*' && key != '#' ) {
      lcd.setCursor(10 + count_i, 1);
      lcd.print(key);
      number[count_i] = key;
      count_i++;
    }
  }
  return (number[0] - '0') * 10 + (number[1] - '0');
}

unsigned char isBufferdata(char data[]) //Kiem tra buffer da co gia tri chua
{
  unsigned char i = 0;
  for (i = 0; i < 5 ; i++)
  {
    if (data[i] == '\0')
    {
      return 0;
    }
  }
  return 1;
}

bool compareData(char data1[], char data2[]) //Kiem tra 2 cai buffer co giong nhau hay khong
{
  unsigned char i = 0;
  for (i = 0; i < 5; i++)
  {
    if (data1[i] != data2[i])
    {
      return false;
    }
  }
  return true;
}

void insertData(char data1[], char data2[]) //Gan buffer 2 cho buffer 1
{
  unsigned char i = 0;
  for (i = 0; i < 5; i++)
  {
    data1[i] = data2[i];
  }
}

void getData()
{
  char key = keypad.getKey();
  if (key)
  {
    Serial.println(key);
    if (in_num == 0)
    {
      data_input[0] = key;
      lcd.setCursor(5, 1);
      lcd.print("*");
    }
    if (in_num == 1) {
      data_input[1] = key;
      lcd.setCursor(6, 1);
      lcd.print("*");
    }
    if (in_num == 2) {
      data_input[2] = key;
      lcd.setCursor(7, 1);
      lcd.print("*");
    }
    if (in_num == 3) {
      data_input[3] = key;
      lcd.setCursor(8, 1);
      lcd.print("*");
    }
    if (in_num == 4) {
      data_input[4] = key;
      lcd.setCursor(9, 1);
      lcd.print("*");
    }
    if (in_num == 4)
    {
      in_num = 0;
    }
    else {
      in_num ++;
    }
  }
}

void checkPass()
{
  getData();
  if (isBufferdata(data_input))
  {
    if (compareData(data_input, password))
    {
      lcd.clear();
      clear_data_input();
      Serial.println("pass");
      index_t = 3;
    }
    else if (compareData(data_input, mode_changePass))
    {
      lcd.clear();
      clear_data_input();
      index_t = 6;
      is_change_pass = true;
    }
    else if (compareData(data_input, mode_addFinger))
    {
      lcd.clear();
      clear_data_input();
      index_t = 6;
      is_add_finger = true;
    }
    else if (compareData(data_input, mode_delFinger))
    {
      lcd.clear();
      clear_data_input();
      index_t = 6;
      is_add_finger = false;
    }
    else
    {
      index_t = 2;
      clear_data_input();
      error_pass++;
      if (error_pass == 3)
      {
        clear_data_input();
        index_t = 4;
      }
    }
  }
}

void clear_data_input()
{
  int i = 0;
  for (i = 0; i < 6; i++)
  {
    data_input[i] = '\0';
  }
}

void changePass() //Thay doi pass
{
  lcd.setCursor(0, 0);
  lcd.print("-- Change Pass --");
  delay(2000);
  lcd.setCursor(0, 0);
  lcd.print("--- New Pass ---");
  while (1)
  {
    if (is_connected) Blynk.run();
    getData();
    if (isBufferdata(data_input))
    {
      insertData(new_pass1, data_input);
      clear_data_input();
      break;
    }
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("---- AGAIN ----");
  while (1)
  {
    if (is_connected) Blynk.run();
    getData();
    if (isBufferdata(data_input))
    {
      insertData(new_pass2, data_input);
      clear_data_input();
      break;
    }
  }
  delay(1000);
  if (compareData(new_pass1, new_pass2))
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("--- Success ---");
    delay(1000);
    writeEpprom(new_pass2);
    insertData(password, new_pass2);
    lcd.clear();
    index_t = 0;
  }
  else
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("-- Mismatched --");
    delay(1000);
    lcd.clear();
    index_t = 0;
  }
}

void confirm_pass() {
  lcd.setCursor(0, 0);
  lcd.print(" Confirm Access ");
  while (1)
  {
    if (is_connected) Blynk.run();
    getData();
    if (isBufferdata(data_input))
    {
      if (compareData(data_input, password)) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(" Accept Access  ");
        delay(1000);
        lcd.clear();
        if (is_change_pass){
          index_t = 1;
          is_change_pass = false;
        }
        else if (is_add_finger) index_t = 7;
        else index_t = 8;
        is_add_finger = false;
      }
      else {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(" Access denied  ");
        delay(1000);
        lcd.clear();
        index_t = 0;
      }
      clear_data_input();
      if (is_connected) {
        Blynk.virtualWrite(V1, LOW);
        Blynk.virtualWrite(V2, LOW);
      }
      break;
    }
  }
  is_add_finger = false;
}

void writeEpprom(char data[])
{
  unsigned char i = 0;
  for (i = 0; i < 5; i++)
  {
    EEPROM.write(i, data[i]);
  }
  EEPROM.commit();
}

void readEpprom()
{
  unsigned char i = 0;
  for (i = 0; i < 5; i++)
  {
    password[i] = EEPROM.read(i);
  }
}

void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}

void get_UID(String content) {
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  content.toUpperCase();
  if (content.substring(1) == "F0 E7 D1 1F")
  {
    Serial.println("rfid");
    openDoor();
    rfid_fail_card = 0;
  }
  else   {
    index_t = 5;
    rfid_fail_card++;
    if (rfid_fail_card == 3) {
      index_t = 4;
    }
  }
}

void rfid_card() {
  if ( ! mfrc522.PICC_IsNewCardPresent())
    return;

  if ( ! mfrc522.PICC_ReadCardSerial())
    return;

  Serial.print(F("Card UID:"));
  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println();

  MFRC522::StatusCode status;

  String content = "";
  get_UID(content);

  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
}

void openDoor()
{
  lcd.setCursor(0, 0);
  lcd.print("-OPEN THE DOOR-");
  digitalWrite(RELAY, LOW);
  if (is_connected) Blynk.virtualWrite(V0, LOW);
  notify_mode(OK);
  delay(5000);
  digitalWrite(RELAY, HIGH);
  lcd.clear();
  index_t = 0;
}

void error()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("     ERROR    ");
  notify_mode(NOT_OK);
  delay(3000);
  index_t = 0;
  lcd.clear();
}

void sos_screen() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("    Canh bao    ");
  lcd.setCursor(0, 1);
  lcd.print("co tinh xam pham");
  if (is_connected) Blynk.logEvent("warning", "Canh bao co tinh xam pham");
  notify_mode(SOS);
  delay(10000);
  lcd.clear();
  index_t = 0;
}

void lcd_wrong_card() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Wrong card   ");
  notify_mode(NOT_OK);
  delay(3000);
  lcd.clear();
  index_t = 0;
}

void lcd_finger_wrong() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Not found finger");
  notify_mode(NOT_OK);
  delay(3000);
  lcd.clear();
  index_t = 0;
}

void notify_mode(int mode) {
  if (mode == OK) {
    for (int i = 0; i < 2; i++) {
      digitalWrite(BUZZ, HIGH);
      delay(80);
      digitalWrite(BUZZ, LOW);
      delay(80);
    }
  } else if (mode == NOT_OK) {
    for (int i = 0; i < 3; i++) {
      digitalWrite(BUZZ, HIGH);
      delay(80);
      digitalWrite(BUZZ, LOW);
      delay(80);
    }
  } else if (mode == SOS) {
    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < 4; i++) {
        digitalWrite(BUZZ, HIGH);
        delay(80);
        digitalWrite(BUZZ, LOW);
        delay(80);
      }
      delay(100);
    }
  }
}

void read_button() {
  if (!digitalRead(BUTTON)) {
    index_t = 3;
  }
}

void getWifi() {
  if (config_wifi) {
    config_wifi = 0;
    char buff_name_wifi[20];
    char buff_pass_wifi[20];
    Blynk.virtualWrite(V3, LOW);
    name_wifi.toCharArray(buff_name_wifi, 20);
    pass_wifi.toCharArray(buff_pass_wifi, 20);
    int len_name = strlen(buff_name_wifi);
    int len_pass = strlen(buff_pass_wifi);
    char eeprom_len_name = len_name + '0';
    char eeprom_len_pass = len_pass + '0';
    writeEeprom(buff_name_wifi, len_name, 10);
    writeEeprom(buff_pass_wifi, len_pass, 30);
    EEPROM.write(40, eeprom_len_name);
    EEPROM.commit();
    EEPROM.write(41, eeprom_len_pass);
    EEPROM.commit();
  }
}

void writeEeprom(char data[], int len, int status_read)
{
  int i = 0;
  for (i = status_read; i < (len + status_read); i++)
  {
    EEPROM.write(i, data[i - status_read]);
  }
  EEPROM.commit();
}

void readEeprom(int len, int status_read, char data_read[])
{
  int i = 0;
  for (i = status_read; i < (len + status_read); i++)
  {
    data_read[i - status_read] = EEPROM.read(i);
  }
}

Here is the result

Firmware Version: 0x92 = v2.0
c_name_wifi = Tuan Anh
c_pass_wifi = t4t4t4t4
.....
[4817] Connecting to Tuan Anh
[4819] Connected to WiFi
[4819] IP: 192.168.1.7
[4819] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on ESP32

 #StandWithUkraine    https://bit.ly/swua


[4974] Connecting to blynk.cloud:80
[8474] Invalid auth token
[22973] Connecting to blynk.cloud:80
[23319] Invalid auth token
[40973] Connecting to blynk.cloud:80
[41244] Invalid auth token
[58973] Connecting to blynk.cloud:80
[59404] Invalid auth token

Please edit your post (using the pencil icon at the bottom) and replace you screenshot with the full code that you are using, copied directly from your IDE as text, and pasted with triple backticks at the beginning and end so that it displays correctly.
Triple backticks look like this:
```

copy and paste them if you can’t find the correct character on your keyboard.

Then, do the same thing with your serial output. Use the mouse to select the text in your serial monitor then use C to copy it.

Pete.

i just edit my thread, can you check it for me. Thank you.

Your sketch is incomplete, and you appear to have made some illogical changes to the sketch from the code that appeared in your screenshot.

Pete.

sorry my bad, i fixed it now.

Your original screenshot showed this…

Were these three lines of Firmware Configuration copied and pasted directly from the Blynk web console, or did you re-type them manually?

I’d suggest that you return to having these three lines of code at the top of your sketch, then delete this line…

and change this line…

to…

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

However, there are numerous problems with the structure of your sketch. I do t understand why you are manually connecting to WiFi then using Blynk.begin()
This makes no sense.

Also, you should be using BlynkTimer to call a function and a void loop that looks like this…

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

rather than your current cluttered void loop and millis comparison process.

Pete.