ラベル Firebase の投稿を表示しています。 すべての投稿を表示
ラベル Firebase の投稿を表示しています。 すべての投稿を表示

2019年4月22日月曜日

A simple demo app using ThunkableX Cloud Variables

Of the few existing App Inventors, ThunkableX has its own distinctive features. Except for being able to create common source programs (blocks) for Android and iOS, I focused on the newly introduced cloud variables. These extend the scope of traditional variables to cloud space based on the Firebase (a kind of real-time database). Normally, the database is created with a user-specific id, but if you know its URL, you can access that cloud variable. When an authorized user updates the value of a variable, the event is immediately received by other apps. Such a facility enables efficient development of database applications, etc.

An example of initializing such cloud variables is shown in Figure 1. You can see that Firebase tags can be mapped to cloud variables. Hierarchical tags can also be cloud variables, such as “fireLoc/lat”.


After initializing these cloud variables, they can be referenced in several ways. Figure 2 shows five access blocks for the cloud variable Betty. Particularly, I would like to note a block called “when Cloud Betty is initialized or changed”. This block allows you to know in real-time the updates to cloud variables, and based on that you can easily set up your application logic.


Gram app [2] is a famous example of using cloud variables. This is a very fine app, but it's somewhat complicated for general programmers. So I created a simpler demo app. Figure 3 shows that. Jack wants to know the location of his daughter Betty in real-time. But, Betty allows sending her location only when she presses a button on her smartphone.


The complete block diagram of ThunkableX that achieves this is shown in Figure 4. Figure 4(a) is for the sender, Betty; and Figure 4(b) is for the receiver, Jack. This diagram shows that using cloud variables make programming much easier. You can access the contents of the database without using Firebase blocks such as registering listeners, storing values in the database, etc. In Fig. 4(a), the location information is fetched by GetCurrentLocation and stored in the cloud variable Betty. Also, in Figure 4(b), updates to the cloud variable Betty is automatically detected, so the result is immediately reflected in the map.


References
[1] thunkable cloud variables, https://docs.thunkable.com/variables
[2] the Gram app, https://x.thunkable.com/projectPage/5bbff7e035aa10fd7702f479

2019年4月21日日曜日

Firebase GPS demo made with ThunkableX (common to Android & iOS)

ThunkableX [1] is a kind of software system of App Inventor, which makes it possible to create a common source program for Android and iOS. Some of its functions have not yet been realized, but it is a wonderful system that continues to progress. Here, we created a simple GPS demo program using ThunkbleX.

Suppose Jack and Betty want to show each other the current location on the smartphone in real time. The MIT App Inventor program that realizes it is shown in the literature [2]. It uses the real-time database Firebase, but it is assumed that both have Android devices. By contrast, this article assumes Jack has an Android device but Betty has an iPhone.

I created a ThunkableX app like Fig. 1 below. The source list (block configuration) of the app used here is common to Jack and Betty. Using the Firebase, current positions of each other are displayed in real time. When you press the send button, your location information will be stored in Firebase. Fig. 2 shows the contents of Firebase. If there is a change in the Firebase, the opponent's smartphone immediately updates the map display by seeing the change event in real time.



The whole block of ThunkableX that realizes this is shown in Fig. 3. For reference [2], registration of the listener for change event as shown in Fig. 3(1) was unnecessary. However, the reason ThunkableX needs it is probably because of the commonality with iOS. When you use Firebase, you do not need to make any settings if it is a temporary test program. However, if you use it in a full-fledged app, you will need to set up your own Firebse Database URL and API Key. Otherwise, security issues may occur.


References
[1] https://thunkable.com/#/
[2] USING FIREBASE IN A REAL APP – “HERE I AM!” GPS DEMO APP (https://appinventor.pevest.com/2016/09/13/using-firebase-in-a-real-app-here-i-am-gps-demo-app/)