This is a demonstration of IoT using Firebase Realtime Database. It is very beginner friendly and can easily be implemented in firebase without knowing backend infrastructure and hosted across the world, and so can be accessed from anywhere!
- Firebase - to host a dashboard page and to make a realtime database
- Node Package Manager or npm from Node.js
- A NodeMCU - which is an ESP8266 based microcontroller kit/board
- Arduino IDE - arduino.cc
- Some LEDs, resistors, sensors and other components as per requirement, to test this project.
→ Clone this repository
→ Host the index.html
inside the Webpage
folder, on firebase hosting
→ Create a Realtime Database on Firebase
→ Head over to the Firebase-basic-iot
folder
→ Open the Firebase-basic-iot.ino
file with Arduino
→ Set the board as generic ESP8266
→ Upload
-
We are using Firebase Realtime Database and Firebase Hosting services, those are available under the spark plan with certain limitations, but it won't be an issue for our purpose.
├── Realtime Database - To store the states and Values and communicate with the IoT device(s)
└── Firebase Hosting - Hosts an web app to interact with the realtime database -
Detailed instructions about firebase integration are available on this page!
-
Firebase Hosting:
├── Go to theWebpage
folder in this repository
└── Theindex.html
contains basic html, styling, and the scripting to connect to the firebase database -
Firebase Realtime Database:
├── Realtime Database in Firebase is a big nested JSON which holds all the Key and Value pairs
└── The values can be changed both from the device and from the web page based on certain logic
Go through this repository for all the instructions including the schematic diagrams.
- Note: If you are working with NodeMCU on Arduino IDE for the first time, you may go ahead and take a look into the NodeMCU setup instructions!
-
At first download the FirebaseESP8266.h library.
-
Then navigate to the Firebase-basic-iot folder and make a file named
config.h
.
Put,
#inlcude FIREBASE_HOST "PROJECT_ID.firebaseio.com"
and
#include FIREBASE_AUTH "DATABASE_SECRET"
insideconfig.h
.- You will find these credentials inside settings of your firebase console page -> choose your firebase project -> Realtime Database -> Data copy the URL you see above the DB table, replace
PROJECT_ID.firebaseio.com
in the macroFIREBASE_HOST
with that URL. Note that the URL may not end withfirebaseio.com
, as in this case, you can see it ends withfirebasedatabase.app
.
- And, ⚙ -> project settings -> Service accounts -> Database Secrets, click Show and then copy the database secret and replace it with
DATABASE_SECRET
inconfig.h
- You will find these credentials inside settings of your firebase console page -> choose your firebase project -> Realtime Database -> Data copy the URL you see above the DB table, replace
-
Your code is now ready, compile it, plug the USB to Node MCU, select the proper board and port(mentioned earlier) and upload!
-
Keep the USB connected to NodeMCU to access the serial monitor in case you want to debug!
Type the URL from your Firebase Hosting page, if you did everything properly, you will see something like this:
-
You have successfully hosted an webpage on firebase to control your IoT device using Firebase RTDB.