{"id":107399,"date":"2025-04-30T11:15:00","date_gmt":"2025-04-30T11:15:00","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=107399"},"modified":"2025-04-30T13:15:54","modified_gmt":"2025-04-30T13:15:54","slug":"esp32-esp8266-firebase-bme280-rtdb","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-bme280-rtdb\/","title":{"rendered":"ESP32\/ESP8266 Firebase: Send BME280 Sensor Readings to the Realtime Database"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to send BME280 sensor readings to the Firebase Realtime Database using the ESP32 or ESP8266 NodeMCU boards. The ESP board will authenticate as a user with email and password, and you&#8217;ll add database security rules to secure your data. The boards will be programmed using the Arduino core.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 NodeMCU Firebase Send BME280 Sensor Readings to the Realtime Database\" class=\"wp-image-169585\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><em>Updated 30 April 2025<\/em><\/p>\n\n\n\n<p class=\"rntbox rntclgray\">Here&#8217;s Part 2 of this project: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">ESP32\/ESP8266: Firebase Web App to Display Sensor Readings (with Authentication)<\/a><\/p>\n\n\n\n<p>Other Firebase Tutorials with the ESP32\/ESP8266 that you might be interested in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-realtime-database\/\">ESP32: Getting Started with Firebase (Realtime Database)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-firebase-realtime-database\/\">ESP8266 NodeMCU: Getting Started with Firebase (Realtime Database)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-web-app\/\">ESP32 with Firebase \u2013 Creating a Web App<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-firebase-web-app\/\">ESP8266 NodeMCU with Firebase \u2013 Creating a Web App<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-authentication\/\">ESP32\/ESP8266 Firebase Authentication (Email and Password)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is Firebase?<\/h2>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"196\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Firebase-Logo.png?resize=750%2C196&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Logo\" class=\"wp-image-169096\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Firebase-Logo.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Firebase-Logo.png?resize=300%2C78&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Firebase is Google&#8217;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 <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-authentication\/\">authentication<\/a>, <a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-realtime-database\/\">realtime database<\/a>, <a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-web-app\/\">hosting<\/a>, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>The following diagram shows a high-level overview of the project we&#8217;ll build.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"746\" height=\"378\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-BME280-Sensor-Readings-Database-Project-Overview-f.png?resize=746%2C378&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase ESP32 ESP8266 NodeMCU Send BME280 Sensor Readings to database Project Overview\" class=\"wp-image-169570\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-BME280-Sensor-Readings-Database-Project-Overview-f.png?w=746&amp;quality=100&amp;strip=all&amp;ssl=1 746w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-BME280-Sensor-Readings-Database-Project-Overview-f.png?resize=300%2C152&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n<ol class=\"wp-block-list\">\n<li>The ESP32\/ESP8266 authenticates as a user with email and password (that user must be set on the Firebase authentication methods);<\/li>\n\n\n\n<li>After authentication, the ESP gets the user UID;<\/li>\n\n\n\n<li>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;<\/li>\n\n\n\n<li>The ESP sends temperature, humidity and pressure to the database.<\/li>\n<\/ol>\n\n\n\n<p>These are the main steps to complete this project:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#create-firebase-project\">Create Firebase Project<\/a><\/li>\n\n\n\n<li><a href=\"#Set-Authentication-Methods\">Set Authentication Methods<\/a><\/li>\n\n\n\n<li><a href=\"#firebase-project-api-key\">Get Project API Key<\/a><\/li>\n\n\n\n<li><a href=\"#Set-up-Realtime-Database\">Set up Realtime Database<\/a><\/li>\n\n\n\n<li><a href=\"#Set-up-Database-Security-Rules\">Set up Database Security Rules<\/a><\/li>\n\n\n\n<li><a href=\"#ESP-Send-Sensor-Readings-RTDB\">ESP32\/ESP8266 Send Sensor Readings to the Realtime Database<\/a><\/li>\n<\/ol>\n\n\n\n<p>You can continue with the Firebase project <strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-authentication\/\">from this previous<\/a> tutorial<\/strong> or create a new project. If you use the Firebase project of that previous tutorial, you can skip to section <a style=\"font-size: inherit;\" href=\"#Set-up-Realtime-Database\">4) Set up Realtime Database<\/a> because the authentication methods are already set up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing Arduino IDE<\/h2>\n\n\n\n<p>For this tutorial, we&#8217;ll program the ESP32 and ESP8266 boards using the Arduino core. So, make sure you have the ESP32 or ESP8266 add-on installed in your Arduino IDE:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp32-arduino-ide-2-0\/\" title=\"\">Installing ESP32 Board in Arduino IDE 2 (Windows, Mac OS X, Linux)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp8266-nodemcu-arduino-ide-2-0\/\" title=\"\">Installing ESP8266 NodeMCU Board in Arduino IDE 2 (Windows, Mac OS X, Linux)<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you want to program the ESP boards using VS Code with the PlatformIO extension, follow the following tutorial instead:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-firebase-project\">1) <span style=\"font-size: inherit;\">Create Firebase Project<\/span><\/h2>\n\n\n\n<p>Follow the next instructions to create a new project on Firebase.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <a href=\"https:\/\/firebase.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Firebase <\/a>and sign in using a Google Account.<\/li>\n\n\n\n<li>Go to the <a href=\"https:\/\/console.firebase.google.com\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Firebase Console<\/a> and create a new project.<\/li>\n\n\n\n<li>Give a name to your project, for example: <em>ESP-Project,<\/em> and click <strong>Continue<\/strong>.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105729\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/1-create-firebase-project.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Set Up Firebase Project for ESP32 and ESP8266 Step 1\"><\/figure><\/li>\n\n\n\n<li>Next, enable or disable AI assistance for your project. This is optional.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105729\" style=\"width: 739px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/2-create-firebase-project-ai-assistance.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Set Up Firebase Project for ESP32 and ESP8266 - Enable AI assistant\"><\/figure><\/li>\n\n\n\n<li>Disable the option <em>Enable Google Analytics<\/em> for this project, as it is not needed. Then, click <strong>Create project<\/strong>.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105730\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/3-create-firebase-project.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Disable Google Analytics for firebase project\"><\/figure><\/li>\n\n\n\n<li>It will take a few seconds to set up your project. Click <strong>Continue <\/strong>when it&#8217;s ready.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105731\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/5-Firebase-project-ready.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project for ESP32 Ready\"><\/figure><br><\/li>\n\n\n\n<li>You&#8217;ll be redirected to your Project console page.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105732\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/6-Firebase-console-ESP-project.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase console project\"><\/figure><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Set-Authentication-Methods\">2) Set Authentication Methods<\/h2>\n\n\n\n<p>To allow authentication with email and password, first, you need to set authentication methods for your app. <\/p>\n\n\n\n<p>&#8220;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 ESP32 or ESP8266). Knowing a user&#8217;s identity allows an app to securely save user data in the cloud and provide the same personalized experience across all of the user&#8217;s devices.&#8221; To learn more about the authentication methods, you can <a href=\"https:\/\/firebase.google.com\/docs\/auth\" target=\"_blank\" rel=\"noreferrer noopener\">read the documentation<\/a>.<\/p>\n\n\n\n<p>You need to set authentication methods for your app. <\/p>\n\n\n\n<p>&#8220;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 ESP32). Knowing a user&#8217;s identity allows an app to securely save user data in the cloud &#8230;&#8221; To learn more about the authentication methods, you can <a href=\"https:\/\/firebase.google.com\/docs\/auth\" target=\"_blank\" rel=\"noreferrer noopener\">read the documentation<\/a>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>On the left sidebar, click on <strong>Build <\/strong>&gt; <strong>Authentication <\/strong>and then on <strong>Get started<\/strong>. <br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105735\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/7-set-authentication.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase project set authentication\"><\/figure><\/li>\n\n\n\n<li>There are several authentication methods like email and password, Google Account, Facebook account, and others.<figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105740\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/8-Firebase-authentication-methods.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SFirebase authentication methods\"><\/figure><\/li>\n\n\n\n<li>Select <strong>Email\/Password<\/strong> and <strong>enable <\/strong>that authentication method. Then, click <strong>Save<\/strong>.<figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105741\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/9-enable-email-password-firebase.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Enable Email Password Sign in Firebase\"><\/figure><\/li>\n\n\n\n<li>Then, at the top, click on the <strong>Users <\/strong>tab. Then, click on <strong>Add user<\/strong>. <figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105741\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/10-add-user-email-password-firebase.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Create a new user\"><\/figure><\/li>\n\n\n\n<li>Create a new user with an email and password. The email can be your personal email. Create a password for that user (you need to remember the password later). Finally, click on <strong>Add user<\/strong>.<figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105741\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/11-add-user-email-pass.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase add user email and password\"><\/figure><\/li>\n\n\n\n<li>The User will show up on the list of users. You can see information about the user, like when it was created, the last time it signed in, and its user UID.<figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105741\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/12-user-created-firebase.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase User Created\"><\/figure><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"firebase-project-api-key\">3) Get Project API Key<\/h2>\n\n\n\n<p>To interface with your Firebase project using the ESP32 or ESP8266 boards, you need to get your project API key. Follow the next steps to get your project API key.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>To get your project&#8217;s API key, on the left sidebar click on <strong>Project Settings<\/strong>.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105748\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/17-project-settings-firebase.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Realtime Database Project Settings\"><\/figure><\/li>\n\n\n\n<li>Copy the API Key to a safe place because you&#8217;ll need it later.<br><figure><img data-recalc-dims=\"1\" decoding=\"async\" class=\"wp-image-105749\" style=\"width: 750px;\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/18-project-api-key-firebase.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project API Key\"><\/figure><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Set-up-Realtime-Database\">4) Set up Realtime Database<\/h2>\n\n\n\n<p>Now, let&#8217;s create a realtime database and set up database rules for our project.<\/p>\n\n\n\n<p><strong>1)<\/strong> On the left sidebar, click on&nbsp;<strong>Realtime Database<\/strong>&nbsp;and then click on&nbsp;<strong>Create Database<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"452\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/13-create-database-firebase.png?resize=750%2C452&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project Create Database\" class=\"wp-image-169109\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/13-create-database-firebase.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/13-create-database-firebase.png?resize=300%2C181&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>2)<\/strong> Select your database location. It should be the closest to your location.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"743\" height=\"369\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/14-database-location-firebase.png?resize=743%2C369&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Realtime Database Set up location\" class=\"wp-image-169110\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/14-database-location-firebase.png?w=743&amp;quality=100&amp;strip=all&amp;ssl=1 743w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/14-database-location-firebase.png?resize=300%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><\/figure><\/div>\n\n\n<p><strong>3)<\/strong> Set up security rules for your database. You can select <strong>Start in test mode<\/strong>. We&#8217;ll change the database rules in just a moment.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"494\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/15-database-start-test-mode-firebase.png?resize=750%2C494&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Realtime Database Start in Test Mode\" class=\"wp-image-169111\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/15-database-start-test-mode-firebase.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/15-database-start-test-mode-firebase.png?resize=300%2C198&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>4)<\/strong> Your database is now created. You need to copy and save the database URL\u2014highlighted in the following image\u2014because you&#8217;ll need it later in your ESP32\/ESP8266 code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"490\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/16-firebase-database-url.png?resize=750%2C490&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Real time database URL\" class=\"wp-image-169112\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/16-firebase-database-url.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/04\/16-firebase-database-url.png?resize=300%2C196&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"Set-up-Database-Security-Rules\">5) Set up Database Security Rules<\/h2>\n\n\n\n<p>Now, let&#8217;s set up the database rules. On the <strong>Realtime Database<\/strong> tab, select the <strong>Rules<\/strong> tab at the top. Then, click on <strong>Edit rules<\/strong>, copy the following rules and then click <strong>Publish<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ These rules grant access to a node matching the authenticated\n\/\/ user's ID from the Firebase auth token\n{\n  \"rules\": {\n    \"UsersData\": {\n      \"$uid\": {\n        \".read\": \"$uid === auth.uid\",\n        \".write\": \"$uid === auth.uid\"\n      }\n    }\n  }\n}<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"492\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Realtime-Database-Rules.jpg?resize=782%2C492&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Realtime Database Set Up Rules\" class=\"wp-image-169571\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Realtime-Database-Rules.jpg?w=782&amp;quality=100&amp;strip=all&amp;ssl=1 782w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Realtime-Database-Rules.jpg?resize=300%2C189&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Realtime-Database-Rules.jpg?resize=768%2C483&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/figure><\/div>\n\n\n<p>These rules allow access only to the node that matches the authenticated user&#8217;s UID. This ensures that each user can access only their own data. In other words, a user can only read or write to the parts of the database located under their specific UID. Any data stored outside of their UID node will not be accessible to them.<\/p>\n\n\n\n<p>For example, imagine our user UID is <span class=\"rnthl rntliteral\">RjO3taAzMMXBB2Xmir2LQ<\/span>. With our security rules, it can read and write data to the database under the node <span class=\"rnthl rntliteral\">UsersData\/RjO3taAzMMXBB2Xmir2LQ<\/span>.<\/p>\n\n\n\n<p>You&#8217;ll better understand how this works when you start working with the ESP32\/ESP8266.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ESP-Send-Sensor-Readings-RTDB\">6) <span style=\"font-size: inherit;\">ESP32\/ESP8266 Send Sensor Readings to the Realtime Database<\/span><\/h2>\n\n\n\n<p id=\"Firebase-Authentication-ESP32-ESP8266\">In this section, we&#8217;ll program the ESP32 or ESP8266 boards to do the following tasks:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Authenticate as a user with email and password (<a href=\"#Set-Authentication-Methods\">the user you set up in this section<\/a>);<\/li>\n\n\n\n<li>Send sensor readings to the Firebase Realtime Database as an authorized user to the node corresponding to its user UID.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this project, you need the following parts*:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32<\/a> or<a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\"> ESP8266<\/a> board (read <a href=\"https:\/\/makeradvisor.com\/esp32-vs-esp8266\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32 vs ESP8266<\/a>);<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BME280<\/a> or any other sensor you&#8217;re familiar with;<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a>;&nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\">&nbsp;<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a>.<\/li>\n<\/ul>\n\n\n\n<p>* you can also test the project with random values instead of sensor readings, or you can use any other sensor you&#8217;re familiar with.<\/p>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>In this tutorial, we&#8217;ll send BME280 sensor readings to the Firebase Realtime Database. So, you need to wire the BME280 sensor to your board. Follow one of the following schematic diagrams.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">ESP32 with BME280<\/h4>\n\n\n\n<p>We&#8217;re going to use <a href=\"https:\/\/randomnerdtutorials.com\/esp32-i2c-communication-arduino-ide\/\" title=\"\">I2C communication<\/a> with the BME280 sensor module. For that, wire the sensor to the default ESP32 SCL (<span class=\"rnthl rntclblue\">GPIO 22<\/span>) and SDA (<span class=\"rnthl rntclgreen\">GPIO 21<\/span>) pins, as shown in the following schematic diagram.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"670\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=675%2C670&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BME280 Sensor Temperature Humidity Pressure Wiring Diagram Circuit\" class=\"wp-image-99755\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?w=675&amp;quality=100&amp;strip=all&amp;ssl=1 675w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=300%2C298&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Not familiar with the BME280 with the ESP32? Read this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\"><strong>ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)<\/strong><\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">ESP8266 with BME280 <\/h4>\n\n\n\n<p>We&#8217;re going to use I2C communication with the BME280 sensor module. For that, wire the sensor to the ESP8266&nbsp;SDA (<span class=\"rnthl rntclgreen\">GPIO 4<\/span>)&nbsp;and&nbsp;SCL (<span class=\"rnthl rntclblue\">GPIO 5<\/span>)&nbsp;pins, as shown in the following schematic diagram.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"531\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?resize=675%2C531&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU BME280 Sensor Temperature Humidity Pressure Wiring Diagram Circuit\" class=\"wp-image-98049\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?w=675&amp;quality=100&amp;strip=all&amp;ssl=1 675w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/07\/ESP8266-NodeMCU-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit.png?resize=300%2C236&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">Not familiar with the BME280 with the ESP8266? Read this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\"><strong>ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)<\/strong><\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Libraries<\/h3>\n\n\n\n<p>For this project, you need to install the following libraries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/mobizt\/FirebaseClient\" title=\"\">FirebaseClient Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BME280 Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit Unified Sensor Library<\/a><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Installing Libraries &#8211; VS Code<\/h4>\n\n\n\n<p>Follow the next instructions if you&#8217;re using VS Code with the PlatformIO or pioarduino extension.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Install the FirebaseClient Library<\/strong><\/h5>\n\n\n\n<p>Click on the <strong>PIO Home<\/strong> icon and select the <strong>Libraries tab<\/strong>. Search for &#8220;<strong>FirebaseClient<\/strong>&#8220;. Select the <strong>Firebase Client Library<\/strong> by Mobitz.<\/p>\n\n\n\n<p>If you&#8217;re using VS Code with the PlatformIO extension, click on the <strong>PIO Home<\/strong> icon and then select the <strong>Libraries tab<\/strong>. Search for &#8220;<strong>FirebaseClient<\/strong>&#8220;. Select the <strong>Firebase Client Library<\/strong> by Mobitz.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"646\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Install-FirebsaeClient-Library-VS-Code.jpg?resize=750%2C646&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install FirebaseClient Library VS Code\" class=\"wp-image-169174\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Install-FirebsaeClient-Library-VS-Code.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Install-FirebsaeClient-Library-VS-Code.jpg?resize=300%2C258&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Then, click <strong>Add to Project<\/strong> and select the project you&#8217;re working on.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"341\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Add-FirebaseClient-library-to-project-VS-Code.jpg?resize=750%2C341&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Add FirebaseClient Library ro project in VS Code\" class=\"wp-image-169175\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Add-FirebaseClient-library-to-project-VS-Code.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/Add-FirebaseClient-library-to-project-VS-Code.jpg?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Then, click <strong>Add to Project<\/strong> and select the project you&#8217;re working on.<\/p>\n\n\n\n<p><strong>Install the BME280 Library<\/strong> <\/p>\n\n\n\n<p>In the <strong>Libraries<\/strong> tab, search for <strong>BME280<\/strong>. Select the <strong>Adafruit BME280<\/strong> library.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"661\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-VS-Code-Search-BME280-library.png?resize=996%2C661&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"PlatformIO VS Code Search for BME280 Library\" class=\"wp-image-99243\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-VS-Code-Search-BME280-library.png?w=996&amp;quality=100&amp;strip=all&amp;ssl=1 996w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-VS-Code-Search-BME280-library.png?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-VS-Code-Search-BME280-library.png?resize=768%2C510&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 996px) 100vw, 996px\" \/><\/figure><\/div>\n\n\n<p> Then, click <strong>Add to Project<\/strong> and select the project you&#8217;re working on.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"243\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-add-library-to-project.png?resize=745%2C243&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"PlatformIO with VS Code Add Library to Project\" class=\"wp-image-99245\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-add-library-to-project.png?w=745&amp;quality=100&amp;strip=all&amp;ssl=1 745w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/09\/PlatformIO-add-library-to-project.png?resize=300%2C98&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/figure><\/div>\n\n\n<p>Also, change the monitor speed to 115200 by adding the following line to the <span class=\"rnthl rntliteral\">platformio.ini<\/span> file of your project:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>monitor_speed = 115200<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Installation &#8211; Arduino IDE<\/h4>\n\n\n\n<p>Follow this section if you&#8217;re using Arduino IDE. <\/p>\n\n\n\n<p>You need to install the following libraries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/mobizt\/FirebaseClient\" title=\"\">FirebaseClient Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BME280 Library<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit Unified Sensor Library<\/a><\/li>\n<\/ul>\n\n\n\n<p>Go to <strong>Sketch <\/strong>> <strong>Include Library<\/strong> > <strong>Manage Libraries<\/strong>, search for the libraries&#8217; names, and install the libraries.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"790\" height=\"586\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/install-Firebase-client-arduino-ide.png?resize=790%2C586&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install Firebase Client Library Arduino IDE\" class=\"wp-image-169118\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/install-Firebase-client-arduino-ide.png?w=790&amp;quality=100&amp;strip=all&amp;ssl=1 790w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/install-Firebase-client-arduino-ide.png?resize=300%2C223&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/install-Firebase-client-arduino-ide.png?resize=768%2C570&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 790px) 100vw, 790px\" \/><\/figure><\/div>\n\n\n<p>Now, you&#8217;re all set to start programming the ESP32 and ESP8266 boards to interact with the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"font-size: inherit;\">Send Sensor Readings to the Realtime Database<\/span> Code<\/h3>\n\n\n\n<p>Copy the following code to your Arduino IDE or to the <span class=\"rnthl rntliteral\">main.cpp<\/span> file if you&#8217;re using VS Code.<\/p>\n\n\n\n<p>You need to insert your network credentials, project API key, database URL, and the authorized user email and password.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n  Complete project details at our blog: https:\/\/RandomNerdTutorials.com\/esp32-esp8266-firebase-bme280-rtdb\/\r\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\r\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n*\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#if defined(ESP32)\r\n  #include &lt;WiFi.h&gt;\r\n#elif defined(ESP8266)\r\n  #include &lt;ESP8266WiFi.h&gt;\r\n#endif\r\n#include &lt;WiFiClientSecure.h&gt;\r\n#include &lt;FirebaseClient.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &lt;Adafruit_BME280.h&gt;\r\n\r\n\/\/ Network and Firebase credentials\r\n#define WIFI_SSID &quot;REPLACE_WITH_YOUR_SSID&quot;\r\n#define WIFI_PASSWORD &quot;REPLACE_WITH_YOUR_PASSWORD&quot;\r\n\r\n#define Web_API_KEY &quot;REPLACE_WITH_YOUR_PROJECT_API_KEY&quot;\r\n#define DATABASE_URL &quot;REPLACE_WITH_YOUR_DATABASE_URL&quot;\r\n#define USER_EMAIL &quot;REPLACE_WITH_THE_USER_EMAIL&quot;\r\n#define USER_PASSWORD &quot;REPLACE_WITH_THE_USER_PASSWORD&quot;\r\n\r\n\/\/ User function\r\nvoid processData(AsyncResult &amp;aResult);\r\n\r\n\/\/ Authentication\r\nUserAuth user_auth(Web_API_KEY, USER_EMAIL, USER_PASS);\r\n\r\n\/\/ Firebase components\r\nFirebaseApp app;\r\nWiFiClientSecure ssl_client;\r\nusing AsyncClient = AsyncClientClass;\r\nAsyncClient aClient(ssl_client);\r\nRealtimeDatabase Database;\r\n\r\n\/\/ Timer variables for sending data every 10 seconds\r\nunsigned long lastSendTime = 0;\r\nconst unsigned long sendInterval = 10000;\r\n\r\n\/\/ Variable to save USER UID\r\nString uid;\r\n\r\n\/\/ Variables to save database paths\r\nString databasePath;\r\nString tempPath;\r\nString humPath;\r\nString presPath;\r\n\r\n\/\/ BME280 sensor\r\nAdafruit_BME280 bme; \/\/ I2C\r\nfloat temperature;\r\nfloat humidity;\r\nfloat pressure;\r\n\r\n\/\/ Initialize BME280\r\nvoid initBME(){\r\n  if (!bme.begin(0x76)) {\r\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\r\n    while (1);\r\n  }\r\n  Serial.println(&quot;BME280 Initialized with success&quot;);\r\n}\r\n\r\nvoid setup(){\r\n  Serial.begin(115200);\r\n\r\n  initBME();\r\n\r\n  \/\/ Connect to Wi-Fi\r\n  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);\r\n  Serial.print(&quot;Connecting to Wi-Fi&quot;);\r\n  while (WiFi.status() != WL_CONNECTED)    {\r\n    Serial.print(&quot;.&quot;);\r\n    delay(300);\r\n  }\r\n  Serial.println();\r\n\r\n  ssl_client.setInsecure();\r\n  #if defined(ESP32)\r\n    ssl_client.setConnectionTimeout(1000);\r\n    ssl_client.setHandshakeTimeout(5);\r\n  #elif defined(ESP8266)\r\n    ssl_client.setTimeout(1000); \/\/ Set connection timeout\r\n    ssl_client.setBufferSizes(4096, 1024); \/\/ Set buffer sizes\r\n  #endif\r\n\r\n  \/\/ Initialize Firebase\r\n  initializeApp(aClient, app, getAuth(user_auth), processData, &quot;\ud83d\udd10 authTask&quot;);\r\n  app.getApp&lt;RealtimeDatabase&gt;(Database);\r\n  Database.url(DATABASE_URL);\r\n}\r\n\r\nvoid loop(){\r\n  \/\/ Maintain authentication and async tasks\r\n  app.loop();\r\n\r\n  \/\/ Check if authentication is ready\r\n  if (app.ready()){\r\n\r\n    \/\/ Periodic data sending every 10 seconds\r\n    unsigned long currentTime = millis();\r\n    if (currentTime - lastSendTime &gt;= sendInterval){\r\n      \/\/ Update the last send time\r\n      lastSendTime = currentTime;\r\n        \r\n      \/\/ Get User UID\r\n      Firebase.printf(&quot;User UID: %s\\n&quot;, app.getUid().c_str());\r\n      uid = app.getUid().c_str();\r\n      databasePath = &quot;UsersData\/&quot; + uid;\r\n\r\n      \/\/ Update database path for sensor readings\r\n      tempPath = databasePath + &quot;\/temperature&quot;; \/\/ --&gt; UsersData\/&lt;user_uid&gt;\/temperature\r\n      humPath = databasePath + &quot;\/humidity&quot;; \/\/ --&gt; UsersData\/&lt;user_uid&gt;\/humidity\r\n      presPath = databasePath + &quot;\/pressure&quot;; \/\/ --&gt; UsersData\/&lt;user_uid&gt;\/pressure\r\n\r\n      \/\/ Get latest sensor readings\r\n      temperature = bme.readTemperature();\r\n      humidity = bme.readHumidity();\r\n      pressure = bme.readPressure()\/100.0F;\r\n        \r\n      Serial.println(&quot;Writing to: &quot; + tempPath);\r\n\r\n      Database.set&lt;float&gt;(aClient, tempPath, temperature, processData, &quot;RTDB_Send_Temperature&quot;);\r\n      Database.set&lt;float&gt;(aClient, humPath, humidity, processData, &quot;RTDB_Send_Humidity&quot;);\r\n      Database.set&lt;float&gt;(aClient, presPath, pressure, processData, &quot;RTDB_Send_Pressure&quot;);\r\n\r\n    }\r\n  }\r\n}\r\n\r\nvoid processData(AsyncResult &amp;aResult){\r\n  if (!aResult.isResult())\r\n    return;\r\n\r\n  if (aResult.isEvent())\r\n    Firebase.printf(&quot;Event task: %s, msg: %s, code: %d\\n&quot;, aResult.uid().c_str(), aResult.eventLog().message().c_str(), aResult.eventLog().code());\r\n\r\n  if (aResult.isDebug())\r\n    Firebase.printf(&quot;Debug task: %s, msg: %s\\n&quot;, aResult.uid().c_str(), aResult.debug().c_str());\r\n\r\n  if (aResult.isError())\r\n    Firebase.printf(&quot;Error task: %s, msg: %s, code: %d\\n&quot;, aResult.uid().c_str(), aResult.error().message().c_str(), aResult.error().code());\r\n\r\n  if (aResult.available())\r\n    Firebase.printf(&quot;task: %s, payload: %s\\n&quot;, aResult.uid().c_str(), aResult.c_str());\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Firebase-ESP\/raw\/main\/ESP-Firebase-Sensor-BME280\/ESP-Firebase-Sensor-BME280.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Continue reading to learn how the code works, or skip to the <a href=\"#demonstration\">demonstration section<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Include Libraries<\/h4>\n\n\n\n<p>First, include the required libraries. We&#8217;re including different WiFi libraries for the ESP32 and ESP8266.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h>\n#if defined(ESP32)\n    #include &lt;WiFi.h>\n#elif defined(ESP8266)\n    #include &lt;ESP8266WiFi.h>\n#endif\n#include &lt;WiFiClientSecure.h>\n#include &lt;FirebaseClient.h>\n#include &lt;Adafruit_Sensor.h>\n#include &lt;Adafruit_BME280.h><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Network Credentials<\/h4>\n\n\n\n<p>Include your network credentials in the following lines so that your boards can connect to the internet using your local network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Insert your network credentials\n#define WIFI_SSID \"REPLACE_WITH_YOUR_SSID\"\n#define WIFI_PASSWORD \"REPLACE_WITH_YOUR_PASSWORD\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Firebase Project API Key, Firebase User, and Database URL<\/h4>\n\n\n\n<p>Insert your <a href=\"#firebase-project-api-key\">Firebase project API key<\/a>\u2014the one you&#8217;ve gotten <a href=\"#firebase-project-api-key\">in this section<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define Web_API_KEY \"REPLACE_WITH_YOUR_PROJECT_API_KEY\"<\/code><\/pre>\n\n\n\n<p>Insert your <a href=\"#Set-up-Realtime-Database\">database URL<\/a> in the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Insert RTDB URLefine the RTDB URL\n#define DATABASE_URL \"REPLACE_WITH_YOUR_DATABASE_URL\"<\/code><\/pre>\n\n\n\n<p>Insert the <a href=\"#Set-Authentication-Methods\">authorized email and the corresponding password<\/a>\u2014these are the details of the user you&#8217;ve added <a href=\"#Set-Authentication-Methods\">in this section<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define USER_EMAIL \"REPLACE_WITH_THE_USER_EMAIL\"\n#define USER_PASSWORD \"REPLACE_WITH_THE_USER_PASSWORD\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Declaring Firebase Authentication and Components<\/h4>\n\n\n\n<p>The following line creates an authentication object using the project API key, the project user email, and password.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>UserAuth user_auth(Web_API_KEY, USER_EMAIL, USER_PASS);<\/code><\/pre>\n\n\n\n<p>This creates a <span class=\"rnthl rntliteral\">FirebaseApp<\/span> instance called <span class=\"rnthl rntliteral\">app<\/span> that refers to the Firebase application.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>FirebaseApp app;<\/code><\/pre>\n\n\n\n<p>The following lines set up the asynchronous communication framework for interacting with Firebase&#8217;s Realtime Database. Basically, you create an SSL client using the <span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> library. Then, you instantiate an Asynchronous client called <span class=\"rnthl rntliteral\">aClient<\/span> that enables secure HTTPS. This will allow you to handle network operations asynchronously.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFiClientSecure ssl_client;\nusing AsyncClient = AsyncClientClass;\nAsyncClient aClient(ssl_client);<\/code><\/pre>\n\n\n\n<p>The following line creates a <span class=\"rnthl rntliteral\">RealtimeDatabase<\/span> object called <span class=\"rnthl rntliteral\">Database<\/span>, which represents the Firebase Realtime Database.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>RealtimeDatabase Database;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Timer and Data Variables<\/h4>\n\n\n\n<p>Then create variables to track the time. We&#8217;ll send sensor readings to the database every 10 seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Timer variables for sending data every 10 seconds\nunsigned long lastSendTime = 0;\nconst unsigned long sendInterval = 10000;<\/code><\/pre>\n\n\n\n<p>Create a variable to save the user UID. The <span class=\"rnthl rntliteral\">uid<\/span> variable will be used to save the user&#8217;s UID. We can get the user&#8217;s UID after the authentication.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Variable to save USER UID\nString uid;<\/code><\/pre>\n\n\n\n<p>Create variables to save the database path and specific database nodes. We&#8217;ll update these variables later in the code when we get the user UID.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Variables to save database paths\nString databasePath;\nString tempPath;\nString humPath;\nString presPath;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">BME280 Variables<\/h4>\n\n\n\n<p>Then, create an <span class=\"rnthl rntliteral\">Adafruit_BME280<\/span> object called <span class=\"rnthl rntliteral\">bme<\/span>. This automatically creates a sensor object on the ESP32 or ESP8266 default I2C pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme; \/\/ I2C<\/code><\/pre>\n\n\n\n<p>The following variables will hold the temperature, humidity, and pressure readings from the sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperature;\nfloat humidity;\nfloat pressure;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">initBME()<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">initBME()<\/span> function will initialize the BME280 sensor. We&#8217;ll call it later in the <span class=\"rnthl rntliteral\">setup()<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Initialize BME280\nvoid initBME(){\n  if (!bme.begin(0x76)) {\n    Serial.println(\"Could not find a valid BME280 sensor, check wiring!\");\n    while (1);\n  }\n  Serial.print(\"BME280 Initialized with success\");\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">setup()<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor, the BME280 sensor, and connect the board to your Wi-Fi network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void setup(){\n    Serial.begin(115200);\n\n    initBME();\n\n    \/\/ Connect to Wi-Fi\n    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);\n    Serial.print(\"Connecting to Wi-Fi\");\n    while (WiFi.status() != WL_CONNECTED)    {\n        Serial.print(\".\");\n        delay(300);\n    }\n    Serial.println();<\/code><\/pre>\n\n\n\n<p>Configure the SSL Client.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ssl_client.setInsecure();\n#if defined(ESP32)\n  ssl_client.setConnectionTimeout(1000);\n  ssl_client.setHandshakeTimeout(5);\n#elif defined(ESP8266)\n  ssl_client.setTimeout(1000); \/\/ Set connection timeout\n  ssl_client.setBufferSizes(4096, 1024); \/\/ Set buffer sizes\n#endif<\/code><\/pre>\n\n\n\n<p>The following line initializes the Firebase app with authentication and sets the <span class=\"rnthl rntliteral\">processData()<\/span> as the callback function for async results (this means that any results from the <span class=\"rnthl rntliteral\">initializeApp()<\/span> function will be handled on the <span class=\"rnthl rntliteral\">processData()<\/span> callback function).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>initializeApp(aClient, app, getAuth(user_auth), processData, \"\ud83d\udd10 authTask\");<\/code><\/pre>\n\n\n\n<p>Then, tell that you want to set the <span class=\"rnthl rntliteral\">Database<\/span> object defined earlier as a database for our Firebase <span class=\"rnthl rntliteral\">app<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>app.getApp&lt;RealtimeDatabase&gt;(Database);<\/code><\/pre>\n\n\n\n<p>Finally, set the database URL.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Database.url(DATABASE_URL);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">loop()<\/h4>\n\n\n\n<p>The Firebase library we&#8217;re using works asynchronously and with callback functions. This means that when an event happens, the corresponding assigned callback functions will run. To keep the Firebase app running, handling authentication and asynchronous tasks, we need to add <span class=\"rnthl rntliteral\">app.loop()<\/span> at the start of our <span class=\"rnthl rntliteral\">loop()<\/span> function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void loop(){\n  app.loop();<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">app.ready()<\/span> command checks if Firebase authentication is complete and ready, so that we can proceed with other Firebase operations (like writing to the database).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (app.ready()){<\/code><\/pre>\n\n\n\n<p>The following lines check if 10 seconds (<span class=\"rnthl rntliteral\">sendInterval<\/span>) have passed. We&#8217;ll use this to send data periodically every 10 seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Periodic data sending every 10 seconds\nunsigned long currentTime = millis();\nif (currentTime - lastSendTime >= sendInterval){\n   \/\/ Update the last send time\n  lastSendTime = currentTime;<\/code><\/pre>\n\n\n\n<p>After a successful authentication, we&#8217;ll get the user UID and save it in the <span class=\"rnthl rntliteral\">uid<\/span> variable. Then, we&#8217;ll update the database path to <span class=\"rnthl rntliteral\">UsersData\/&lt;USER_UID><\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>  \/\/ Get User UID\n Firebase.printf(\"User UID: %s\\n\", app.getUid().c_str());\n uid = app.getUid().c_str();\n databasePath = \"UsersData\/\" + uid;<\/code><\/pre>\n\n\n\n<p>Then, we&#8217;ll update the path for each node where the readings will be saved.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Update database path for sensor readings\ntempPath = databasePath + \"\/temperature\"; \/\/ --> UsersData\/&lt;user_uid>\/temperature\nhumPath = databasePath + \"\/humidity\"; \/\/ --> UsersData\/&lt;user_uid>\/humidity\npresPath = databasePath + \"\/pressure\"; \/\/ --> UsersData\/&lt;user_uid>\/pressure<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get Sensor Readings<\/h4>\n\n\n\n<p>Then, we get new sensor readings and save them in the <span class=\"rnthl rntliteral\">temperature<\/span>, <span class=\"rnthl rntliteral\">humidity<\/span>, and <span class=\"rnthl rntliteral\">pressure<\/span> variables.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> \/\/ Update database path for sensor readings\n tempPath = databasePath + \"\/temperature\"; \/\/ --> UsersData\/&lt;user_uid>\/temperature\n humPath = databasePath + \"\/humidity\"; \/\/ --> UsersData\/&lt;user_uid>\/humidity\n presPath = databasePath + \"\/pressure\"; \/\/ --> UsersData\/&lt;user_uid>\/pressure<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Send Data to the Database<\/h4>\n\n\n\n<p>To send data to the database we use <span class=\"rnthl rntliteral\">Database.set()<\/span>. This is templated to support different data types. Here\u2019s the general syntax and the arguments:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Database.set&lt;T&gt;(AsyncClient &amp;client, const String &amp;path, T value, AsyncResultCallback callback, const String &amp;uid);<\/code><\/pre>\n\n\n\n<p>Let&#8217;s break down how it works: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">&lt;T&gt;<\/span> refers to the data type. In the code, it\u2019s used as <span class=\"rnthl rntliteral\">Database.set&lt;String&gt;<\/span>, <span class=\"rnthl rntliteral\">Database.set&lt;int&gt;<\/span> and <span class=\"rnthl rntliteral\">Database.set&lt;float&gt;<\/span>. You can use other data types.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">AsyncClient &amp;client<\/span>: this is the asynchronous client object (<span class=\"rnthl rntliteral\">aClient<\/span> in the code) that manages the network connection to Firebase.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">const String &amp;path<\/span>: specifies the path in the Firebase Realtime Database where the data will be written. The path is relative to the database root (defined by <span class=\"rnthl rntliteral\">DATABASE_URL<\/span>). For example: <span class=\"rnthl rntliteral\">&#8220;test\/string&#8221;<\/span>.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">T value<\/span>: the value to be written to the specified path.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">AsyncResultCallback callback<\/span>: a function pointer to the callback that handles the result of the asynchronous operation. In the code, this is the <span class=\"rnthl rntliteral\">processData()<\/span> function. It processes the <span class=\"rnthl rntliteral\">AsyncResult<\/span> object to log events, errors, debug messages, or successful payloads. The callback is called when the Firebase server responds or if an error occurs during the request.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">const String &amp;uid<\/span>: a unique identifier for the task, used to track the specific operation in the callback. This helps differentiate between multiple asynchronous tasks in the <span class=\"rnthl rntliteral\">processData()<\/span> function.<\/li>\n<\/ul>\n\n\n\n<p class=\"rntbox rntclblue\">Learn more: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-realtime-database\/\">ESP32: Getting Started with Firebase (Realtime Database)<\/a><\/p>\n\n\n\n<p>In our example, we&#8217;ll send float variables. We use the <span class=\"rnthl rntliteral\">set()<\/span> function as follows to send the readings to their specific database node paths.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Database.set&lt;float>(aClient, tempPath, temperature, processData,\"RTDB_Send_Temperature\");\nDatabase.set&lt;float>(aClient, humPath, humidity, processData, \"RTDB_Send_Humidity\");\nDatabase.set&lt;float>(aClient, presPath, pressure, processData, \"RTDB_Send_Pressure\");<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Process the Async Results<\/h4>\n\n\n\n<p>Finally, the <span class=\"rnthl rntliteral\">processData()<\/span> function logs the results of the asynchronous Firebase operations.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void processData(AsyncResult &amp;aResult) {\n  if (!aResult.isResult())\n    return;\n\n  if (aResult.isEvent())\n    Firebase.printf(\"Event task: %s, msg: %s, code: %d\\n\", aResult.uid().c_str(), aResult.eventLog().message().c_str(), aResult.eventLog().code());\n\n  if (aResult.isDebug())\n    Firebase.printf(\"Debug task: %s, msg: %s\\n\", aResult.uid().c_str(), aResult.debug().c_str());\n\n  if (aResult.isError())\n    Firebase.printf(\"Error task: %s, msg: %s, code: %d\\n\", aResult.uid().c_str(), aResult.error().message().c_str(), aResult.error().code());\n\n  if (aResult.available())\n    Firebase.printf(\"task: %s, payload: %s\\n\", aResult.uid().c_str(), aResult.c_str());\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>Upload the previous code to your board. The code is compatible with both the ESP32 and ESP8266 boards. Don&#8217;t forget to insert your network credentials, project API key, database URL, user email, and the corresponding password.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200 and check that everything is working as expected.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"534\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Send-BME280-Readings-to-Firebase-RTDB-Serial-Monitor.png?resize=750%2C534&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Send BME280 Sensor Readings to Firebase RTDB - Serial Monitor\" class=\"wp-image-169580\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Send-BME280-Readings-to-Firebase-RTDB-Serial-Monitor.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Send-BME280-Readings-to-Firebase-RTDB-Serial-Monitor.png?resize=300%2C214&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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 user UID\u2014this is a way to restrict access to the database.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"518\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Data-Written-to-Firebase-RTDB-Under-Users-Node.png?resize=745%2C518&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Sensor Readings on Firebase Realtime Database\" class=\"wp-image-169578\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Data-Written-to-Firebase-RTDB-Under-Users-Node.png?w=745&amp;quality=100&amp;strip=all&amp;ssl=1 745w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-Data-Written-to-Firebase-RTDB-Under-Users-Node.png?resize=300%2C209&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/figure><\/div>\n\n\n<p>And that&#8217;s it. You&#8217;ve successfully sent sensor readings to the Firebase Realtime Database, and you protected the data using database rules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"wrapping-up\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you&#8217;ve learned how to authenticate the ESP32\/ESP8266 as a user with email and password, send sensor readings to the database, and set up security rules to protect your database and restrict access.<\/p>\n\n\n\n<p>In <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">PART 2<\/a>, we&#8217;ll create a <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">Firebase Web App with authentication (login with email and password)<\/a> that displays the sensor readings saved in the database. Only an authorized logged-in user can access the data. Later, you&#8217;ll be able to modify that project to display all sorts of data and restrict or allow access to the data to specific users.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful.<\/p>\n\n\n\n<p><strong>&gt;&gt; <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">Continue to Part 2: ESP32\/ESP8266: Firebase Web App to Display Sensor Readings (with Authentication)<\/a><\/strong><\/p>\n\n\n\n<p>If you like Firebase projects, take a look at our eBook. We&#8217;re sure you&#8217;ll like it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the ESP32 and ESP8266 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\" title=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">Free ESP32 Projects and Tutorials<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\" title=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">Free ESP8266 Projects and Tutorials<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to send BME280 sensor readings to the Firebase Realtime Database using the ESP32 or ESP8266 NodeMCU boards. The ESP board will authenticate as a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32\/ESP8266 Firebase: Send BME280 Sensor Readings to the Realtime Database\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-bme280-rtdb\/#more-107399\" aria-label=\"Read more about ESP32\/ESP8266 Firebase: Send BME280 Sensor Readings to the Realtime Database\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":169585,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264],"tags":[],"class_list":["post-107399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-ESP8266-Firebase-RTDB-Sensor-Readings-Authentication.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=107399"}],"version-history":[{"count":26,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107399\/revisions"}],"predecessor-version":[{"id":169587,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107399\/revisions\/169587"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/169585"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=107399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=107399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=107399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}