In this guide, you’ll learn how to log data with the ESP8266 NodeMCU to the Firebase Realtime Database with timestamps (data logging) so that you have a record of your data history. As an example, we’ll log temperature, humidity, and pressure from a BME280 sensor and we’ll get timestamps from an NTP server. Then, you can access the data using the Firebase console, or build a web app to display the results (check this tutorial).
Part 2: ESP32/ESP8266: Firebase Data Logging Web App (Gauges, Charts, and Table)
Other Firebase Tutorials with the ESP32/ESP8266 that you might be interested in:
- ESP8266 NodeMCU: Getting Started with Firebase (Realtime Database)
- ESP8266 NodeMCU with Firebase – Creating a Web App
- ESP32/ESP8266 Firebase Authentication (Email and Password)
- ESP32/ESP8266 Firebase: Send BME280 Sensor Readings to the Realtime Database
- ESP32/ESP8266: Firebase Web App to Display Sensor Readings (with Authentication)
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 like authentication, realtime database, hosting, etc.
Project Overview
The following diagram shows a high-level overview of the project we’ll build.
- The ESP8266 authenticates as a user with email and password (that user must be set on the Firebase authentication methods);
- After authentication, the ESP gets the user UID;
- The database is protected with security rules. The user can only access the database nodes under the node with its user UID. After getting the user UID, the ESP can publish data to the database;
- The ESP8266 gets temperatrure, humidity and pressure from the BME280 sensor.
- It gets epoch time right after gettings the readings (timestamp).
- The ESP8266 sends temperature, humidity, pressure and timestamp to the database.
- New readings are added to the database periodically. You’ll have a record of all readings on the Firebase realtime database.
These are the main steps to complete this project:
- Create Firebase Project
- Set Authentication Methods
- Get Project API Key
- Set up Realtime Database
- Set up Database Security Rules
- ESP8266 Datalogging (Firebase Realtime Database)
You can continue with the Firebase project from this previous tutorial or create a new project. If you use the Firebase project of that previous tutorial, you can skip to section 4) Set up Realtime Database because the authentication methods are already set up.
Preparing Arduino IDE
For this tutorial, we’ll program the ESP8266 board using the Arduino core. So, make sure you have the ESP8266 add-on installed in your Arduino IDE:
If you want to program the ESP boards using VS Code with the PlatformIO extension, follow the following tutorial instead:
1) Create Firebase Project
1) Go to Firebase and sign in using a Google Account.
2) Click Get Started and then Add project to create a new project.
3) Give a name to your project, for example, ESP Firebase Demo.
4) Disable the option Enable Google Analytics for this project as it is not needed and click Create project.
5) It will take a few seconds to set up your project. Then, click Continue when it’s ready.
6) You’ll be redirected to your Project console page.
2) Set Authentication Methods
To allow authentication with email and password, first, 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 identifying 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.
1) On the left sidebar, click on Authentication and then on Get started.
2) Select the Option Email/Password.
3) Enable that authentication method and click Save.
4) The authentication with email and password should now be enabled.
5) Now, you need to add a user. On the Authentication tab, select the Users tab at the top. Then, click on Add User.
6) Add an email address for the authorized user. It can be your google account email or any other email. You can also create an email for this specific project. Add a password that will allow you to sign in to your app and access the database. Don’t forget to save the password in a safe place because you’ll need it later. When you’re done, click Add user.
7) A new user was successfully created and added to the Users table.
Notice that Firebase creates a unique UID for each registered user. The user UID allows us to identify the user and keep track of the user to provide or deny access to the project or the database. There’s also a column that registers the date of the last sign-in. At the moment, it is empty because we haven’t signed in with that user yet.
3) Get Project API Key
To interface with your Firebase project using the ESP8266 board, you need to get your project API key. Follow the next steps to get your project API key.
1) On the left sidebar, click on Project Settings.
2) Copy the Web API Key to a safe place because you’ll need it later.
4) Set up Realtime Database
Now, let’s create a realtime database and set up database rules for our project.
1) On the left sidebar, click on Realtime Database and then click on Create Database.
2) Select your database location. It should be the closest to your location.
3) Set up security rules for your database. You can select Start in test mode. We’ll change the database rules in just a moment.
4) 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.
5) Set up Database Security Rules
Now, let’s set up the database rules. On the Realtime Database tab, select the Rules tab at the top. Then, click on Edit rules, copy the following rules and then click Publish.
// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
"rules": {
"UsersData": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
These rules grant access to a node matching the authenticated user’s UID. This grants that each authenticated user can only access its own data. This means the user can only access the nodes that are under a node with its corresponding user UID. If there are other data published on the database, not under a node with the users’ UID, that user can’t access that data.
For example, imagine our user UID is RjO3taAzMMXBB2Xmir2LQ. With our security rules, it can read and write data to the database under the node UsersData/RjO3taAzMMXBB2Xmir2LQ.
You’ll better understand how this works when you start working with the ESP8266.
6) ESP8266 Datalogging (Firebase Realtime Database)
In this section, we’ll program the ESP8266 board to do the following tasks:
- Authenticate as a user with email and password (the user you set up in this section);
- Get BME280 readings: temperature, humidity, and pressure;
- Get epoch time (timestamp) from an NTP server;
- Send sensor readings and timestamp to the realtime database as an authorized user.
Parts Required
For this project, you need the following parts*:
- ESP8266 board (read best ESP8266 boards comparison);
- BME280 or any other sensor you’re familiar with;
- Breadboard;
- Jumper wires.
* you can also test the project with random values instead of sensor readings, or you can use any other sensor you’re familiar with.
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Schematic Diagram
In this tutorial, we’ll send BME280 sensor readings to the Firebase Realtime Database. So, you need to wire the BME280 sensor to your board.
We’re going to use I2C communication with the BME280 sensor module. For that, wire the sensor to the default ESP8266 SCL (GPIO 5 (D1)) and SDA (GPIO 4 (D2)) pins, as shown in the following schematic diagram.
Not familiar with the BME280 with the ESP8266? Read this tutorial: ESP8266 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity).
Installing Libraries
For this project, you need to install the following libraries:
Installing Libraries – VS Code
Follow the next instructions if you’re using VS Code with the PlatformIO extension.
Install the Firebase-ESP-Client Library
There is a library with lots of examples to use Firebase with the ESP8266: the Firebase-ESP-Client library. This library is compatible with both the ESP32 and ESP8266 boards.
Click on the PIO Home icon and 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.
Install the BME280 Library
In the Libraries tab, search for BME280. Select the Adafruit BME280 library.
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
Follow this section if you’re using Arduino IDE.
You need to install the following libraries:
Go to Sketch > Include Library > Manage Libraries, search for the libraries’ names and install the libraries.
For the Firebase Client library, select the Firebase Arduino Client Library for ESP8266 and ESP32.
Now, you’re all set to start programming the ESP8266 board to interact with the database.
Datalogging—Firebase Realtime Database Code
Copy the following code to your Arduino IDE or to the main.cpp file if you’re using VS Code.
You need to insert your network credentials, project API key, database URL, and the authorized user email and password.
/*
Rui Santos
Complete project details at our blog: https://RandomNerdTutorials.com/esp8266-data-logging-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.
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <NTPClient.h>
#include <WiFiUdp.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_PROJECT_API_KEY"
// Insert Authorized Email and Corresponding Password
#define USER_EMAIL "REPLACE_WITH_THE_USER_EMAIL"
#define USER_PASSWORD "REPLACE_WITH_THE_USER_PASSWORD"
// Insert RTDB URLefine the RTDB URL
#define DATABASE_URL "REPLACE_WITH_YOUR_DATABASE_URL"
// Define Firebase objects
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
// Variable to save USER UID
String uid;
// Database main path (to be updated in setup with the user UID)
String databasePath;
// Database child nodes
String tempPath = "/temperature";
String humPath = "/humidity";
String presPath = "/pressure";
String timePath = "/timestamp";
// Parent Node (to be updated in every loop)
String parentPath;
FirebaseJson json;
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
// Variable to save current epoch time
int timestamp;
// BME280 sensor
Adafruit_BME280 bme; // I2C
float temperature;
float humidity;
float pressure;
// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 180000;
// Initialize BME280
void initBME(){
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
// Initialize WiFi
void initWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
}
// Function that gets current epoch time
unsigned long getTime() {
timeClient.update();
unsigned long now = timeClient.getEpochTime();
return now;
}
void setup(){
Serial.begin(115200);
// Initialize BME280 sensor
initBME();
initWiFi();
timeClient.begin();
// Assign the api key (required)
config.api_key = API_KEY;
// Assign the user sign in credentials
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
// Assign the RTDB URL (required)
config.database_url = DATABASE_URL;
Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);
// Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
// Assign the maximum retry of token generation
config.max_token_generation_retry = 5;
// Initialize the library with the Firebase authen and config
Firebase.begin(&config, &auth);
// Getting the user UID might take a few seconds
Serial.println("Getting User UID");
while ((auth.token.uid) == "") {
Serial.print('.');
delay(1000);
}
// Print user UID
uid = auth.token.uid.c_str();
Serial.print("User UID: ");
Serial.println(uid);
// Update database path
databasePath = "/UsersData/" + uid + "/readings";
}
void loop(){
// Send new readings to database
if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
//Get current timestamp
timestamp = getTime();
Serial.print ("time: ");
Serial.println (timestamp);
parentPath= databasePath + "/" + String(timestamp);
json.set(tempPath.c_str(), String(bme.readTemperature()));
json.set(humPath.c_str(), String(bme.readHumidity()));
json.set(presPath.c_str(), String(bme.readPressure()/100.0F));
json.set(timePath, String(timestamp));
Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
}
}
How the Code Works
Continue reading to learn how the code works or skip to the demonstration section.
Include Libraries
First, include the required libraries. The ESP8266WiFi.h library to connect the ESP8266 to the internet, the Firebase_ESP_Client.h library to interface the board with Firebase, the Wire, Adafruit_Sensor, and Adafruit_BME280 to interface with the BME280 sensor, and the NTPClient and WiFiUdp libraries to get the time.
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <NTPClient.h>
#include <WiFiUdp.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"
Network Credentials
Include your network credentials in the following lines so that your boards can connect to the internet using your local network.
// Insert your network credentials
#define WIFI_SSID "REPLACE_WITH_YOUR_SSID"
#define WIFI_PASSWORD "REPLACE_WITH_YOUR_PASSWORD"
Firebase Project API Key, Firebase User, and Database URL
Insert your Firebase project API key—the one you’ve gotten in this section.
#define API_KEY "REPLACE_WITH_YOUR_PROJECT_API_KEY"
Insert the authorized email and the corresponding password—these are the details of the user you’ve added in this section.
// Insert Authorized Email and Corresponding Password
#define USER_EMAIL "REPLACE_WITH_THE_USER_EMAIL"
#define USER_PASSWORD "REPLACE_WITH_THE_USER_PASSWORD"
Insert your database URL in the following line:
// Insert RTDB URLefine the RTDB URL
#define DATABASE_URL "REPLACE_WITH_YOUR_DATABASE_URL"
Firebase Objects and Other Variables
The following line defines a FirebaseData object.
FirebaseData fbdo;
The next line defines a FirebaseAuth object needed for authentication.
FirebaseAuth auth;
Finally, the following line defines a FirebaseConfig object required for configuration data.
FirebaseConfig config;
The uid variable will be used to save the user’s UID. We can get the user’s UID after the authentication.
String uid;
The databasePath variable saves the database main path, which will be updated later with the user UID.
String databasePath;
The following variables save the database child nodes for the temperature, humidity, pressure, and timestamp.
String tempPath = "/temperature";
String humPath = "/humidity";
String presPath = "/pressure";
String timePath = "/timestamp";
The parentPath is the parent node that will be updated in every loop with the current timestamp.
// Parent Node (to be updated in every loop)
String parentPath;
To better understand how we’ll organize our data, here’s a diagram.
It might seem redundant to save the timestamp twice (in the parent node and in the child node), however, having all the data at the same level of the hierarchy will make things simpler in the future, if we want to build a web app to display the data.
Define the NTP client to get time:
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
The timestamp variable will be used to save time (epoch time format).
int timestamp;
To learn more about getting epoch time with the ESP8266 board, you can check the following tutorial:
We’ll send all the readings and corresponding timestamp to the realtime database at the same time by creating a JSON object that contains the values of those variables. The ESP Firebase Client library has its own JSON methods. We’ll use them to send data in JSON format to the database. We start by creating a variable of type FirebaseJson called json.
FirebaseJson json;
The ESP_Firebase_Client library provides some examples showing how to use FirebaseJson and how to send data in JSON format to the database: ESP_Firebase_Client library FirebaseJson examples.
Then, create an Adafruit_BME280 object called bme. This automatically creates a sensor object on the ESP8266 default I2C pins.
Adafruit_BME280 bme; // I2C
The following variables will hold the temperature, humidity, and pressure readings from the sensor.
float temperature;
float humidity;
float pressure;
Delay Time
The sendDataPrevMillis and timerDelay variables are used to check the delay time between each send. In this example, we’re setting the delay time to 3 minutes (18000 milliseconds). Once you test this project and check that everything is working as expected, we recommend increasing the delay.
// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 180000;
initBME()
The initBME() function initializes the BME280 library using the bme object created previously. Then, you should call this library in the setup().
void initBME(){
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
initWiFi()
The initWiFi() function connects your ESP to the internet using the network credentials provided. You must call this function later in the setup() to initialize WiFi.
// Initialize WiFi
void initWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
}
getTime()
The getTime() function returns the current epoch time.
// Function that gets current epoch time
unsigned long getTime() {
timeClient.update();
unsigned long now = timeClient.getEpochTime();
return now;
}
setup()
In the setup(), initialize the Serial Monitor for debugging purposes at a baud rate of 115200.
Serial.begin(115200);
Call the initBME() function to initialize the BME280 sensor.
initBME();
Call the initWiFi() function to initialize WiFi.
initWiFi();
Initialize the time client:
timeClient.begin();
Assign the API key to the Firebase configuration.
config.api_key = API_KEY;
The following lines assign the email and password to the Firebase authentication object.
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
Assign the database URL to the Firebase configuration object.
config.database_url = DATABASE_URL;
Add the following to the configuration object.
// Assign the callback function for the long running token generation task
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
// Assign the maximum retry of token generation
config.max_token_generation_retry = 5;
Initialize the Firebase library (authenticate) with the configuration and authentication settings we defined earlier.
// Initialize the library with the Firebase authen and config
Firebase.begin(&config, &auth);
After initializing the library, we can get the user UID by calling auth.token.uid. Getting the user’s UID might take some time, so we add a while loop that waits until we get it.
// Getting the user UID might take a few seconds
Serial.println("Getting User UID");
while ((auth.token.uid) == "") {
Serial.print('.');
delay(1000);
}
Finally, we save the user’s UID in the uid variable and print it in the Serial Monitor.
uid = auth.token.uid.c_str();
Serial.print("User UID: ");
Serial.print(uid);
After getting the user UID, we can update the database path to include the user UID.
// Update database path
databasePath = "/UsersData/" + uid + "/readings";
loop()
In the loop(), check if it is time to send new readings:
if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
If it is, get the current time and save it in the timestamp variable.
//Get current timestamp
timestamp = getTime();
Serial.print ("time: ");
Serial.println (timestamp);
Update the parentPath variable to include the timestamp.
parentPath= databasePath + "/" + String(timestamp);
Then, add data to the json object by using the set() method and passing as first argument the child node destination (key) and as second argument the value:
json.set(tempPath.c_str(), String(bme.readTemperature()));
json.set(humPath.c_str(), String(bme.readHumidity()));
json.set(presPath.c_str(), String(bme.readPressure()/100.0F));
json.set(timePath, String(timestamp));
Finally, call Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) to append the data to the parent path. We can call that instruction inside a Serial.printf() command to print the results in the Serial Monitor at the same time the command runs.
Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
Demonstration
Upload the previous code to your ESP8266 NodeMCU board. Don’t forget to insert your network credentials, project API key, database URL, user email, and the corresponding password.
After uploading the code, press the board RST button so that it starts running the code. It should authenticate to Firebase, get the user UID, and immediately send new readings to the database.
Open the Serial Monitor at a baud rate of 115200 and check that everything is working as expected.
Aditionally, go to the Realtime Database on your Firebase project interface and check that new readings are saved. Notice that it saves the data under a node with the own user UID—this is a way to restrict access to the database.
Wait some time until you get some readings on the database. Expand the nodes to check the data.
Wrapping Up
In this tutorial, you learned how to log your sensor readings with timestamps to the Firebase Realtime Database using the ESP8266. This was just a simple example for you to understand how it works.
You can use other methods provided by the ESP_Firebase_Client library to log your data, and you can organize your database in different ways. We organized the database in a way that is convenient for another project that we’ll publish soon.
In PART 2, we’ll create a Firebase Web App to display all saved data in a table and the latest readings on charts:
We hope you’ve found this tutorial useful.
If you like Firebase projects, please take a look at our new eBook. We’re sure you’ll like it:
Learn more about the ESP8266 with our resources:
Thanks for reading.
I wish this also had how to do this with deep sleep enabled
Great code, as long as the esp8266+BME280 of the device is placed in the detection environment, I can run Firebase real-time data anywhere, watch the detection: temperature/humidity/atmospheric pressure, thank you for sharing the code👍
Hi,
Excellent tutorial!
I tried replicating it on my NodeMCU (ESP8266), but I got an error.
../Arduino/libraries/Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32/src/Utils.h:1301:68: error: ‘schedule_function’ was not declared in this scope
{ schedule_function(callback); });
I don’t know where this function was supposed to be declared.
Could you help me?
Thanks!
Hi.
Are you using Arduino IDE or VS Code?
What is the version of the library that you are using?
Regards,
Sara
Hi.
I am using the Arduino IDE 1.8.19 and Firebase Arduino Client Library for ESP8266 and ESP32 ver. 3.0.1
Try downgrading the library to version 2.5.5 and check if that solves the issue.
Regards,
Sara
It worked just fine with version 2.5.5!
Thank you!
Regards,
Ricardo
For me Firebase stops working after certain time, when i see usage in firebase dashboard it shows all requests in denies, my question is how to know exact reason for denies?
I want to use Arduino Nano 33 BLE sense for this project, just wondering if I can use Firebase Arduino Client Library for ESP8266 and ESP32 for this board ?
Hi.
I don’t think it is compatible.
But you can try it and then you’ll see.
Regards,
sara
Hi,
I want to get and post data to Firebase by using AT commands ESP01 via TCP/IP.
I connected to Firebase but I can’t get or post.
AT+CIPSTART=”TCP”,”XXXX.firebaseio.com”,80
–> CONNECT
OK
AT+CIPSEND=
Hi Great Code! I am not using an authentication for my project but i do need the timestamps in my sensor reading. How can i add it?
Hi,
I tried your project but I get the following error:
“no matching function for call to ‘NTPClient::NTPClient(WiFiUDP&, const char[13]’
any help?
Hi.
What ESP8266 boards version are you using?
Go to Tools > Boards > Boards Manager and search for ESP8266.
You probably need to downgrade.
Regards,
Sara
Works very well.Tnx for the great work
Thanks
Hello how can i use other sensors i have dht11 and other bunch of sensors, i dont get the BME object and its functions how can i do that thank you <3
HELP I tried changing it to another sensor this is i get
.192.168.100.118
Token info: type = id token, status = on request
Token info: type = id token, status = ready
Getting User UID
User UID: MiSXMHlYq4M0LVwWCWWK0lnEdEe2
time: 1663231102
Set json… not found
Hi.
I think you’re not using the setjson function correctly.
Regards,
Sara
Is this right ?
parentPath= databasePath + “/” + String(timestamp);
json.set(tempPath.c_str(), String(randNumber));
json.set(timePath, String(timestamp));
Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
Is this right ?
parentPath= databasePath + “/” + String(timestamp);
json.set(tempPath.c_str(), String(randNumber));
json.set(timePath, String(timestamp));
Serial.printf(“Set json… %s\n”, Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? “ok” : fbdo.errorReason().c_str());
Thanks for posting this project. I’m trying to replicate but I got this error message:
21:45:08.251 -> Token info: type = id token (GITKit token), status = on request
21:45:08.251 -> Token info: type = id token (GITKit token), status = error
21:45:08.251 -> Token error: code: -4, message: connection lost
21:45:08.251 -> Getting User UID
21:45:08.251 -> …………………………………………………
Do u know why?
I’m trying to make the same project but with Arduino UNO and ESP8266-01s. I have issues, firstly, I don’t know what is the proper way to upload sensors data to the firebase to be accessed by the website? Any help will be appreciated. Thanks.
I’m trying to make the same project but with Arduino UNO and ESP8266-01s. I have issues, firstly, I don’t know what is the proper way to upload sensors data to the firebase to be accessed by the website? Any help will be appreciated. Thanks.
Testing the connection with firebase the result in the monitor is:
snip
…..192.168.xx.xx
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: INVALID_PASSWORD
Token info: type = id token (GITKit token), status = error
Token error: code: 400, message: bad request
Getting User UID
…………………………………….
snip end
The “Getting User UID lasts forever.
What can be the cause of this?
Greetings,
René.
Hi.
On your error statement, you have the following:
Token error: code: 400, message: INVALID_PASSWORD
So, double-check your password and the other configuration settings.
Regards,
Sara
Hi,
Thank you Sara.
Resetting the password did the trick.
Regards,
René.
Great!
Hi Sara,
I used Firebase Arduino Client Library for ESP8266 and ESP32 v,2.3.7 as suggested, but I can not compile the sketch for ESP8266, only for ESP32.
Any suggestion.thanks
Renzo
Check if you need to update your ESP8266 boards version.
In your Arduino IDE, go to Tools > Board > Boards Manager, search for ESP8266 and check if there are any updates.
Regards,
Sara
Thank you Sara,
just to make sure PC and code is uptodate and running I added just a single line of code:
Serial.printf(“*** temp %4.1f°C hum %2.0f%% pres %4.0f hPa\n”, bme.readTemperature(), bme.readHumidity(), bme.readPressure()/100.0F);
As you can see from the output:
Token info: type = id token (GITKit token), status = nrequest
Token info: type = id token GITKit token), status = ready
Getting User UID
User UID: D9sViJpqCHRyBHgVEPtpaGwOq8H3
time: 1674822801 <===== epoch is exact
*** temp 19.1°C hum 34% pres 969 hPa <===== values are ok!
Set json… send request failed <===========
All output is ok, only the json.set(…….) commands fails with “send request failed”
However the reported User UID:D9sViJpqCHRyBHgVEPtpaGwOq8H3
is different from the one I got while setup the database
user-ID D9sViJpqCHRyBHgVEPtpaGwOq8H
Here the trailing “3” is missing
Thank you for taking time to help me
Joshen
Hi Sara,
thank you for this great and comprehensive tutorial. Following all the steps I ended up with this messages:
Token info: type = id token (GITKit token), status = on request
Token info: type = id token (GITKit token), status = ready
Getting User UID
User UID: D9sV*****GwOq8H3
time: 1674810307
*** temp 20.1°C hum 33% pres 969 hPa <= introduced by me
Set json… send request failed
time: 1674810316
*** temp 20.1°C hum 33% pres 969 hPa
Set json… send request failed
Maybe you have a hint what is wrong in my settings/code.
Thank you
Joschen
Hi.
What lines of code did you change?
Regards,
Sara
Hi, is there a way to read data that has been sent to another esp32? (as data reader)
or are there any tutorial on how to do that in this website?
Thank you.
Hi Sara,
im working with project to update data of mq135 from esp8266 to realtime database, so i connect A0 of mq135 to A0 of esp8266wifi. The only thing i couldn’t understand is i can find where you define gate D0, D1 as input in your code because i want to change it to A0. So please help me, thank you.
Thank you
Minh
Hi.
I’m sorry, but I didn’t understand your question.
If you have doubts about the ESP8266 pinout, you can take a look at this tutorial: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
Regards,
Sara
Hello Sara,
I am trying to understand how you are storing the data.
If the sensor has a float value for temperature, humidity and pressure, why does the JSON.SET command use String (bme.readTemperature) instead of storing the float values in the database?
When I click on the data in the database, it shows ABC which I am thinking is storing the data as text. If I go to use the data later – read it, do something with it, will I need to convert from string back to float?
Thank you
Is there a way to just update everytime and not create a new entry everytime?I want to use the data in an android aplication and just need it to update the values from sensors each time?
Everything works great but what if I have one user with different esp modules posting different sensor data and another user that also hase more than one esp posting data.How do I add a ID for the esp so that each user will only be able to read the data that was stored by his different ESPs