B4J Question Firebase Realtime database example

morosh

Member
Hello:
I'm looking for a simple example for reading a firebase realtime database, preferably one single file, I searched a little but all what I found is more complex that what I need: for the moment I just need to read a specific line, like the this arduino example (getting string for line beginning with "parameter1"):
firebase realtime db read:
#include <Arduino.h>
#if defined(ESP32)
  #include <WiFi.h>
#elif defined(ESP8266)
  #include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>

//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"

// Insert your network credentials
#define WIFI_SSID "abc"
#define WIFI_PASSWORD "xyz"

// Insert Firebase project API Key
#define API_KEY "AIzaSyB6BA4DAC7j4V4rdLyfoPIPkCYMzrH9mnE"

// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "https://morosh-firebase1-default-rtdb.europe-west1.firebasedatabase.app/"

//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

unsigned long sendDataPrevMillis = 0;
String value;
bool signupOK = false;

void setup() {

// connect to wifi

  /* Assign the api key (required) */
  config.api_key = API_KEY;

  /* Assign the RTDB URL (required) */
  config.database_url = DATABASE_URL;

  /* Sign up */
  if (Firebase.signUp(&config, &auth, "", "")) {
    Serial.println("ok");
    signupOK = true;
  }
  else {
    Serial.printf("%s\n", config.signer.signupError.message.c_str());
  }

  /* Assign the callback function for the long running token generation task */
  config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

  Firebase.begin(&config, &auth);
  Firebase.reconnectWiFi(true);
}

void loop() {
  if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)) {
    sendDataPrevMillis = millis();
    if (Firebase.RTDB.getString(&fbdo, "parameter1")) {
        Value = fbdo.stringData();
        Serial.println(Value);
    }
    else {
      Serial.println(fbdo.errorReason());
    }
    
  }
}

Any help is apprecited
Thank you
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…