I would like to control the ESP32 Led from the firebase by sending OFF to turn off and sending ON to turn on. The problem is, I have set the loop delay to 1s, however, the loop function takes about 3-5 seconds for every loop. I guess the problem is because of the (Firebase.getString) function. This function is used three call functions to link (TCP connection). I would appreciate if you Could help me to solve this issue or is there any function that didn't use the three call function from firebase to ESP32?
This is the complete code, just try to run it with and without the getString function and see the delay.
#include "WiFi.h"
#include <HTTPClient.h>
#include <FirebaseESP32.h>
#include <WebServer.h>
#include <WiFiManager.h>
const char* ssid = "Mobile net";
const char* password = "hmsx21hm";
const int led2 = 18;
#define FIREBASE_HOST "YourFirebaseAccount.com"
#define FIREBASE_AUTH "Your ID"
FirebaseData DeviceStatus2;
FirebaseJson json;
void setup() {
Serial.begin(115200);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
WiFi.begin(ssid, password);
// initialize digital pin LED_BUILTIN as an output.
pinMode(led2, OUTPUT);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
}
void loop() {
digitalWrite(led2, HIGH);
Serial.println("");
Serial.print("LED is ON... Normal ");
//delay(1000);
Firebase.getString(DeviceStatus2, "LED_STATUS2/Led");
if (DeviceStatus2.stringData() == "OFF") {
digitalWrite(led2, LOW);
Serial.println("");
Serial.println("Led Turned OFF");
}
else if (DeviceStatus2.stringData() == "ON") {
digitalWrite(led2, HIGH);
Serial.println("");
Serial.println("Led Turned ON");;
}
}