Firebase getstring Delay

Hello,

i am using ESP32 for my home automation project.
in this project i am using the google firebase to communicate with my mobile application.

there are total 4 switches/ relays in my system which i control through the mobile application.

in my arduino code , i continously read the data from firebase using the firebase.getstring command but i am getting the delay while after sending the command.
controller stops working for 2 seconds and then it prints the data to serial.

why there is a delay in the firebase.getstring command?????

this is causing me total delay of 8 seconds .

i have attached code for reference.

code.txt (2.35 KB)

AshishMone:
Hello,

i am using ESP32 for my home automation project.
in this project i am using the google firebase to communicate with my mobile application.

there are total 4 switches/ relays in my system which i control through the mobile application.

in my arduino code , i continously read the data from firebase using the firebase.getstring command but i am getting the delay while after sending the command.
controller stops working for 2 seconds and then it prints the data to serial.

why there is a delay in the firebase.getstring command?????

this is causing me total delay of 8 seconds .

i have attached code for reference.

For starters, I would remove the personal information from your code.

Next, this code should be wrapped in code tags.

#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>          //https://github.com/esp8266/Arduino
#endif

//needed for library
#include <DNSServer.h>
#if defined(ESP8266)
#include <ESP8266WebServer.h>
#else
#include <WebServer.h>
#endif
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager                                                         //https://github.com/esp8266/Arduino
#include <IOXhop_FirebaseESP32.h>                                             // firebase library   
#include <stdio.h>

#define FIREBASE_HOST "homeconnect-5914a.firebaseio.com"                       //Do not include https:// in FIREBASE_HOST
#define FIREBASE_AUTH "<YOURKEY>"               // project secret API key
#define WIFI_SSID "<WIFISSID>"
#define WIFI_PASSWORD "<PASSWORD>"

const int relay1=2;
const int relay2=15;
const int relay3=17;
const int relay4=18;

String switch_1="avlon_connect_device_id/Avlon-1234/switch_1";
String switch_2="avlon_connect_device_id/Avlon-1234/switch_2";
String switch_3="avlon_connect_device_id/Avlon-1234/switch_3";
String switch_4="avlon_connect_device_id/Avlon-1234/switch_4";

void setup() {
  // initialize serial communication at 115200 bits per second:
  Serial.begin(115200);
  pinMode(relay1,OUTPUT);
   pinMode(relay2,OUTPUT);
   pinMode(relay3,OUTPUT);
   pinMode(relay4,OUTPUT);

 WiFiManager wifiManager;

        //and goes into a blocking loop awaiting configuration
    wifiManager.autoConnect("Avollon_Connect");

    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
     Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());
/////////////////////////////////////////////////////firebase connection///////////////////////////////////////////////////////
   Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);                                       // connect to firebase
   delay(2000);
}







void loop()
{
                    val1=Firebase.getString(switch_1); 
                    Serial.println(val1);
                    val2=Firebase.getString(switch_2);  
                    Serial.println(val2);   
                    val3=Firebase.getString(switch_3);
                    Serial.println(val3);
                    val4=Firebase.getString(switch_4); 
                    Serial.println(val4); 
}

Hello Romonaga,

thanks for the suggestions.

moving forward , do you have any solution on this ?

AshishMone:
Hello Romonaga,

thanks for the suggestions.

moving forward , do you have any solution on this ?

I had looked at your code, I did not see anything glaring. However, I also never used Firebase.

The one comment I do have is that your loop is running full throttle, and I would not think that a provider would like you hitting its door so many times. I do not know if this is the issue, as the provider could be throttling you because of the excess number of hits to the service.

To rule this out, put some timing inside your loop, and try NOT to use delay.

I have no experience with eiter the ESP or Firebase. Although I have not been able to check it completely, I doubt it's the getString method itself that is the bottleneck. getString calls http.sendRequest() which is probably part of the ESP libraries and will wait for a reply.

To shorten your delay for each getString(), you probably want to request all data in one go and not each individual part. With the libraries that you use, I have no idea how to do that.

Lastly, you can check / learn how you can achieve things at a lower level. You can send a request to a webserver, do something else and next check if a reply was received. Unfortunately no experience with the ESP.

Thank you for reply @sterretje & romonaga