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
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.