Serverless IoTs with Firebase Realtime Database and ESP32

Raster
3 min readApr 3, 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 32 MCU or ESP32.

If you’re familiar with Firebase Realtime Database please go to Part2 — ESP32 Setup

Prepare your Firebase RTDB

Using web browser and goto https://firebase.google.com/ and sign in with your google account.

After signed in, click at GET STARTED button.

Click at Add project.

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

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

Wait for your project for successfully created.

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

Now from you console screen will show the block of information that allows you to create Cloud Firestore Database which we are not use it for our ESP32 project. Let scroll down to the block that show you the option to create Realtime Database which is supported by ESP32 Arduino library.

Click at Create database button to start creating 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 allow 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 Enable button.

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

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

We need to create database secret to allow ESP32 Firebase Library to connect through REST API.

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

Select Project settings from drop down.

Click at Service accounts tab.

Click at Database secrets under Firebase Admin SDK menus.

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

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

If all of above were done, now it’s time to connect with ESP32.

See Part 2— ESP32 Setup

--

--