BLE disconnect is not working properly

I updated the extension to Extension Version: 20200828 and removed the clock2 but still disconnect is not working. Looks like it the app doesn't have full control over disconnect function it only works if I close the app from background or turn off the Bluetooth.

But if I call bt_disconect() from nrf52833dk then it gets disconnected.

It will not necessarily affect the disconnection as a timer, but both Clocks must be disabled before you disconnect.

That is a Bluetooth Classic method. You are actually receiving and processing via a BLE 'Floats Received' Block so you could instead use 'Register for Floats' and simply work with the timing in the microprocessor script.

The replace text code is not necessary - the 'floatValues' are a list, just use the List Blocks to get the values.

The latest is 20201223

Your code is somewhat unconventional and that might have something to do with it but I agree, it looks like disconnect should work.

Did you notice that we are running the new App Inventor version today? Unfortunately still on SDK 30 - Android 11.

In this topic in the first example there is an app called p110i_esp32_ble_conexión.aia (199.5 KiB), can you check if the connection/disconnection works for you?

1 Like

If you stick with this method, change your code to:

EDIT: The Clock should be disabled:

This is what your 'FloatsReceived' Block could look like:

As I said before, you could have the App instruct the board to disconnect - is your Project just for you or is it going to be distributed? If it's just for you, then the Activity Starter method should suffice.

What do you mean by unconventional?
I start scanning, find the devices, look for device with particular name, connect, start timer and read data on timer ticks and then display data accordingly.

I can modify my app and will test it

You don't test that you are still connected (not correctly, see my Clock1 Block update), you don't use the BLE method 'register for floats', you use separate characteristics when the value type is the same, etc. That does not mean, except for testing that you are connected, that your code is wrong in any way, nor does it mean your code makes disconnection fail.

Also, not sure why you cut a chunk out of the address found for the device? You should be able to simply use the string listed and leave the extension to work with it.

Try disconnecting with this Block:


You shouldn't need to ask for Bluetooth permission, the extension does that.

Chunk is because if I get the full address it comes along with the device name and If I connect with it, it gives error. So I get that the chunk that is only the device address so that it connect without errors.

I used disconnectWitAddress block but it still doesn't work.
If I make an app with just scan and disconnect functionality then disconnect start to work like I tested with my new application with only connect and disconnect functionality and also the app from @Juan_Antonio
It means my this app have some thing wrong that is not allowing it to disconnect even when it is calling disconnect.

TextBox1 and TextBox3 should Labels - Similarly, Buttons 'minutes' and 'sec' should be Labels. Discard the display of milliseconds and update the timer in seconds.

I completely removed clock2 and timer display but still same with disconnect.

Hmm, that should not be the case - perhaps the full address is formatted in an unexpected way (from the perspective of the extension).

There are a lot of little things wrong in your code - the ListView for example. It's not being used by the User? You make it invisible several times. If the User does not need it, delete it.

Disconnection is not necessarily instant, you could try waiting before testing:

Wait 200 milliseconds or more.

A tidy code version of your Project with niggles fixed (but may fail on device address as you described):
Testing_edit.aia (197.9 KB)