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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
News
-
An All-Snap Version of Ubuntu is In The Works
Along with the standard deb version of the open-source operating system, Canonical will release an-all snap version.
-
Mageia 9 Beta 2 Ready for Testing
The latest beta of the popular Mageia distribution now includes the latest kernel and plenty of updated applications.
-
KDE Plasma 6 Looks to Bring Basic HDR Support
The KWin piece of KDE Plasma now has HDR support and color management geared for the 6.0 release.
-
Bodhi Linux 7.0 Beta Ready for Testing
The latest iteration of the Bohdi Linux distribution is now available for those who want to experience what's in store and for testing purposes.
-
Changes Coming to Ubuntu PPA Usage
The way you manage Personal Package Archives will be changing with the release of Ubuntu 23.10.
-
AlmaLinux 9.2 Now Available for Download
AlmaLinux has been released and provides a free alternative to upstream Red Hat Enterprise Linux.
-
An Immutable Version of Fedora Is Under Consideration
For anyone who's a fan of using immutable versions of Linux, the Fedora team is currently considering adding a new spin called Fedora Onyx.
-
New Release of Br OS Includes ChatGPT Integration
Br OS 23.04 is now available and is geared specifically toward web content creation.
-
Command-Line Only Peropesis 2.1 Available Now
The latest iteration of Peropesis has been released with plenty of updates and introduces new software development tools.
-
TUXEDO Computers Announces InfinityBook Pro 14
With the new generation of their popular InfinityBook Pro 14, TUXEDO upgrades its ultra-mobile, powerful business laptop with some impressive specs.