Firebase ESP32 Client: the Realtime Database from an ESP32
Yes, with limits. You can use the Firebase ESP32 Client library online in Mokxi with nothing to install, and the sketch runs in your browser. Part of it is not simulated, and the notes below say which. The example below, "Writing a counter to the Realtime Database", runs on the ESP32-C3-DevKitM-1.
Built in on Mokxi: #include <FirebaseESP32.h> and it builds, with nothing to install. Free, and no account needed.
What Firebase ESP32 Client does
Firebase ESP32 Client, by Mobizt, connects an ESP32 to Google’s Firebase, and this page covers its Realtime Database part: a JSON tree in the cloud that the board writes sensor values into and reads settings from, while a phone app or web page watches the same paths. A path like /test/int is a node, and setInt() or getInt() reads and writes it.
Every call goes through a FirebaseData object, which carries the request and the answer. After a call returns true, fbdo holds the value, its type and its path; after a call returns false, fbdo.errorReason() says what went wrong. Firebase.begin() takes either the database URL and a legacy secret, as the older examples do, or a config and auth pair for a user sign-in.
In Mokxi the calls run over the database’s REST API through HTTPClient. With the simulated network, https is refused, so each call returns false and errorReason() explains; with Real internet switched on in the Cloud panel they reach your actual database. Only the legacy database secret works here: email and password or anonymous sign-in leave Firebase.ready() false. Streams are not simulated. Mobizt now points new projects to his FirebaseClient library.
| Library Manager name | Firebase ESP32 Client |
|---|---|
| Author | Mobizt |
| Include | #include <FirebaseESP32.h> |
| Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM |
| In the simulator | Runs, with a gap the note below names. |
Install it
It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM.
In Mokxi it is built in: #include <FirebaseESP32.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Firebase ESP32 Client" by Mobizt from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Firebase ESP32 Client to lib_deps in PlatformIO. Mokxi follows the calls of release 4.4.17, so a sketch written here builds there too.
What to know in the simulator: Realtime Database calls only, over its REST API on HTTPClient: with the simulated network https is refused, so each call returns false and fbdo.errorReason() says why; with Real internet on in the Cloud panel they reach Firebase (reads as GET, writes as POST with x-http-method-override). Only the legacy database secret is simulated: email and password, anonymous sign-up and service accounts need an ID token too long for HTTPClient’s URL, so Firebase.ready() stays false and says why. Streams are not simulated; FirebaseJson builds flat objects.
The calls you will use
In the order a sketch meets them.
FirebaseData fbdo
The object every call reads and writes through. One is enough for a simple sketch; streams need a second.
Firebase.begin(DATABASE_URL, DATABASE_SECRET)
Points the library at your database with its URL and the legacy secret from Project settings, Service accounts, Database secrets.
Firebase.reconnectWiFi(true)
Lets the library rejoin WiFi on its own after a drop.
Firebase.ready()
True once authentication is done and calls may go out. Check it before each batch of calls.
Firebase.setInt(fbdo, "/test/int", count)
Writes an integer to a path and returns true on success. setFloat(), setString() and setBool() work the same way.
Firebase.getInt(fbdo, "/test/int")
Reads an integer and returns true on success; the value is then in fbdo.intData().
if (Firebase.getInt(fbdo, "/test/int")) {
Serial.println(fbdo.intData());
}fbdo.errorReason()
Why the last call failed, as a String: permission denied, path not found, a token error or a network error.
Firebase.setJSON(fbdo, "/readings", json)
Writes a FirebaseJson object as a whole node, for several values at once.
Example: Writing a counter to the Realtime Database
On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.
// After the library's Basic example, in its older Firebase.begin(host, secret) spelling.
#include <WiFi.h>
#include <FirebaseESP32.h>
#define DATABASE_URL "mokxi-demo-default-rtdb.firebaseio.com"
#define DATABASE_SECRET "DATABASE_SECRET_FROM_PROJECT_SETTINGS"
FirebaseData fbdo;
unsigned long sendDataPrevMillis = 0;
int count = 0;
void setup() {
Serial.begin(115200);
WiFi.begin("Mokxi-Lab", "breadboard");
while (WiFi.status() != WL_CONNECTED) delay(250);
Serial.println("Connected with IP: " + WiFi.localIP().toString());
Firebase.begin(DATABASE_URL, DATABASE_SECRET);
Firebase.reconnectWiFi(true);
}
void loop() {
if (Firebase.ready() && (millis() - sendDataPrevMillis > 2000 || sendDataPrevMillis == 0)) {
sendDataPrevMillis = millis();
if (Firebase.setInt(fbdo, "/test/int", count)) {
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
} else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if (Firebase.getInt(fbdo, "/test/int")) {
Serial.println(fbdo.intData());
} else {
Serial.println("get failed: " + fbdo.errorReason());
}
count++;
}
}Common errors and how to fix them
REASON: Permission denied
The database rules refuse the write. For a first test set the rules for that path to allow read and write, then tighten them once it works. With a legacy secret, rules are bypassed, so this error means the secret is wrong or missing.
Firebase.ready() never becomes true
Authentication has not finished or failed. Check the API key and the user’s email and password, and that the sign-in method is enabled in the Firebase console. In Mokxi, only the database secret is simulated, so other sign-ins stay not ready and say why.
Calls fail with a connection or host error
The DATABASE_URL is wrong. Copy it from the Realtime Database page of the console, including the region part such as europe-west1.firebasedatabase.app, and leave off any trailing slash or path.
Questions and answers
Does this library work with Firestore?
The upstream library has some Firestore support through its newer Firebase_ESP_Client form, but this page covers the Realtime Database calls, which are the only ones simulated in Mokxi.
Try Firebase ESP32 Client without installing anything
Open the example, change the sketch, and keep your version in a free account.