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