Serverless IoTs with Firebase Realtime Database and ESP8266

Raster
3 min readJul 9, 2019

--

Part 1 — Firebase RTDB Project Setup

This story is the introduction of how to make serverless IoTs using Firebase Realtime Database (RTDB) and Espressif 8266 MCU or ESP8266.

If you’re familiar with Firebase Realtime Database or set it up already, please go to Part2 — ESP8266 Setup

Prepare your Firebase RTDB

Using the web browser and go to https://firebase.google.com/ and sign in with your Google account.

After signing in, click at the GET STARTED button.

Click at Add project.

Set your project name and id. In this example, we will use the “ESP8266 Firebase Project” and “esp8266-firebase-project” for name and id, respectively. The project id is a unique id that you can access through https://your_project_id.firebaseio.com.

Tick the checkmark at I accept the controller-controller terms and click at Create project button.

Wait for your project for successfully created.

If the project created, click at the Database menu from the right navigation menus.

Now from your console screen will show the block of information that allows you to create Cloud Firestore Database, which we do not use it for our ESP8266 project.

Let scroll down to the block that shows you the option to create Realtime Database, which is supported by the ESP8266 Arduino library.

Click at Create database button to start creating the RTDB database.

Now you’ll see the popup dialog to select the security rules for RTDB.

Choose Start in locked mode or Start in test mode option.

Start in locked mode still allows us to read and write data to Firebase RTDB through REST API by providing database secret or security rules can be any if you use database secret to connect.

Click the Enable button.

After enabling the security rules, your console will show the root of your RTDB, which has a null value, which means no node is under your esp8266-firebase-project root.

Null (null) in RTDB is not evaluated as the string “null”.

We need to create the database secret which required for authentication.

Click at the gear icon on the right of the Project Overview menu.

Select the Project settings from the drop-down.

Click at the Service accounts tab.

Click at Database secrets under Firebase Admin SDK menus.

Click at Show button on the right of the Database Secrets list.

Click at Copy secret button, which this database secret will be used in ESP8266 Arduino Library to connect to Firebase RTDB.

If all of the above done, now it’s time to connect with ESP8266.

See Part 2 — ESP8266 Setup

--

--