All posts by edwardm

Using Firebase in a real app – “Here I AM!” GPS Demo app

A previous post introduced the experimental Firebase component in MIT App Inventor. Firebase is a cloud-based database that may be used by App Inventor apps, and which makes exchanging data between users easy. Note: Firebase is experimental and may change in the future. At the present time, there is one Firebase database that is shared by all users. See comments in previous post for more information.

This post uses the GPS location sensors in phones to determine the phone’s position in latitude and longitude. Pressing a button labeled “Send GPS” sends the latitude and longitude coordinates to another phone, which then draws the position on a map. In this way, two phone users can wander about and transmit their location to each other, sending the data through the Firebase cloud database. I named this app “Here I AM!” – pressing the Send GPS tells another user that “I am here!”

User Interface

To use this app, the exact same app should be running on two separate phones. You can run it on a single phone but obviously, you will not be getting updates from anyone else!

The first time you run this app on Android 6, you will be asked to give permission to use location information. Also, be sure to set Location services to on, in Android Settings.

As you move about, press the Send GPS button.  Your latitude and longitude will be sent to Firebase, the other app will be alerted to an updated location, and your location will be displayed on the Google maps on their phone. If they press Send GPS, then their location will be updated on your phone.

The Lat/Long. textbox displays either the latitude, longitude or is prefixed with “THEM:”. “THEM:” means the textbox is showing the other phone’s location; if “THEM:” is not shown, then the textbox is showing your own latitude, longitude.

Screenshot_20160913-102744

Press Retrieve GPS to retrieve and display the latitude/longitude value currently stored in Firebase.

Press Show Map to display the  last retrieved location on the map.

Continue reading Using Firebase in a real app – “Here I AM!” GPS Demo app

Some computer joke in this

Saw this sign at a campground, identifying 4 separate roadway loops where people may camp.

For programmers, this sign is amusing. “A Loop”, and “BCD Loops”. BCD stands for binary coded decimal, which is a way of storing decimal numbers for financial calculations. I know, bad joke – but one of those things that makes us software developers have a good laugh 🙂

OLYMPUS DIGITAL CAMERA
OLYMPUS DIGITAL CAMERA

MIT Professor Seymour Papert, passed away 31 July 2016

MIT Professor Seymour Papert was a forward looking visionary who pioneered the adoption of computing concepts in children’s education, including the development of Logo, Mindstorms and turtle programming. His distant work back in the 1960s and 1970s lay the foundation for today’s use of MIT App Inventor in children’s education. His contributions to education and computing are greatly appreciated.

Much more about Paupert’s background may be read in the NY Times or in this essay by a colleague here.

Demonstration app for using FirebaseDB in AppInventor

FirebaseDB provides for sharing between users all running the exact same app on their device. Read “What is FirebaseDB?” to learn more about FirebaseDB and what it does for your applications.

This is a quick and very short app that demonstrates the fundamental operation of FirebaseDB when used in MIT App Inventor. I hope to create a more interesting demo app a bit later.

Caution: FirebaseDB is an experimental component offered by MIT App Inventor. FirebaseDB remains under development and is subject to change; apps written today might not work in the future. Apps containing the FirebaseDB component will not work in the emulator – run on your phone or tablet instead. At this time, the cloud-based database is a shared database, shared among multiple users, and cannot – yet – be linked to your personal Google account.

FirebaseDB is Similar to TinyWebDB

The programming interface for FirebaseDB is nearly the same as that used for TinyWebDBTinyWebDB is a simple cloud-based database – to use, you need to set up the TinyWebDB on your own server or on Google’s servers. With your data stored in the “cloud”, your data may be shared among many apps. For the FirebaseDB demo, you do not need to set up your own server, nor do you need to use TinyWebDB:

For details on setting up and using TinyWebDB – including some tricks that enable sharing of TinyWebDB data between apps – please see my book,

  • App Inventor 2 Databases and Files (Volume 3 e-book)
    Step-by-step TinyDB, TinyWebDB, Fusion Tables and Files
    Buy from: Amazon, Google Books, Kobo Books

For more information, including a sample chapter, please see my App Inventor books page.

Sample App User Interface

Our simple demonstration app stores and retrieves a text value to and from the FirebaseDB. As with TinyDB or TinyWebDB, enter a “tag” value to use to look up the value. For example, a tag value could be a part number, and the value could be the text description of the part’s name. Or the tag could be a phone number and the value could be the name of the person who has that phone number.

