Search code examples
cfirebasearduinoesp32data-retrieval

Cannot get the correct data from firebase using esp32. Everytime I use get function, the output is 0 in serial monitor


Firebase

Below is the code. I should get output as 1, but getting 0. I am sure that my firebase details are correct such as host and authentication because the demo example runs perfect.

I am using esp32 with Arduino IDE 1.8.12. Arduino Json 5.13.5

#include <IOXhop_FirebaseESP32.h>
#include <IOXhop_FirebaseESP32.h>

#include <WiFi.h>

#define FIREBASE_HOST "lab.firebaseio.com" // include the link of your firebase project
#define FIREBASE_AUTH "QWTbVwv"  // Include the authentication of your firebase project
#define WIFI_SSID "TAIM5_2.4Ghz"  // the name of the WiFi connection of your home or office
#define WIFI_PASSWORD "abc"  // password of the WiFi connection of your home or office 

int a;

void setup()
{
    Serial.begin(9600);
    delay(1000);

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi

    Serial.print("Connecting to ");
    Serial.print(WIFI_SSID);

    while (WiFi.status() != WL_CONNECTED) {

        Serial.print(".");
        delay(500);
    }

    Serial.println();
    Serial.print("Connected to ");
    Serial.println(WIFI_SSID);
    Serial.print("IP Address is : ");
    Serial.println(WiFi.localIP()); //print local IP address

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
}

void loop()
{
    a = (Firebase.getInt("fan/Fan"));

    if (Firebase.failed()) {
        Serial.println(Firebase.error());
    }
    else {
        Serial.println(a);
    }

    delay(1000);
}

I have tried to access other nodes also and still getting 0. What can be the problem?


Solution

  • I have tried to access other nodes also and still getting 0. What can be the problem?

    Could it be all your values are string instead of int?

    Have you tried:

    String str = Firebase.getString("fan/Fan");
    //...
    Serial.println(str);