2

I have an issue with the connection(with bonding) between two android devices using the Bluetooth Low Energy. On both devices I'm running Android 8.0. The problem is the following. When I establish the connection between both devices, everything works fine but after closing the BLE server(and open it again) I am not able to reconnect from the client. The only way so far is deleting the bonding information from the client. However this is not comfortable at all. Is there a way to reestablish the connection without deleting the bonding manually? For example, resetting some flag from the BLE protocol or something. Also, I have a short output from the connection process:

1970-01-04 05:36:10.158 5254-5348/   D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=7C:92:B3:23:C0:19
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## CURRENT BLE STATUS: 0 [DISCONNECTED]
1970-01-04 05:36:10.164 5254-5348/   I/info: ######## NEW BLE STATUS: 2 [CONNECTED]
1970-01-04 05:36:10.164 5254-5348/   D/BluetoothGatt: configureMTU() - device: 7C:92:B3:23:C0:19 mtu: 482
1970-01-04 05:36:10.238 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=42
1970-01-04 05:36:10.239 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=42
1970-01-04 05:36:11.164 5254-5348/   D/BluetoothGatt: onConfigureMTU() - Device=7C:92:B3:23:C0:19 mtu=482 status=0
1970-01-04 05:36:11.165 5254-5348/   D/BluetoothGatt: requestConnectionPriority() - params: 1
1970-01-04 05:36:11.360 5254-5348/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=0
1970-01-04 05:36:11.361 5254-5268/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=39 latency=0 timeout=500 status=0
1970-01-04 05:36:11.793 5254-5348/   D/BluetoothGatt: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=12 latency=0 timeout=2000 status=0
1970-01-04 05:36:11.793 5254-5268/   D/BluetoothGattServer: onConnectionUpdated() - Device=7C:92:B3:23:C0:19 interval=12 latency=0 timeout=2000 status=0
1970-01-04 05:36:13.353 5254-5348/   D/BluetoothGattServer: onServerConnectionState() - status=0 serverIf=5 device=7C:92:B3:23:C0:19
1970-01-04 05:36:13.355 5254-5348/   D/BluetoothGatt: onClientConnectionState() - status=19 clientIf=6 device=7C:92:B3:23:C0:19
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## CURRENT BLE STATUS: 19 [HID_DEVICE]
1970-01-04 05:36:13.356 5254-5348/   I/info: ######## NEW BLE STATUS: 0 [DISCONNECTED]
1970-01-04 05:36:13.356 5254-5348/   D/BluetoothGatt: close()

As you can see, the initial state of the client is: DISCONNECTED. After that, he tries to connect, but after a few seconds gets disconnected. Any ideas why?

Thanks a lot!

bozhi
  • 21
  • 1

1 Answers1

1

I believe that this is happening because either one of the Android devices has a flag that indicates that it requires bonding, or one of the characteristics in the GATT table requires bonding (Unless you are specifically calling the InitiatePairing or CreateBond methods).

You can resolve this issue by either checking why your Android devices are automatically triggering the bonding (i.e. go through the entire GATT table and figuring out if there is a specific attribute that requires authentication), or by adding a workaround that removes the bonding programmatically. The latter would probably be the quicker method and I've seen it being done on multiple occasions. Have a look at the links below to see how this is done:-

I also recommend the links below that describe this and the pairing/bonding operations further on Android:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
  • Hi, thanks for the answer. Actually yes, some of the characteristics I have defined require bonding. I also have a BondListener which calls the method CreateBond(). So for my application, the bonding is required. As I told you, the issue is solved after deleting the bonding on the client side. However, I'm not sure if this "solution" is the best one. – bozhi Oct 19 '20 at 08:39
  • No problem, happy to help. The answer in the links removes the bonds programmatically as you requested (so you don't have to do anything manually). Unfortunately the Android BLE implementation has many issues and limitation therefore workarounds like these may be the only solution. – Youssif Saeed Oct 20 '20 at 08:34