Serverless IoTs with Firebase Realtime Database and ESP8266

Part2 — ESP8266 Setup

Raster
4 min readJul 9, 2019

From Part1 of Serverless IoTs with Firebase RTDB, we set up the Firebase RTDB already with the project name “ESP8266 Firebase Project” and project ID “esp8266-firebase-project”.

This part of the story, we will be wiring the circuits, install Firebase Arduino Library for ESP8266 in Arduino IDE, connect ESP8266 to Firebase RTDB and test for storing and reading the data from the database.

Hardware

All ESP8266 boards supported by the Firebase RTDB library we used.
Here is the circuit for two nodes (Wemos D1 Mini module).

Each node consists of one push-button, one LED, and two resistors (200 and 4.7 k ohms).

We will turn the LED1 (GPIO4 or D2) on Node 1 (U1), ON and OFF by pushing the button S2 (GPIO5 or D1) on Node2 (U2) and also LED2 (GPIO4 or D2) on Node 2 (U2) will be controlled by push button S1 (GPIO5 or D1) on Node1 (U1).

Installing the ESP8266 Add-on on Arduino IDE (Core SDK)

Add the additional board manager URL to add the predefined hardware configuration to Arduino IDE.

  1. Go to menu File > Preferences to open the Preference window.

From the Preference window, click at the button next to the input box “Additional Boards Manager URLs:”

Copy this URL to the text box http://arduino.esp8266.com/stable/package_esp8266com_index.json

Press OK and OK to exit from the Preference window.

2. Install the ESP8266 core libraries and its toolchains (ESP8266 Core SDK for Arduino) for code compilation and build.

Go to menu Tools > Board:xxxxx > Boards Manager…

From Boards Manager window, search “esp8266” then choose the version to install, click the install button. Recommend to install the latest version.

From the image below, version 2.5.1 was installed.

Now you’re ready to use Arduino IDE to code, compile and upload your program. The next step is to install the Firebase Arduino library for ESP8266

Firebase Arduino Library installation

We will use the Firebase Arduino Library for ESP8266 from here https://github.com/mobizt/Firebase-ESP8266

For Arduino IDE and PlatformIO, this library is available from the Library Manager.

This story, we will show you how to program in Arduino IDE.

From Arduino IDE, open Library Manager Window by going to menu Sketch > Include Library > Manage Libraries…

Search “firebase” in Library Manager, select Firebase ESP8266 Client by Mobizt, choose the latest version, 2.1.6 in this example, and click Install button and close this window.

Now you’re prompt to code your Firebase RTDB program for IoTs.

Arduino Sketch for Node1 (U1)

Arduino Sketch for Node2 (U2)

The result

When you turn on/off button or switch one on Node 1, the LED2 on Node 2 will be ON/OFF, and on the other hand, when you turn on/off button or switch two on Node1, the LED1 on Node1 will be ON/OFF.

Here is the data in your Firebase RTDB looks like.

--

--