This is an old revision of the document!


Lab 4: Databases for IoT

In this lab assignment we'll explore hot to leverage online databases to write and read sensor data from an IoT application and access this data from anywhere in the world. We'll use two similar DB platforms: InfluxDB and Firebase.

Firebase

Firebase is Google’s set of hosting services for mobile applications, which comprises a wide range of solutions to manage data from Android, iOS or web applications. We will use the real-time database solution from Firebase (RTDB) and we will store and read values from the DB using our ESP32 boards.

We can send and receive data with the ESP32 board to/from Firebase from anywhere in the world, as long as we have an Internet connection. This, coupled with the fact that we can create a web app that can be accessed anywhere with an Internet connection makes Firebase a very powerful tool, as you can manage, monitor, automate and send commands to an IoT application remotely.

First step is to create a Firebase project with a real-time database and use the ESP32 to write and read data from this database.

Set Up New Firebase Account

  • Sign in to Firebase with your Google account
  • Click Get Started, and then Create Project to create a new project
  • Give a name to your project, for example: ESP32 Firebase
  • Click to Disable Google Analytics (we don't need it for this simple demo)

If everything went well, you should be able to see your project page displayed in a few seconds.

Set Authentication Method

We need to set an authentication method for our app.

In the left sidebar, click on Build → Authentication → Get Started

There are several authentication methods from different sign-in providers. For the purpose of this app where the ESP32 board connects directly to the Firebase app, we can select to have no authentication. Select Anonymous from the list, click to enable and the Save.

Create Real-Time Database

In the left sidebar, click on Build → Realtime Database → Create Database. In the pop-up window that appears, select the DB location (recommended to select the Belgium site) and “Start in Test Mode” in the next tab, then click Enable.

Your database is now created, you will need to copy the URL in the web page, as we will be using it from the ESP32 side to connect to our database.

You'll also need to get the API key, by clicking on the cog next to Project Overview:

With this, you're all set up on the DB side!

Program ESP32 to Connect to the DB

We will use the Firebase-ESP-Client library, which we will need to install.

  1. Go to Sketch > Include Library > Manage Libraries
  2. Search for Firebase ESP Client and install the Firebase Arduino Client Library for ESP8266 and ESP32 by Mobitz.
iothings/laboratoare/2022/lab4.1666872150.txt.gz · Last modified: 2022/10/27 15:02 by dan.tudose
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0