Skip to first unread message

DebombDiggety

unread,
Jun 16, 2019, 2:33:58 PM6/16/19
to MIT App Inventor Forum
I am relatively new to the app inventor, (I already know some other languages so I got the hang of it pretty quickly) but I am running into a problem.

Basically, I am building a pair of smart glasses from some 3d printed parts and an Arduino. One of the features I want it to have is to be able to send text to the small OLED I am using when I receive a text(Through a Bluetooth module and an Arduino). Eventually, I want to have it display most notifications that my phone gets, but I'm starting with SMSs.

The problem is it only works when I have the app open on my phone (yes, RecievingEnabled is set to 3). When I exit the app it stops sending commands to my Arduino, but still sends notifications to the drop down on my phone. Is there some way that I could set the app inventor to... not do this? Maybe some way to detect/read notifications that my phone receives? Or maybe have the MessageRecieved command activate something that can send Bluetooth commands even when the app isn't running on screen?

It may be very basic, I am mostly self-taught so its touch-and-go for what stuff I know.

Thanks

Chris Ward

unread,
Jun 16, 2019, 10:41:52 PM6/16/19
to MIT App Inventor Forum
Hi

When you exit the App, The Bluetooth connection is lost and that is something that cannot be changed. What else happens depends on the version of Android and how it is implemented by the phone manufacturer.

Gerard Bucas

unread,
Jun 20, 2019, 6:44:46 PM6/20/19
to MIT App Inventor Forum
Hi DebombDiggety

That sounds like an interesting application!
I have written an AI2 app that happily communicates with an Arduino based BLE equipped device EVEN when the phone locks itself and/or the app is no longer visible. I have run it like that for days sending data from the Arduino device to the app (at intervals of 100msecs, etc - so tons of data reliably received over BLE by my app whether it is in foreground or background!). So I think what you want to do is possible but you need to approach it a little differently.

Having said that, Chris is of course correct in that certain BLE functionality like Scanning & Connecting do NOT work in an AI2 app when the app is no longer in the foreground (showing on the screen) but these should not affect your planned application if you approach it correctly.

So what I KNOW works even if app is no longer active on the screen (so you are running other apps or phone simply goes into lock mode with screen off) are things like "BLE.StringsReceived" (from the Arduino device, after you have first connected and then "BLE.RegisteredForStrings" in your app before the app/phone goes to semi-sleep). I have tested this on my relatively old Google/LG Nexus 5 phone (which uses Android 6.X). I also tested it on a newer Google Pixel Phone running Android 8 I think. Not sure if other (non-Google branded) phones would behave the same (as obviously there is a slight battery hit when this BLE data transfer is continuously happening in "background" mode. 

So here is my suggestion:
1. When your app starts up you do the BLE Scan, Connect & RegisterForStrings using a BLE module on the Arduino side that has a UART Service & Characteristics UUID (like this one: https://learn.adafruit.com/introducing-adafruit-ble-bluetooth-low-energy-friend/uart-service ).
2. Then you let the Arduino side "drive" the connection by sending data to the App (which you will receive in the App via BLE.StringsReceived ) every so often (maybe every second or even less frequently in your case). The data sent by Arduino side could be a single character like a "?" (sort of a "What's Up?" or a "Anything new?" for me!).
3. On the AI2 app side you can then use the "BLE.StringsReceived" event to check if you have received an SMS (or whatever you want to send to your glasses!) and if you DO have something you "simply" issue a "BLE.WriteStrings" on the same connection but using the "TX" CharacteristicUUID with the same ServiceUUID of the previously (& continuously kept alive by BLE!) established connection.

So bottom line is that you "stay connected" and you let the glasses "drive" the process (in other words the simple data received from the glasses will "wake up" your app with the "BLE.StringsReceived" event/call, thereby allowing your app to check if anything new has arrived that needs to be sent to the glasses). If yiu have something to send to the glasses you send it with "WriteStrings" and then the app simply "goes to sleep" again, waiting for the next "StringsReceived" call from the glasses. 

I am pretty confident this will work and in fact in AI2 it is simple to implement! :)

Hope this helps and/or it at least provides you with some food for thought!

Good luck..!

Best Regards

Gerard  

Ghica

unread,
Jun 23, 2019, 12:02:59 PM6/23/19
to MIT App Inventor Forum
Sounds interesting. Let us know whether it works!
Cheers, Ghica.

DebombDiggety

unread,
Jun 23, 2019, 2:37:30 PM6/23/19
to MIT App Inventor Forum
I had to google quite a few things in order to understand this lol

Anyway, I only have a hc-06 module, and I suppose I will need to get a BLE module in order to do this right?

Also fyi I will be traveling for the next two weeks and wont be able to check the forum. Thanks for the help!

Gerard Bucas

unread,
Jun 23, 2019, 4:34:23 PM6/23/19
to MIT App Inventor Forum
Yes - you will need a BLE module. Also essential for power reasons if you want the battery on your glasses to have a reasonable use time.

Once you have the concept working you will have to spend a lot of time on power optimization (another reason why it’s better to let the glasses drive/wake up the phone app instead of the other way around.

Happy travels...! :)

Gerard
Reply all
Reply to author
Forward
0 new messages