1446406

unread,
Apr 18, 2019, 5:42:23 PM4/18/19
to MIT App Inventor Forum

I'm trying to create a Bluetooth detector for a school project that will emit a beeping noise when a specific Bluetooth module is NOT detected. Is this even possible?

1446406

unread,
Apr 18, 2019, 5:45:36 PM4/18/19
to MIT App Inventor Forum
Specifically, I want to use if/then logic to test if a specific Bluetooth device is connected

Chris Ward

unread,
Apr 18, 2019, 6:28:19 PM4/18/19
to MIT App Inventor Forum
Hi

There is a difference between being detected and being connected - you could detect (find) a device, but be unable to connect to it.

Based on that, what do you actually need to do?

1446406

unread,
Apr 18, 2019, 6:51:28 PM4/18/19
to MIT App Inventor Forum
So what I want to do is connect to a bluetooth device, and then whenever that device is not in range I get an indicator

Chris Ward

unread,
Apr 18, 2019, 8:44:34 PM4/18/19
to MIT App Inventor Forum
OK - when out of range, the connection is lost. In App Inventor that can be detected and then any type of indication can be made - sound, pop-up message, phone vibrate.

1446406

unread,
Apr 19, 2019, 11:48:56 AM4/19/19
to MIT App Inventor Forum
Sorry if this is asking too much, but how exactly would I detect that?

Chris Ward

unread,
Apr 19, 2019, 4:38:37 PM4/19/19
to MIT App Inventor Forum
Ok, Bluetooth Classic and BLE have similar Blocks to check that the Android Device (phone) is connected. If the connection is lost, then "IsConnected" returns "False".

Here is an example where an App periodically receives data from a microcontroller. If the connection is lost, the phone is vibrated:

AlertUserConnectionLost.png


1446406

unread,
Apr 19, 2019, 6:01:29 PM4/19/19
to MIT App Inventor Forum
is this testing for a Bluetooth connection in general or for a specific device? And could I use this same block setup to test for a BlueTooth connection?

Chris Ward

unread,
Apr 19, 2019, 6:17:51 PM4/19/19
to MIT App Inventor Forum
Hi

The Block checks the connection to a previously selected device, then checks if data is available to receive.

Before that, a List of available devices detected is collated and the User selects which device to connect to from that List.

1446406

unread,
Apr 19, 2019, 7:06:46 PM4/19/19
to MIT App Inventor Forum

I already have a block setup that connects to a selected BlueTooth device, will this work together?

Capture.PNG



1446406

unread,
Apr 19, 2019, 8:26:17 PM4/19/19
to MIT App Inventor Forum
Also when you say micro-controller does that mean the device containing the BlueTooth module?

1446406

unread,
Apr 19, 2019, 8:27:27 PM4/19/19
to MIT App Inventor Forum
And with a shorter time interval for the clock will that make it so that the system does checks more often?

Chris Ward

unread,
Apr 19, 2019, 8:28:50 PM4/19/19
to MIT App Inventor Forum
Hi

Yes they will, but, in your ListPicker 1 AfterPicking Block, the Connect block should not be assigned to ListPicker.selection! Also, your Block assumes a lightning-fast connection, which will be true in most cases but you can't bank on it, so testing for "IsConnected" in a Timer Block gets that one out of jail.

CheckForConnectionSuccess.png






Chris Ward

unread,
Apr 19, 2019, 8:36:11 PM4/19/19
to MIT App Inventor Forum
Yes, the device that hosts the Bluetooth module - Arduino Uno R3 is a popular choice for example.

See the Links on my website about microcontrollers and Bluetooth - lots of valuable information, set-up examples by various experts and gotchas to avoid.

Chris Ward

unread,
Apr 19, 2019, 8:44:00 PM4/19/19
to MIT App Inventor Forum
Shorter time interval = checking more often. Don't over do it.

Note that you will use two timers, one to ensure the initial connection is successful, the other to check that the connection has not broken (typically caused by the Phone moving too far away from the target device - Bluetooth range is limited)

I scrambled the example code together for you as it's getting late here (UK time). It's good practice to give all components meaningful names rather than just Button1, Clock1 etc.

See:

1446406

unread,
Apr 19, 2019, 8:45:17 PM4/19/19
to MIT App Inventor Forum
What is Clock_TimerConnect?

1446406

unread,
Apr 19, 2019, 8:47:29 PM4/19/19
to MIT App Inventor Forum
nevermind I understand

Chris Ward

unread,
Apr 19, 2019, 8:48:24 PM4/19/19
to MIT App Inventor Forum
:)

1446406

unread,
Apr 20, 2019, 3:59:20 PM4/20/19
to MIT App Inventor Forum
would I need to set globaltimercount back to zero if the bluetooth connects after being disconnected

Chris Ward

unread,
Apr 20, 2019, 4:25:38 PM4/20/19
to MIT App Inventor Forum
Hi

That particular Block is checking to see if the first attempt to connect is a success or not. In either case, the timer disables itself. The expectation is that if connection was not successful, the App would be exited by the User (to examine the target device for example). Once the first attempt to connect is a success, the auto-reconnect block could be used if it is thought that the connection could be lost during a session of data exchange - perhaps because the device is close to the distance limit for example.

That's the long story. If you intend to keep the App running and try to connect again (repicking the target device from the list) after tweaking something, then certainly timer count should be returned to zero before hand. You can do that in the same part of the timer block that reports the error.

1446406

unread,
Apr 20, 2019, 8:17:29 PM4/20/19
to MIT App Inventor Forum
Hello again, the app is about finished and am trying to add background music, but the file size is too large. Is there a way to get around this?

TimAI2

unread,
Apr 21, 2019, 5:29:53 AM4/21/19
to MIT App Inventor Forum
Reduce the file size, or call the file in on first run of the app from a web resource.

1446406

unread,
Apr 21, 2019, 9:46:42 AM4/21/19
to MIT App Inventor Forum
How do I do the second option?

1446406

unread,
Apr 22, 2019, 11:10:09 AM4/22/19
to MIT App Inventor Forum
How do I make the app download the mp3 file once it is already on the phone? I want to do this in order to bypass the 10 mb limit on audio and video files.
Reply all
Reply to author
Forward
0 new messages