Cloud storage for your IoT projects
App Inventor
App Inventor [4] [5] is a web-based Android app creation tool with a graphical programming environment. App Inventor has two main screens: the Designer screen, on which you lay out the Android app, and the Blocks screen, where you build the logic. On the right side of the top menubar, the Designer and Blocks buttons allow you to toggle between the two screens.
On the Designer screen, an app layout is created by dragging a component from the Palette window onto the Viewer. The App Inventor Android app I create here will read Raspberry Pi values from the Firebase IoT database and write a value back.
The visual layout of this application uses a Button, two Labels, a ListView, and a TextBox component. A non-visual FirebaseDB component connects to the Firebase Realtime Database (Figure 10). After a component is added to the application, you can rename or delete that component from the Components window. In the Properties window, you can edit the features of a component. For example, for the FirebaseDB component, I need to configure the Token and URL to match my project credentials.
Once the layout design is complete, you add logic by clicking on the Blocks button in the top menubar. To build the logic, you select an object in the Blocks window and click on the specific block you want to use.
App Inventor is pretty amazing when it comes to doing some very quick prototyping. The entire app in this example only uses two main blocks (Figure 11).
The when FirebaseDB1.DataChanged
block is executed whenever new data arrives into the Firebase database. The DataChanged
block returns tag
and value
variables. The tag
variable is the top-level item name, (i.e., pi
in this example). The value will be a string of the items and their values, for example:
{pi_value2 = 34, pi_value1=77}
A replace all text
block removes the leading and trailing }
characters and then passes the string to the ListView component. Note this same code will pass two or 2,000 tags in the pi
tag section. The when BT_PUT.Click
block writes the text entered on the screen into the android/and_value1
item in the Firebase database.
After the screen layout and logic are complete, the Build menu item compiles the app, which can then be made available as an APK downloadable file or as a QR code link. Figure 12 shows the final Android app communicating with the Firebase Realtime Database.
Python Data Monitoring Example
The example IoT Firebase Realtime Database is quite simple. Data monitoring or Supervisory Control and Data Acquisition (SCADA) projects usually require more information than just a value. A more realistic sensor database would include fields such as a tag name, description, status, time, and units. By adding some indexing in the Firebase security rules (Figure 13), you can create queries and sort the data, such as Points in alarm or Point values between 2:00 and 2:15.
In Listing 2, the statement
tag_sum = db.child("pi").order_by_child("status").equal_to("ALARM").get()
Listing 2
firebase2.py
(line 14) shows only records that have the ALARM
status. Some other filter options include .limit_to_first(n)
, .start_at(time1).end_at(time2).get()
, and .order_by_value()
.
A good next step would be to pass important filtered information to Firebase's messaging feature.
Summary
Without a lot of configuration, you can configure a Google Firebase project and have Python, Node-RED, and App Inventor apps read and write values. The level of programming complexity is on par with an MQTT implementation; however, Google Firebase offers a lot more future functionality that you wouldn't have with MQTT, such as file storage, machine learning, messaging, and server-side functions.
Infos
- Google Firebase: https://firebase.google.com
- Node-RED: https://nodered.org
- Installing Node-RED: https://nodered.org/docs/getting-started/installation
- App Inventor project: http://appinventor.mit.edu
- App Inventor access: http://ai2.appinventor.mit.edu/
« Previous 1 2
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
-
Gnome OS Adopting systemd-sysupdate
Gnome OS is about to undergo a major under-the-hood change that promises enhanced security.
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.