Cloud storage for your IoT projects
On Fire
IoT projects on the Google Firebase platform promise future expandability and features.
For many Internet of Things (IoT) projects, a message-queuing system like Message Queue Telemetry Transport (MQTT) is all you need to connect sensors, devices, and graphic interfaces. If, however, you require a database with sorting, queuing, and multimedia support, some great cloud storage platforms are available, and one that is definitely worth taking a look at is Google Firebase.
Like any IoT solution, Google Firebase can take various programmatic and sensor data inputs and has a variety of client applications to view the data (Figure 1). However, Google Firebase also offers other features, such as file storage, machine learning, messaging, and server-side functions. In this article, I will:
- set up a sample Firebase IoT project,
- use Python to simulate I/O data,
- create a web dashboard with Node-RED to view and write data,
- create an Android app with App Inventor to view and write data, and
- look at a more complex data monitoring example in Python.
Getting Started
Google Firebase [1] might not have the huge variety of options that Amazon Web Services (AWS) has, but I found as an IoT engineer that Google Firebase had all the features I need to get up and running quickly, and I don't need a credit card for my free activation.
To begin, log in with your Google account [1] and select Get Started. After I created a sample project called My-IoT, Firebase gave it a unique identifier name (e.g., my-iot-4ded7).
Firebase data can be stored in either a Firebase Realtime Database or a Cloud Firestore. The Realtime Database is an unstructured NoSQL format that has been around for about four or five years, so a lot of third-party components exist. The Cloud Firestore stores the data in structured collections and is fairly new, so the number of APIs isn't as extensive as you can find for the Realtime Database. For my test IoT project, I use the Realtime Database (Figure 2), which you can create from the Database | Data menu option.
The database structure can be built directly from the Firebase web console or imported from a JSON file. For this database, I defined three groupings, one each for Android, Node-RED, and Raspberry Pi I/O values. From the Firebase console, you can set, change, and view database values (Figure 3). Security is configured under Database | Rules.
To keep things simple for testing, I set read and write security to true
for public access, but I will have to remember to change this when I put the project into production (Figure 4). The project's remote access settings are shown in the Authentication section from the Web setup button (Figure 5).
At this point, I have an empty database, I've opened up the security, and I have the credentials for remote access, so now it's time for some programming.
Python
A number of Python libraries access Firebase. I like the pyrebase library because it has some added functionality, such as queries, sorting, file downloads, and streaming support. The pyrebase library only supports Python 3, and it needs an upgrade of the Google authorization library:
sudo pip3 install pyrebase sudo pip3 install --upgrade google-auth-oauthlib
Listing 1 is a Python example I ran on a Raspberry Pi that sets two values (pi/pi_value1
and pi/pi_value2
) in lines 15 and 16 and reads a single point (lines 19 and 20) and a group of points (lines 23 to 25). Remember to change the configuration settings to match your project's security credentials. From the Firebase web console, you can check the results from the test program.
Listing 1
firebase1.py
Node-RED
Node-RED [2] is a visual programming environment that allows you to create applications by dragging and dropping nodes onto the screen and logic flows by connecting the nodes. Node-RED has been preinstalled on Raspbian Jesse since the November 2015 release and can be installed on Windows, Linux, and macOS, as well. You can find instructions online [3] to install and run Node-RED on your specific system.
To install the Firebase components, select the Manage palette option from the right side of the menubar, then search for firebase, and install the node-red-contrib-firebase module (Figure 6).
For my Node-RED example, I use web gauges to show two Python simulated test points and send a text comment back to the Firebase database. The complete Node-RED logic (Figure 7) only needs six nodes.
To read the Raspberry Pi values, I use two firebase.on()
nodes, and to set the Firebase database and data point information (Figure 8), I double-click these nodes. The Firebase field has an edit (pencil) button that allows you to enter your project credentials. To write or set a value in Firebase, you configure a firebase modify
node.
The output from the firebase.on()
node is connected to two dashboard gauge
nodes. Double-clicking on the gauge
node allows you to edit its labels and ranges and create a dashboard layout. A text input
node lets you enter text from a web dashboard that then can be passed into Firebase.
After the logic is complete, hit the Deploy button on the right side of the menubar to run the logic. The Node-RED dashboard user interface is accessed at http://<ipaddress>:1880/ui (e.g., http://192.168.1.108:1880/ui) (Figure 9).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.