Cloud storage for your IoT projects
On Fire

Lead Image © Fernando Cortés, 123RF.com
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
Direct Download
Read full article as PDF:
Price $2.95
News
-
Apple M1 Hardware Support to be Merged into Linux Kernel 5.13
Linux users will be able to install their favorite distribution on Apple’s M1-based hardware.
-
KDE Launches the Qt 5 Patch Collection
To support and maintain a stable Qt 5 for KDE Gears and Frameworks, KDE will maintain a patch collection.
-
Linux Creator Warns Next Kernel Could be Delayed
Linus Torvalds has issued concern about the size of kernel 5.12 and possible delays for its release.
-
System76 Updates its Pangolin Laptop
System76 has released a much-anticipated AMD version of their most popular laptop, the Pangolin.
-
New Debian-Based Distribution Arrives on the Market
TelOS is a new Debian-based Linux distribution with a customized, touch-screen-ready KDE Plasma 5 desktop.
-
System76 Releases New Thelio Desktop
One of the most ardent supporters of open source hardware has released a new desktop machine for home or office.
-
Mageia 8 Now Available with Linux 5.10 LTS
The latest release of Mageia includes improved graphics support for both AMD and NVIDIA GPUs.
-
GNOME 40 Beta has been Released
Anyone looking to test the beta for the upcoming GNOME 40 release can now do so.
-
OpenMandriva Lx 4.2 has Arrived
The latest stable version of OpenMandriva has been released and offers the newest KDE desktop and ARM support.
-
Thunderbird 78 Ported to Ubuntu 20.04
The Ubuntu developers have made the decision to port the latest release of Thunderbird to the LTS version of the platform.