Quirky BLE now works

34 views
Skip to first unread message
Assigned to ewpa...@gmail.com by chrisw...@gmail.com

Frank R. Nichols

unread,
May 4, 2019, 10:12:26 PM5/4/19
to MIT App Inventor Forum
(Sharing my solution to a BLE problem that's plagued me for days and days and days)

I had started another thread back in late April, entitled
BLE scan works from IDE (MIT AI2 Companion QRS scan) but not from APK build

It's been quite the journey to get to where I think I have things working (both Companion AND downloaded .apk).

I thought I'd share in case anyone else is struggling with the BLE extension.

Here's what I've done

  1. Latest BLE extension (always had it - Version 2)
  2. Check for and recognize buggy project loading (cure is to re-load aia from local computer) before building
  3. Invoke (when Screen1.initialize).AskForPermission->ACCESS_COARSE_LOCATION
    1. Not really sure this is necessary, but my project is connecting fine and receiving byte data from my BLE device, so I'm not in the mood to experiment with deleting this
  4. In the Designer, incorporate the 2016 workaround, (add BluetoothClient1 - with NO reference to any of its procedures in the Blocks. Just make sure it appears in the Designer. Something about a missing comma in the permissions in the manifest?). I found this workaround in another post on this forum (see below).
I'm putting the project as FinallyConnectingBLE_AsAPK_01.aia here:

https://drive.google.com/open?id=1A-wMlLyChYr3uTJHvO1IzXVBha5tRbIQ


The image of the Design window and the Blocks window can also be found there, as jpg files.

Removing the BluetoothClient1 from Design causes the following failure:
  • Works fine from Companion
  • Never scans or finds BLE device when running APK
If anyone has any further thoughts or suggestions, or thinks I'm experiencing a false sense of security - please let me know.

Thanks for everyone's great help and suggestions!

(The 2016 workaround follows)


jisMIT App Inventor Team

7/9/16

We understand the problem. Btw. There is a likely work around. If you drag a Bluetooth component into the designer (you don't have to actually use it) things should work.


The problem is that we left out a comma in the permissions string. So instead of giving location permission and bluetooth permission to the BLE component, we give it one permission which is the concatenation of the strings representing the two permissions!


Needless to say, this doesn't work. By dragging in the Bluetooth component, you get the correct permissions when you build.


The reason it works in the Companion is that the Companion has the permissions of all components! So it works.


We have the fix. What we are waiting on is for me to write the document explaining the process for upgrading an extension you have already loaded into your project. It is a non-trivial process now (which we are going to improve).


-Jeff

Marked complete byTaifunPower User



Chris Ward

unread,
May 5, 2019, 5:48:27 AM5/5/19
to MIT App Inventor Forum
Hi Frank

There is a reason to use the Classic Bluetooth Client anyway, and that is to verify Bluetooth is enabled on the device (phone). If it is not enabled, the App can pop-up a reminder Notification. It is possible for the App to switch Bluetooth on via Activity Starter, but that probably needs a permission nowadays.


Chris Ward

unread,
May 5, 2019, 6:00:17 AM5/5/19
to mitappinv...@googlegroups.com
Hi Frank

Concerning this:
  1. Check for and recognize buggy project loading (cure is to re-load aia from local computer) before building.

That is probably not a cure, given that the problem reoccurs. 


I suggested you try this:

Your before and after screenshots make the issue very clear. Never seen that happen before and I'm wondering if the .aia is in fact corrupted in some way. If you can post that, I can have a look (within the .aia, which is in fact a collection of files).

Something you can try when the issue occurs:

If for example you are looking at the Blocks for Screen 1, reselect the screen. This should perform a refresh:

ReselectScreen.png


If that does not work for you, then we would very much like to see the Project File (.aia) so that we can study the internal files.


EDIT: You can also try:


Right-Mouse Menu in Blocks Viewer workspace (i.e. not on a Block) and select "Clean up Blocks"


Chris Ward

unread,
May 5, 2019, 6:34:18 AM5/5/19
to mitappinv...@googlegroups.com
Hi Frank

One other thing concerning "FinallyConnectingBLE_AsAPK_01" - I think it is still not great to use a hard-coded device address. Why? Your code finds devices, but there is nothing to ensure that the required device is found.

Also, each heart monitor device should have it's own unique ID, so your App will only ever work with one device as it stands, although of course that may be all you require.

Ensure required device is found:

EnsureRequiredDeviceIsFound.png


Reply all
Reply to author
Forward
0 new messages