Get started quickly with Firebase using the ESP8266 NodeMCU board. Firebase is Google’s mobile application development platform that includes many services to manage data from IOS, Android, or web applications. You’ll create a Firebase project with a realtime database (RTDB), and you’ll learn how to store and read values from the database with your ESP8266 board.
In a later tutorial, you’ll learn how to create a Firebase web app that you can access from anywhere to monitor and control your ESP8266 using firebase’s realtime database.
We have a similar tutorial for the ESP32 board: Getting Started with Firebase (Realtime Database)
What is Firebase?
Firebase is Googleâs mobile application development platform that helps you build, improve, and grow your app. It has many services used to manage data from any android, IOS, or web application.
The following paragraph clearly explains the advantages of using Firebase:
“Firebase is a toolset to âbuild, improve, and grow your appâ, and the tools it gives you cover a large portion of the services that developers would normally have to build themselves but donât really want to build because theyâd rather be focusing on the app experience itself. This includes things like analytics, authentication, databases, configuration, file storage, push messaging, and the list goes on. The services are hosted in the cloud and scale with little to no effort on the part of the developer.”
This paragraph was taken from this article, and we recommend that you read that article if you want to understand better what firebase is and what it allows you to do.
You can use the ESP8266 to connect and interact with your Firebase project, and you can create applications to control the ESP8266 via Firebase from anywhere in the world.
In this tutorial, we’ll create a Firebase project with a realtime database, and we’ll use the ESP8266 to store and read data from the database. The ESP8266 can interact with the database from anywhere in the world as long as it is connected to the internet.
This means that you can have two ESP8266 boards in different networks, with one board storing data and the other board reading the most recent data, for example.
In a later tutorial, we’ll create a web app using Firebase that will control the ESP8266 to display sensor readings or control outputs from anywhere in the world.
Project Overview
In this tutorial, you’ll learn how to create a Firebase project with a realtime database and store and read data from the database using the ESP8266.
To follow this project, first, you need to set up a Firebase project and create a realtime database for that project. Then, you’ll program the ESP8266 to store and read data from the database. This tutorial is divided into three sections.
- Create a Firebase Project
- ESP8266: Store data to the Firebase Realtime Database
- ESP8266: Read data from the Firebase Realtime Database
Let’s get started!
Set Up a Firebase Account and Create a New Project
1.Create a New Project
Follow the next instructions to create a new project on Firebase.
- Go to Firebase and sign in using a Google Account.
- Click Get Started, and then Add project to create a new project.
- Give a name to your project, for example: ESP Firebase Demo.
- Disable the option Enable Google Analytics for this project as it is not needed and click Create project.
- It will take a few seconds setting up your project. Then, click Continue when it’s ready.
- You’ll be redirected to your Project console page.
2. Set Authentication Methods
You need to set authentication methods for your app.
“Most apps need to know the identity of a user. In other words, it takes care of logging in and identify the users (in this case, the ESP8266). Knowing a user’s identity allows an app to securely save user data in the cloud and provide the same personalized experience across all of the user’s devices.” To learn more about the authentication methods, you can read the documentation.
- On the left sidebar, click on Authentication and then on Get started.
- There are several authentication methods like email and password, Google Account, Facebook account, and others.
- For testing purposes, we can select the Anonymous user (require authentication without requiring users to sign in first by creating temporary anonymous accounts). Enable that option and click Save.
3. Creating a Realtime Database
The next step is creating a Realtime Database for your project. Follow the next steps to create the database.
- On the left sidebar click on Realtime Database and then, click on Create Database.
- Select your database location. It should be the closest to your location.
- Set up security rules for your database. For testing purposes, select Start in test mode. In later tutorials you’ll learn how to secure your database using database rules.
- Your database is now created. You need to copy and save the database URLâhighlighted in the following imageâbecause you’ll need it later in your ESP8266 code.
The Realtime Database is all set. Now, you also need to get your project API key.
4. Get Project API Key
- To get your project’s API key, on the left sidebar click on Project Settings.
- Copy the API Key to a safe place because you’ll need it later.
Now, you have everything ready to interface the ESP8266 with the database.
Program the ESP8266 to Interface with Firebase
Now that the Firebase Realtime Database is created, you’ll learn how to interface the ESP8266 with the database.
To program the ESP8266, you can use Arduino IDE, VS Code with the PlatformIO extension, or other suitable software.
Note: for firebase projects, we recommend using VS Code with the PlatformIO extension because if you want to develop a web application to make the bridge between the ESP8266 and Firebase, VS Code provides all the tools to do that. However, we won’t build the web application in this tutorial, so you can use Arduino IDE.
Install the Firebase-ESP-Client Library
There is a library with lots of examples to use Firebase with the ESP8266 and ESP32 boards: the Firebase-ESP-Client library.
In this tutorial, we’ll look at simple examples to store and read data from the database. The library provides many other examples that you can check here. It also provides detailed documentation explaining how to use the library.
Installation – VS Code + PlatformIO
If you’re using VS Code with the PlatformIO extension, click on the PIO Home icon and then select the Libraries tab. Search for “Firebase ESP Client“. Select the Firebase Arduino Client Library for ESP8266 and ESP32.
Then, click Add to Project and select the project you’re working on.
Also, change the monitor speed to 115200 by adding the following line to the platformio.ini file of your project:
monitor_speed = 115200
Installation – Arduino IDE
If you’re using Arduino IDE, follow the next steps to install the library.
- Go to Sketch > Include Library > Manage Libraries
- Search for Firebase ESP Client and install the Firebase Arduino Client Library for ESP8266 and ESP32 by Mobitz.
Now, you’re all set to start programming the ESP8266 board to interact with the database.
ESP8266 Store Data to Firebase Database
Copy the following code to your Arduino IDE. This sketch inserts an int and a float number into the database every 15 seconds. This is a simple example showing you how to connect the ESP8266 to the database and store data. This is also compatible with ESP32 boards.
/*
Rui Santos
Complete project details at our blog.
- ESP32: https://RandomNerdTutorials.com/esp32-firebase-realtime-database/
- ESP8266: https://RandomNerdTutorials.com/esp8266-nodemcu-firebase-realtime-database/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Based in the RTDB Basic Example by Firebase-ESP-Client library by mobizt
https://github.com/mobizt/Firebase-ESP-Client/blob/main/examples/RTDB/Basic/Basic.ino
*/
#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 "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"
// Insert Firebase project API Key
#define API_KEY "REPLACE_WITH_YOUR_FIREBASE_PROJECT_API_KEY"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "REPLACE_WITH_YOUR_FIREBASE_DATABASE_URL"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int count = 0;
bool signupOK = false;
void setup(){
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* 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();
// Write an Int number on the database path test/int
if (Firebase.RTDB.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());
}
count++;
// Write an Float number on the database path test/float
if (Firebase.RTDB.setFloat(&fbdo, "test/float", 0.01 + random(0,100))){
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
}
}
You need to insert your network credentials, URL database, and project API key for the project to work.
This sketch was based on the basic example provided by the library. You can find more examples here.
How the Code Works
Continue reading to learn how the code works, or skip to the demonstration section.
First, include the required libraries. The ESP8266WiFi.h library to connect the ESP8266 to the internet (or the WiFi.h in case of the ESP32 board) and the Firebase_ESP_Client.h library to interface the boards with Firebase.
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
You also need to include the following for the Firebase library to work.
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
Include your network credentials in the following lines.
#define WIFI_SSID "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"
Insert your firebase project API keyâthe one you’ve gotten in section 4.1.
#define API_KEY "REPLACE_WITH_YOUR_FIREBASE_PROJECT_API_KEY"
Insert your database URLâsee section 3.4.
#define DATABASE_URL "REPLACE_WITH_YOUR_FIREBASE_DATABASE_URL"
setup()
In the setup(), connect your board to your network.
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Assign the API key and the database URL to the Firebase configuration.
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
The following lines take care of the signup for an anonymous user. Notice that you use the signUp() method, and the last two arguments are empty (anonymous user).
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
Note: in the anonymous user signup, every time the ESP connects, it creates a new anonymous user.
If the sign-in is successful, the signupOK variable changes to true.
signupOK = true;
The library provides examples for other authentication methods like signing in as a user with email and password, using the database legacy auth token, etc. You can check all the examples for other authentication methods here. If you end up using other authentication methods, don’t forget that you need to enable them on your firebase project (Build > Authentication > Sign-in method).
loop()
In the loop(), we’ll send data to the database periodically (if the signup is successful and everything is set up).
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)){
Send Data to the Database
As mentioned in the library documentation, to store data at a specific node in the Firebase RTDB (realtime database), use the following functions: set, setInt, setFloat, setDouble, setString, setJSON, setArray, setBlob, and setFile.
These functions return a boolean value indicating the success of the operation, which will be true if all of the following conditions are met:
- Server returns HTTP status code 200.
- The data types matched between request and response.Only setBlob and setFile functions that make a silent request to Firebase server, thus no payload response returned.
In our example, we’ll send an integer number, so we need to use the setInt() function as follows:
Firebase.RTDB.setInt(&fbdo, "test/int", count)
The second argument is the database node path, and the last argument is the value you want to pass to that database pathâyou can choose any other database path. In this case, we’re passing the value saved in the count variable.
Here’s the complete snippet that stores the value in the database and prints a success or failed message.
if (Firebase.RTDB.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());
}
We proceed in a similar way to store a float value. We’re storing a random float value on the test/float path.
// Write an Float number on the database path test/float
if (Firebase.RTDB.setFloat(&fbdo, "test/float", 0.01 + random(0, 100))) {
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
Demonstration
Upload the code to your ESP8266 board. Don’t forget to insert your network credentials, database URL path, and the project API key.
After uploading the code, open the Serial Monitor at a baud rate of 115200 and press the ESP8266 on-board reset button so it starts running the code.
If everything works as expected, the values should be stored in the database, and you should get success messages.
Go to your project’s Firebase Realtime database, and you’ll see the values saved on the different node paths. Every 15 seconds, it saves a new value. The database blinks when new values are saved.
Congratulations! You’ve successfully stored data in Firebase’s realtime database using the ESP8266. In the next section, you’ll learn to read values from the different database’s node paths.
ESP8266 Read From Firebase Database
In this section, you’ll learn how to read data from the database. We’ll read the data stored in the previous section. Remember that we saved an int value in the test/int path and a float value in the test/float path.
The following example reads the values stored in the database. Upload the following code to your board. You can use the same ESP8266 board or another board to get the data posted by the previous board.
/*
Rui Santos
Complete project details at our blog.
- ESP32: https://RandomNerdTutorials.com/esp32-firebase-realtime-database/
- ESP8266: https://RandomNerdTutorials.com/esp8266-nodemcu-firebase-realtime-database/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Based in the RTDB Basic Example by Firebase-ESP-Client library by mobizt
https://github.com/mobizt/Firebase-ESP-Client/blob/main/examples/RTDB/Basic/Basic.ino
*/
#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 "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"
// Insert Firebase project API Key
#define API_KEY "REPLACE_WITH_YOUR_FIREBASE_PROJECT_API_KEY"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "REPLACE_WITH_YOUR_FIREBASE_DATABASE_URL"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int intValue;
float floatValue;
bool signupOK = false;
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* 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.getInt(&fbdo, "/test/int")) {
if (fbdo.dataType() == "int") {
intValue = fbdo.intData();
Serial.println(intValue);
}
}
else {
Serial.println(fbdo.errorReason());
}
if (Firebase.RTDB.getFloat(&fbdo, "/test/float")) {
if (fbdo.dataType() == "float") {
floatValue = fbdo.floatData();
Serial.println(floatValue);
}
}
else {
Serial.println(fbdo.errorReason());
}
}
}
Don’t forget to insert your network credentials, database URL, and API key.
How the Code Works
The code is very similar to the previous section’s example, but it reads data from the database. Let’s take a look at the relevant parts for this section.
Data at a specific node in Firebase RTDB can be read through the following functions: get, getInt, getFloat, getDouble, getBool, getString, getJSON, getArray, getBlob, getFile.
These functions return a boolean value indicating the success of the operation, which will be true if all of the following conditions were met:
- Server returns HTTP status code 200
- The data types matched between request and response.
The database data’s payload (response) can be read or access through the following Firebase Data object’s functions: fbdo.intData, fbdo.floatData, fbdo.doubleData, fbdo.boolData, fbdo.stringData, fbdo.jsonString, fbdo.jsonObject, fbdo.jsonObjectPtr, fbdo.jsonArray, fbdo.jsonArrayPtr, fbdo.jsonData (for keeping parse/get result), and fbdo.blobData.
If you use a function that doesn’t match the returned data type in the database, it will return empty (string, object, or array).
The data type of the returning payload can be determined by fbdo.getDataType.
The following snippet shows how to get an integer value stored in the test/int node. First, we use the getInt() function; then, we check if the data type is an integer with fbdo.dataType(), and finally, the fdbo.intData() gets the value stored in that node.
if (Firebase.RTDB.getInt(&fbdo, "/test/int")) {
if (fbdo.dataType() == "int") {
intValue = fbdo.intData();
Serial.println(intValue);
}
}
else {
Serial.println(fbdo.errorReason());
}
We use a similar snippet to get the float value.
if (Firebase.RTDB.getFloat(&fbdo, "/test/float")) {
if (fbdo.dataType() == "float") {
floatValue = fbdo.floatData();
Serial.println(floatValue);
}
}
else {
Serial.println(fbdo.errorReason());
}
Demonstration
Upload the code to your board. Then, open the Serial Monitor at a baud rate of 115200. After a few seconds, it will print the values saved on the database.
Wrapping Up
Congratulations! In this tutorial, you’ve created a Firebase project with a Realtime Database and learned how to store and read data from the database using the ESP8266 NodeMCU board.
To keep things simple, we’ve stored sample values on the database. The idea is to save useful data like sensor readings or GPIO states.
Then, you can access the database with another ESP8266 to get the data or create a Firebase web app to use that data to display sensor readings or control the ESP8266 GPIOs from anywhere in the world. We’ll cover how to create a Firebase Web App in a future tutorial. So, stay tuned.
We hope you find this tutorial useful.
We hope you find this tutorial useful. If you want to learn more about Firebase with the ESP32 and ESP8266 boards, check out our new eBook:
If you want to learn more about the ESP8266, check our courses:
- Home Automation Using ESP8266
- Build Web Servers with ESP32 and ESP8266 eBook (2nd Edition)
- More ESP8266 Projects and TutorialsâŠ
Thanks for reading.
This looks like an exciting project, cant wait to see the 2nd part, web based output. Thanks again .
Looks interesting but so far I haven’t gotten the first part to work. Below is what shows on my serial monitor.
Any idea what is wrong.
Serial monitor:
Connected with IP xxx.xxx.x.xxx
ok
FAILED
REASON: connection lost
FAILED
REASON: connection lost
#define DATABASE_URL “esp-firebase-demo-xxxxx-default-xxxx: null”
#define DATABASE_URL “esp-firebase-demo-xxxxx-default-xxxx:”
<I tried but ways but doesn’t work either way>
probably you put a variable before the “if” in the loop. I added my variable inside the first if and it solved:
“if (Firebase.ready() && signupOK && (millis() – sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
variable = (analogRead(A0)*3.3/1023);
// Write an Int number on the database path test/int
if..."
First post discarded all my comments, one more time
Looks interesting but so far I haven’t gotten the first part to work. Below is what shows on my serial monitor.
Any idea what is wrong.
Serial monitor:
Connected with IP xxx.xxx.x.xxx
ok
//after about 2 minutes//
//from else line 89//
FAILED
REASON: connection lost
//after about 2 minutes//
//from else line 101//
FAILED
REASON: connection lost
//repeats//
//should line 32 include ‘:null’//
#define DATABASE_URL “esp-firebase-demo-xxxxx-default-xxxx: null”
//or//
#define DATABASE_URL “esp-firebase-demo-xxxxx-default-xxxx:”
//I tried both ways but doesn’t work either way//
//Nothing shows up on the Realtime Database//
Hi Bob.
Can you send an email to our support? https://randomnerdtutorials.com/support/
Rui will forward your email to me and it will be easier to find out what is happening.
Just add [To Sara] in the email subject.
Regards,
Sara
Hi Sara
Thanks for the response
I found my mistake. I copied the wrong data to line 32 #define DATABASE_URL
Works just fine now.
Thanks for randomnerdtutorials.com It is a great source of information
Bob
Great!
I’m glad you solved the issue.
Regards,
Sara
It sort of works for me. I have added the snippets to my program which displays time and temp on Oled and I get several exception(3) restarts just after initializing the firebase stuff in setup.
I wonder if more people see this happening?
BR
Jan
Hi.
Where did you insert the code for the OLED display?
What libraries do you use for your OLED?
Regards,
Sara
Hi again.
I saw your most recent comment.
If you need more help, you can send an email to our support: https://randomnerdtutorials.com/support/
Regards,
Sara
Realized I could do the test with original program from Sarah as described above.
That does not give the resets/restarts.
My program without firebase snippets works ok, but inserting the firebase snippets causes the restarts (Exception (3)) just in setup executing Firebase.begin(&config, &auth);
No clue why (yet).
Exactly what I need bit I can’t get past the Firebase.begin statement. Firebase.signup is ok as I see the IDs O. The Firebase console.
The error I get is a code 400 bad request. Pretty sure the URL and API key is correct. Any idea?
Hi.
What is the version of the ESP Firebase Client Library that you’re using?
Try downgrading to version 2.3.7 and see if that solves the issue.
Regards,
Sara
Thanks for getting back, Sara
I had v2.5.4 installed and found out it broke with v2.5.3. Any idea why? Does the code need to be changed?
Two more questions:
1) Is the connection from the ESP8266 to the Firebase RTDB secure (https)? If not how can I make it secure?
2) Is it possible to send JSON payload to Firebase? Didn’t see any obvious code samples but would like to try that
Hi.
I don’t know why it doens’t work with recent versions of the library.
Yes, you can secure with HTTPS. See the documentation: https://github.com/mobizt/Firebase-ESP-Client It explains how to add a certificate.
Yes, you can send JSON payload by using the setJSON method.
The ESP Firebase Client library has its own JSON functions, so it is useful taking a look at the documentation: https://github.com/mobizt/Firebase-ESP-Client#append-data
Regards,
Sara
Will do Txs for the great help, Sara
I had the same error.
Great answer solved it, big thanks.
Great thanks for learning from this site!!
Hi, first I apology for my bad English.
I almost do eveything above,but it just keep showing these.
Token info: type = id token, status = error
Token error: code: 400, message: bad request
Token info: type = id token, status = on request
Is that something I did wrong?
Hi
Check Your project API key and database URL.
If everything is correct, try downgrading to the ESP Firebase Client library to version 2.3.7
Regards,
Sara
I tried and it works, but I expected to see in the database give all the values, and the previous ones. I found it interesting as a data logger. May?
Hi.
Yes, it can be used as a datalogger.
For example, save the readings under nodes with the timestamp.
Regards,
Sara
sorry but, how I do that ?
Hello,
The Arduino Serial Monitor is only printing “Connecting to WiFI…………………………..”
Please let me know the resolution to this issue.
John
Hi.
Double-check that you’ve inserted the right network credentials in the code.
Regards,
Sara
Hi Sara,
I have check these values several times, Should I start a new project?
Thank you for your response.
John
I don’t know.
That issue is usually related to:
– incorrect SSID or password;
– poor wi-fi range (the ESP can’t connect to the router)
I don’t think it has anything to do with the project itself.
Regards,
Sara
cannot find Firebase_ESP_Client.h
Hi.
Install the Firebase ESP Client Library.
Regards,
Sara
Congratulations on the article, finally someone able to explain in a simple and accurate way how to start a Firebase-ESP8266 project.
I followed your examples and everything works fine. I tried to manage my data and I found some difficulties that I hope you will help me to solve.
In firebase I have this example:
MW-COUNT
0-MAX 5
1-TOUT 3
2-TING 2
I generated this structure by inserting integer values (5,3,2)
Now I tried to read them in a single function but I only ever get the first value 5.
Do you have a solution to this problem?
Is it possible to read the entire MW-COUNT node?
Thanks for your kind cooperation.
Hi.
Yes, you just have to read the parent path, instead of the full path node.
Regards,
Sara
Hello Sarah,
Very nice project. I have lots of ideas for firebase. Just a question. how much does it cost for basic projects. Is there a limit before we pay.
thank you Michel
Hi.
For basic projects is completely free.
Regards.
Sara
Hi Sara, I have encounter the following error when I compiling. I have downgraded the library to 2.3.7 version but still cannot work.
Arduino: 1.8.19 (Windows 10), Board: “Arduino Nano, ATmega328P”
In file included from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Utils.h:37:0,
from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/signer/Signer.h:37,
from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Firebase_ESP_Client.h:41,
from C:\Users\angyo\Desktop\Arduino\ESP_Testing_Send\ESP_Testing_Send.ino:18:
C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/common.h:36:10: fatal error: vector: No such file or directory
#include
^~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Hi.
Select an ESP32 or ESP8266 board in Tools > Board.
From your output, it seems you have an Arduino Nano selected.
Regards,
Sara
Hi Sara, I have choose the correct board but still cannot work, this is what I get:
Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)”
In file included from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/common.h:45:0,
from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Utils.h:37,
from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/signer/Signer.h:37,
from C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Firebase_ESP_Client.h:41,
from C:\Users\angyo\Desktop\Arduino\ESP_Testing_Send\ESP_Testing_Send.ino:18:
C:\Users\angyo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/wcs/esp8266/FB_TCP_Client.h:56:30: fatal error: CertStoreBearSSL.h: No such file or directory
#include <CertStoreBearSSL.h>
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
have found solution this problem?
Hi.
Please try updating your boards installation to the latest version.
Regards,
Sara
hello, I still have this error, I redid the tutorial 10 times but still the same error
13:55:00.902 -> Connected with IP: 192.168.1.60
13:55:00.902 ->
13:55:02.065 -> API key not valid. Please pass a valid API key.
13:55:02.065 -> Token info: type = id token, status = on request
13:55:03.189 -> Token info: type = id token, status = error
13:55:03.189 -> Token error: code: 400, message: API key not valid. Please pass a valid API key.
13:55:03.189 -> Token info: type = id token, status = error
13:55:03.237 -> Token error: code: 400, message: bad request
13:55:03.237 -> Token info: type = id token, status = on request
13:55:04.334 -> Token info: type = id token, status = error
13:55:04.380 -> Token error: code: 400, message: API key not valid. Please pass a valid API key.
13:55:04.380 -> Token info: type = id token, status = error
13:55:04.380 -> Token error: code: 400, message: bad reques
Hi.
Double-check your API key.
Are you copying the API key correctly? Are you copying the database URL correctly?
The error is about the API key.
Maybe create a new Firebase project and see if that solves the issue.
Regards,
Sara
Hi !
Token info: type = id token, status = error
Token error: code: 400, message: bad request
Token info: type = id token, status = on request
I am a student studying in Korea.
The above error appears repeatedly.
Can you help?
I respect you.
Can you tell me how to study?
Hi.
Please double-check the database URL and token.
Regards,
Sara
finally man. i have done a through research on this subject for my home automation and found only outdated material which my board wont be able to run but before i gave up i found this article and it works great . thank you so much really appreciate it keep up the good work .
That’s great!
Hi
I keep getting an error stating that this is an Admin Only Operation? Any help would be appreciated.
Thanks
Hi.
Check your database rules and that you’ve enabled anonymous users.
Regards,
Sara
Hi Sara Santos,
Very useful. I have different issue. My firebase RTDB store N number of data of people (name, age , salary). Surely I need a loop to read all data of N people. My path is like this
root/uniqueID_1/name
root/uniqueID_1/age
root/uniqueID_1/salary
root/uniqueID_2/name
root/uniqueID_2/age
root/uniqueID_2/salary
and so on.
How can parse this entire databse ot retreive each data
Hi Sara, if i set rules: Read: false, Write: false. What do i need to add to the code so it can connect to rtdb. please
Hi.
With those rules, you won’t be able to write to the database, except manually.
Regards,
Sara
Itried the code, gives the error: Token error: code: 400, message: INVALID_PASSWORD.
For login the gmail account after inserting the correct password, I need to tap on the phone. Is the error has anything to do with login procedure?
Hi Sara,
I try this sketch, it runs for ESP32 but with ESP8266 I can’t compile.
I use as you suggested but it is full of errors, i.e. <C:\Users\Renzo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\SD\src/SD.h:30:20: note: to match this ‘(‘>
or <C:\Users\Renzo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\SD\src/SD.h:30:28: note: in expansion of macro ‘O_READ’
30 | #define FILE_WRITE (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT | sdfat::O_APPEND)>
For me is deep dark.
Probably there is another library that is incompatible
If you have any solution , thanks
Renzo
Hi.
Make sure you have all the latest libraries and the latest ESP8266 installation.
Regards,
Sara
Hi Sara,
greate tutorial, thank-you đđ
after completing successful the first one in the “firebase” series “esp8266-nodemcu-firebase-realtime-database” step by step I have tried the more realistic one
“esp32-data-logging-firebase-realtime-database/”
using the same firebase as created by the first tutorial. Using the same API Key and DATABASE_URL. However access was denied due to PASSWORD_LOGIN_DISABLED.
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: PASSWORD_LOGIN_DISABLED
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: bad request
Getting User UID
Maybe I have to change the access method for my firebase or other settings. Please tell me where and how to do this.
Thanks again for sharing your knowledgeđ
Joshen
Hi.
You need to follow all the instructions here: https://randomnerdtutorials.com/esp32-data-logging-firebase-realtime-database/
You can use the same project and database, but you need to set up authentication with username and password: https://randomnerdtutorials.com/esp32-data-logging-firebase-realtime-database/#Set-Authentication-Methods
Regards,
Sara
thank you for very fast respons, however there is no “get started” button under Authentication:-((
Clicking Authentication all I see is a 18 entries long list of (anonym) users.
Thank you spending even more time solving my problem
Joschen
So, you need to add a new authentication method.
When you click “Authentication”, there is a tab at the top “Sign-in method”-
There you’ll create a provider with email/password.
I hope this helps.
Regards,
Sara
Thank you Sara, now login is ok!
Have a nice day.
Hi, I am getting the error:
FAILED
REASON: send request failed
Can you please help me with this. It is really urgent for me. I’d be really thankful.
Thanks.
I tried downgrading the library to 2.3.7 and now it only shows the line
Connected to IP: (and the address)_and thats it. Can you help?
Hello,
I have followed this tutorial and successfully build a project using Esp8266 and Firebase Realtime Database. Everything works fine except that when my project is kept idle for like an hour or something it gives me this error:
Token info: type = id token, status = on request
Token info: type = id token, status = error
Token error: code: 400, message: INVALID_EMAIL
Please Note that my Token and Database URL are totally fine. As far as the Email is concerned, im using the anonymous authentication of firebase so that the ESP can connect directly without any human interaction.
Thank you.
I successfully logged into the firebase. But in the loop() part, the error “connection lost” keeps comming. I am using v 2.3.7. The newest version gave me error “connection failed”
Hi Sara,
I try to compile for Wemos mini ESP8266 , but the compilation in not successful.
Probably the error is here;
In file included from C:\Users\Renzo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SD\src/SD.h:25,
from c:\users\renzo\documents\arduino\libraries\firebase_arduino_client_library_for_esp8266_and_esp32\src\firebasefs.h:162,
from C:\Users\Renzo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Firebase.h:36,
from C:\Users\Renzo\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/Firebase_ESP_Client.h:34,
from C:\Users\Renzo\AppData\Local\Temp\arduino_modified_sketch_190486\sketch_sep12b.ino:18:
C:\Users\Renzo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SDFS\src/SDFS.h: In member function ‘virtual int sdfs::SDFSFileImpl::availableForWrite()’:
C:\Users\Renzo\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\SDFS\src/SDFS.h:279:31: error: ‘using element_type = class File32’ {aka ‘class File32’} has no member named ‘availableSpaceForWrite’; did you mean ‘availableForWrite’?
279 | return _opened ? _fd->availableSpaceForWrite() : 0;
| ^~~~~~~~~~~~~~~~~~~~~~
| availableForWrite
Pi
Can you help me?
Tanks
Renzo Giurini
hello i did your tutorial but i keep getting this error:
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: -4, message: connection lost