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.