Screenshot_20160815-152608

The program is operated by entering a tag and a value and then pressing the Store Value button. The value entered is written to the FirebaseDB database in the cloud.

After a value has been stored, you retrieve values by entering the original tag and pressing Retrieve Value. The data corresponding to the tag is retrieved from FirebaseDB and display in the Value field, on screen.

If the app is run simultaneously on other devices, any data updates made on the other devices result in all devices receiving a data changed notification. When the data in the FirebaseDB is changed, the new data is displayed on all devices.

Designer View

A combination of vertical and horizontal layouts is used to organize the positions of the controls (see the Components list, below, or download the sample code).

Store Value and Retrieve Value are buttons. Tag and Value are labels, followed by text boxes for data entry.  Data Changed Event and the status message are both labels.

Drag the FirebaseDB component from the Experimental section of the Designer controls palette. You will receive a warning that FirebaseDB is experimental.

FirebaseDesigner

FBDemo_Components

Blocks View

(Sorry for the image quality on these three blocks – the screen capture utility I used for these did not do a very good job)

The btnStoreValue event handler reads the enter tag and data value from the text boxes on screen, and then stores those to the FirebaseDB. Find the FirebaseDB StoreValue component by clicking on the FirebaseDB component in the Blocks list.

FirebaseBlocks1

Fetching a store value is simple – call FirebaseDB’s GetValue method and pass to it the tag. Unlike TinyDB (but similar to TinyWebDB), the value is not read instantaneously but instead, once the data is read and available, an event called GotValue occurs.  A GotValue event handler processed the incoming data; in our simple app, the data is stored back in to the Value text box, on screen.

FirebaseBlocks2

A unique feature of FirebaseDB is the database’s ability to alert apps that data inside the database has been changed. This alert caused a DataChanged event to occur – and which delivers the tag and value that were updated to the app.

FirebaseBlocks3

Reminder

FirebaseDB is experimental and incomplete, is subject to change, and should not be relied upon at this time for production code. However, you may use it for learning and experimentation.

Download Source Code

Download: FirebaseDB_Demo.aia

After downloading to your computer, you may upload the file to your App Inventor account using Projects | Import project (.aia) from my computer

Related Tutorials

 

Fewer professional coders in the future?

That is the actual future of software development: It will become so easy and second nature, that for ordinary tasks you won’t even have to think about it.

Source: Dear Google, the future is fewer people writing code | TechCrunch

Tools like MIT App Inventor, and others, are making programming so easy that it no longer requires extensive training and high levels skills to create many types of useful programs.

Specifically,

Writing code will become less and less necessary, making software development more accessible to everyone. This will allow people to solve new and unique problems for themselves, and true software engineers will continue to find ways to empower others through various platforms.

We used to call people who wrote programs, programmers. Later, this was change to titles like software developer, software engineer or sometimes computer engineer. Today, the media has short circuited the entire field to just “coders”, which seems like a downgrading of skills and title.

What is the FirebaseDB?

Hidden at the bottom of the Designer palette, is a category labeled Experimental and within that, there is a single item, the FirebaseDB:

Firebase

What is FirebaseDB?

FirebaseDB provides a database “in the cloud” for your MIT App Inventor apps and supports the sharing of data between users simultaneously. When data in your FirebaseDB is changed, all apps are alerted to the updated data.

At this time, FirebaseDB is an experimental feature with critical limitations – notably you cannot yet set up your own personal FirebaseDB account but must instead use a single FirebaseDB run by MIT as a “shared account”. Sharing is limited to all users of a single app, and is not available between different apps.

FirebaseDB is Similar to TinyWebDB

The programming interface for FirebaseDB is nearly the same as that used for TinyWebDB. TinyWebDB is a simple cloud-based database – to use, you need to set up the TinyWebDB on your own server or on Google’s servers. With your data stored in the “cloud”, your data may be shared among many apps.

For details on setting up and using TinyWebDB – including some tricks that enable sharing of TinyWebDB data between apps – please see my book,

  • App Inventor 2 Databases and Files (Volume 3 e-book)
    Step-by-step TinyDB, TinyWebDB, Fusion Tables and Files
    Buy from: Amazon, Google Books, Kobo Books

For more information, including a sample chapter, please see my App Inventor books page.

Continue reading What is the FirebaseDB?