Send Data to Firebase Using Raspberry Pi

Let's try python3 Firebase libraries on Raspberry Pi.

Introduction

Firebase (Google’s platform) is a mobile-backend-as-a-service that provides powerful features for building mobile apps. It has three core services: a realtime database, user authentication and hosting. In this tutorial, we will try to explore how to send data to Firebase using Raspberry Pi.

Video

This video show how to send sensor data to Firebase using Raspberry Pi.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python3 example program to read sensor data from MLX90614 and send it to the Firebase. It involves 3 libraries, you can install it through the following commands.

sudo pip3 install adafruit-blinka
sudo pip3 install adafruit-circuitpython-mlx90614
sudo pip3 install pyrebase
"""
Tutorial: Send Data to Firebase Using Raspberry Pi
Hardware:
– Raspberry Pi 4 Model B
– Maker pHAT
– MLX90614
References:
– https://circuitpython.readthedocs.io/projects/mlx90614/en/latest/
– https://github.com/thisbejim/Pyrebase
"""
import time
import board
import busio as io
import adafruit_mlx90614
import pyrebase
i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
mlx = adafruit_mlx90614.MLX90614(i2c)
config = {
"apiKey": "database-secret",
"authDomain": "project-id.firebaseapp.com",
"databaseURL": "https://database-url.firebaseio.com",
"storageBucket": "project-id.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
print("Send Data to Firebase Using Raspberry Pi")
print("—————————————-")
print()
while True:
ambientString = "{:.2f}".format(mlx.ambient_temperature)
objectString = "{:.2f}".format(mlx.object_temperature)
ambientCelsius = float(ambientString)
objectCelsius = float(objectString)
print("Ambient Temp: {} °C".format(ambientString))
print("Object Temp: {} °C".format(objectString))
print()
data = {
"ambient": ambientCelsius,
"object": objectCelsius,
}
db.child("mlx90614").child("1-set").set(data)
db.child("mlx90614").child("2-push").push(data)
time.sleep(2)

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
TinyML on Arduino using Edge Impulse
Tutorials of Cytron Technologies Scroll to Top