MIT’s App Inventor

AI2 LogoI have recently discovered MIT App Inventor 2 for building Android apps and I must say I’m quite impressed. Before that, I had learnt some basics of Java and taken on learning Android and the Android Studio IDE — with some success, but not beyond the point of being able to create a basic activity screen with a few buttons.Then I decided to have a go at App Inventor… and after a couple of hours following a few tutorials, short and to the point, I was already able to do much more: build UIs, draw on the screen, animate sprites, take pictures…

Mind you, I’m not saying App Inventor is anywhere near as powerful as Android Studio for instance, nor that it can be used to build very elegant, fluid or complex Apps. It does have limitations and implementing, for example, non-trivial control structures or math operations quickly becomes awkward. Still, I find it extremely valuable as, with very limited effort, it enables anyone to prototype decent Apps and come up with relevant proofs of concept for projects that involve App-based interactions.

 

Using App Inventor 2 (AI2) with LimiFrog

If I’m writing about MIT App Inventor in this blog, of course, it is because it has an interest in the context of LimiFrog.

LimiFrog can communicate over Bluetooth Low Energy  (BLE) with a smartphone… provided the right App is available on the smartphone side. The software package provided on GitHub does contain an Android example application interacting with a LimiFrog running the DSPS (Dialog Serial Port Service) custom profile from Dialog, which provides a “UART-over-BLE” functionality. However you need some Android coding skills to modify it and adapt it to your needs. Therefore I thought it would be interesting to try and create a BLE communication example based on MIT’s App Inventor.

 

BLE in App Inventor 2 (AI2)

In addition to the many widgets supported “out of the box” by App Inventor, the MIT is providing an optional toolbox for BLE support. It is still in development and therefore not yet offered as standard, nevetheless it is possible to download it as an extension to the standard package.  As such, it does have limitations, but I was interested to see to what extent it could be used to interact with LimiFrog.

Here is the set up :

– LimiFrog is configured to run the DSPS (Dialog Serial Port Service), a custom GATT profile provided by Dialog. See LimiFrog documentation and have a look, for example, at project 7_LimiFrog_UnitTest_BLE_Device.

– a smartphone (with BLE capability of course) running at least Android 5 (Lollipop) is required.  Although Android has been supporting BLE since Android 4.3, the MIT took a shortcut to Android 5 to keep clear of possible problems with earlier implementations by some manufacturers that could behave inconsistently (some details in this thread )

I created a demo app under AI2 to connect with LimiFrog through BLE and exchange data with it. The source code is here (to be clear: I’ve tested it on my smartphone only and I do not guarantee the rendering will be correct on any Android phone).  Once you have created your AI2 account (very simple, but you need a Google account in the first place) you can import this .aia source package and explore, test or modify the code. AI2 enables easy live testing on your smartphone (just need to install MIT’s “AI2 Companion App” first), with the App under test downloaded over WiFi. Once you’re happy with your code, AI2 can package it as a standard Android App (.apk) and save it or directly install it on your phone.

 

Here is a snapshot of the App Inventor “designer” perspective:

Screen_Capture_App_Inventor

and here is a portion of the “Blocks” perspective, where the response to events is implemented using predefined methods etc. through a graphical interface :

AI2_Blocks_Snapshot

If you know Scratch, that should look familiar. However while I see Scratch just as a good tool to teach the basics of programming and algorithms to kids, I think App Inventor can serve a much wider audience.

And here’s what the actual display looks like when in use :

App_Inventor_on_Smartphone

The user interface of this example App is deliberately designed to expose different steps in BLE connection and transfer:

  • the Start Scan button instructs the App to look for nearby BLE devices advertizing their presence. The devices found (ID + RSSI) are then listed below that button.
  • The user can select the index (1 for first device displayed, etc.) of that to which he/she wants to connect and click the ‘Connect’ button. To connect to LimiFrog running the Dialog DSPS firmware, the device to choose is that whose information includes ID DA1458x  (which is the name of the BLE chip used in LimiFrog). In the picture above, no hesitation, there is only one device detected. The connection status is reported under these buttons.
  • A message to send to the Android device can be entered in the text box of the Tx control section. It is sent over BLE when button “Send Message” is pressed. In accordance with the BLE DSPS profile implemented on LimiFrog side, the data is sent using a specific “write with no response” characteristic of that profile. This is conveniently achieved using a predefined method in App Inventor.
  • The data sent by LimiFrog over BLE can be monitored or ignored, the choice is done through button “Enable data reception” / “Disable data reception” (button text toggles depending on current state). When reception is enabled, data is obtained by App Inventor by tracking a specific “notify” characteristics of the implemented profile. Again, this is conveniently achieved using a predefined method in App Inventor.

 

Conclusion

In its current version, the BLE extension of App Inventor 2 can satisfactorily be used to exchange character strings between LimiFrog and a smartphone, using Dialog’s Serial Port Service profile. This makes App Inventor 2 very relevant for people with no or limited Android programming skills willing to build Limifrog-based projects or proofs of concept requiring interactions through a smartphone. One may imagine, for example, sending some configuration data to LimiFrog from a UI built on the phone, or sending sensor data provided by LimiFrog to a web server through the smartphone app, etc.

This being said, with the current version of the BLE extension there seem to remain important limitations. They’re not hurting in the case of this demo based on the DSPS profile but may be more of an issue in cases that implement other profiles. In particular, accessing “characteristics”  that have a payload other than a string of characters and longer than 1 byte or 1 float seems to require awkward work-arounds. Also, it seems that trying to read (or get notified of) different characteristics for a same service is problematic.
The good news is BLE development for AI2 is still in progress so hopefully things will continue to improve in the next releases.

EDIT :

It turns out a significant update of the BLE extension for AI2 is undergoing beta-testing at the time of publishing this article. This update addresses many issues and limitations of the current BLE extension. However the new BLE extension will not be backwards-compatible with that already released. When the update goes live, (time permitting) I will update on GitHub the example AI2 project for interactions with LimiFrog.

ShareTweet about this on TwitterShare on FacebookEmail this to someoneShare on Google+Share on LinkedInPin on Pinterest