Connect ESP32+GSM (Sim800l) to Google Firebase to send sensor data.
As Firebase only accepts HTTPS requests, it becomes a bit difficult to send sensor data to the Real-time Database with an ESP32 and a GSM Module. I did not find any resource for this when I was doing my project, so I am keeping this here for anyone who needs it in the future.
In this project, I develop an IoT application capable of sending data to the Firbase Real-Time database using GPRS and receiving the sent data using a Python script. We utilize the following components:
Add Project
on Firebase and give a suitable name to it and Create Project
. Project Overview
and click Realtime Database
. Then Create Database
, select a preferable location for your database (doesn’t matter really) and enable Test mode
.https://xxxxx-xxxx-xxxx-xxxx.firebaseio.com/
) Project Settings
and under Service Accounts
click Database secrets
show and copy the API KEY
. This is required for authentication in sending and extracting the data.public.html
in the File manager and upload the files from the PHP server
folder. This creates a PHP server that accepts an HTTP POST
request and sends the data to Firebase.
NOTE: Do not upload the folder, just the files inside it.
upload.php
file to add the details of the database link (DEFAULT_URL
)and the API key (DEFAULT_TOKEN
). Also, keep in mind the structure of the database the $DEFAULT PATH
defines the variable under which the database will record the value. You can add additional paths by adding /<variable_name>
.8
on your real-time database.This will cover the use of Python script to extract the data from the database for processing. The library in use is a Python interface to the Firebase’s REST API.
pip install python-firebase
"</>"
with the tag add firebase to your web appvar firebaseConfig = {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "xxxxx-xxxx.firebaseapp.com",
databaseURL: "https://xxxxx-xxxxx-xxxxx-xxxxx.firebaseio.com",
projectId: "xxxx-xxxx",
storageBucket: "xxxx-xxxx.appspot.com",
messagingSenderId: "xxxxxxxxxxxxxx",
appId: "1:xxxxxxxxxxxx:web:xxxxxxxxxxxxxxxxx",
measurementId: "xxxxxxxxxxxxxxxx"
};