Short delay in Blynk application

I am using ESP32 as my main model and Blynk version is 1.3.2.
The main issue I’m experiencing is a short delay in my Blynk application. Strangely, I can get an instant response on my LCD screen. Is there any way for me to improve this delay? Thanks.

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "TMPL6V4egzmmb"
#define BLYNK_TEMPLATE_NAME "Table Tracking"
#define BLYNK_AUTH_TOKEN "GHaVBBTeg8qHtXYmrYTWk1rh4kixTBPg"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "DSE@unifi";
char pass[] = "C!ykChuah_*6@5308";


LiquidCrystal_I2C lcd(0x27, 20, 4);
 
int sensor1 = 13;
int sensor2 = 14;
int sensor3 = 27;
int sensor4 = 26;

int available_tables = 4; // Initialize available tables
int unavailable_tables = 1; // Define the number of unavailable tables
unsigned long previousMillis = 0;
const unsigned long interval = 1000; // Update every 1 second

void setup() 
{
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(sensor3,INPUT);
pinMode(sensor4,INPUT);
  Serial.begin(115200);
  lcd.init(); // initializing the LCD
  lcd.backlight(); // Enable or Turn On the backlight
  lcd.setCursor(0,0); // Position of Cursor on LCD Screen
  lcd.print("LCD CONNECTING..."); // Start Printing
  //delay(2000);
  lcd.clear();
  // Initialize previousMillis
  previousMillis = millis();
  Blynk.begin(auth, ssid, pass);
}

void updateTableStatus(int pin, int table_number) {
  if (digitalRead(table_number) == LOW) {
    if (pin == 0) {
      lcd.setCursor(0, 0);
      lcd.print("Table 1 is Full");
      Blynk.virtualWrite(V0, "Not Available");
      Blynk.setProperty(V1, "color", "#D3435C");
    }  
    else if (pin == 1) { 
      lcd.setCursor(0, 1);
      lcd.print("Table 2 is Full");
      Blynk.virtualWrite(V2, "Not Available");
      Blynk.setProperty(V3, "color", "#D3435C");
    }
    else if (pin == 2) { 
      lcd.setCursor(0, 2);
      lcd.print("Table 3 is Full");
      Blynk.virtualWrite(V5, "Not Available");
      Blynk.setProperty(V6, "color", "#D3435C");
    }
    else if (pin == 3) { 
      lcd.setCursor(0, 3);
      lcd.print("Table 4 is Full");
      Blynk.virtualWrite(V7, "Not Available");
      Blynk.setProperty(V8, "color", "#D3435C");
    }
  } else {
    if (pin == 0) {
      lcd.setCursor(0, 0);
      lcd.print("Table 1 is Free");
      Blynk.virtualWrite(V0, "Available");
      Blynk.setProperty(V1, "color", "#23C48E");
    } else if (pin == 1) {
      lcd.setCursor(0, 1);
      lcd.print("Table 2 is Free");
      Blynk.virtualWrite(V2, "Available");
      Blynk.setProperty(V3, "color", "#23C48E");
    }
    else if (pin == 2) {
      lcd.setCursor(0, 2);
      lcd.print("Table 3 is Free");
      Blynk.virtualWrite(V5, "Available");
      Blynk.setProperty(V6, "color", "#23C48E");
    }
    else if (pin == 3) {
      lcd.setCursor(0, 3);
      lcd.print("Table 4 is Free");
      Blynk.virtualWrite(V7, "Available");
      Blynk.setProperty(V8, "color", "#23C48E");
    }
  }
}

void updateAvailableTables() {
  available_tables = 4; // Reset the count
  for (int pin = 1; pin <= 1; pin++) {
    if (digitalRead(13) == LOW) {
      available_tables -= unavailable_tables;
    }
    if (digitalRead(14) == LOW) {
      available_tables -= unavailable_tables;
    }
    if (digitalRead(27) == LOW) {
      available_tables -= unavailable_tables;
    }
    if (digitalRead(26) == LOW) {
      available_tables -= unavailable_tables;
    }
  }
}

void loop() {
  unsigned long currentMillis = millis();
  
  if (currentMillis - previousMillis >= interval) {
    updateTableStatus(0, sensor1);
    updateTableStatus(1, sensor2);
    updateTableStatus(2, sensor3);
    updateTableStatus(3, sensor4);
    updateAvailableTables();
    Blynk.virtualWrite(V4, available_tables);
    previousMillis = currentMillis;

  }

  Blynk.run();
}

Before that, I wanted to try using the SimpleTimer or BlynkTimer library. However, it appears there was an issue with the library, so I had to change my approach.

What issue is this?

BlynkTimer is the way to go, and will allow you to clean-up your void loop.

You need to define what this means in more detail, and quantify what “short” means in practical terms.

Pete.

:\Users\JoyceYing\Documents\Arduino\LCD\TableTracking\TableTracking.ino:2:10: fatal error: BlynkTimer.h: No such file or directory
 #include <BlynkTimer.h>
          ^~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: BlynkTimer.h: No such file or directory

This is what the error message that I am get when I am trying to use BlynkTimer library.

I am not sure if the issue is related to the library or the version.

When the sensor detects motion, my LCD can update the status immediately, while at the same time with Blynk, there is a 3-4 minute delay in updating the status, and sometimes it can even extend to a 5-minute delay in the application.

You don’t need to include BlynkTimer, it’s already part of the Blynk libraries.
Read this for more info…

Is your device staying connected to Blynk?
Are you having any internet issues?
I’d expect the Blynk app to be updated within a few tenths of a second at most.

Pete.


Another issue that is troubling me is that even though I have already set the LED color for status changes, it still doesn’t display the color when there is a change in status detected by the sensor (It only affects the web Blynk, but it works normally in the mobile app.).

I got it after changing to BlynkTimer. Thanks a lot.