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
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.