Cloud storage for your IoT projects

On Fire

Lead Image © Fernando Cortés,

Lead Image © Fernando Cortés,

Article from Issue 223/2019

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.
Figure 1: Firebase IoT overview.

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.

Figure 2: Creating a Firebase Realtime Database.

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.

Figure 3: Create/view a database structure.

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).

Figure 4: Firebase database security.
Figure 5: Firebase authentication information.

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.


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



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).

Figure 6: Installing Firebase on Node-RED.

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.

Figure 7: Node-RED logic.

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.

Figure 8: Firebase input configuration.

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., (Figure 9).

Figure 9: Node-RED web dashboard.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux newsletters