This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unexpected disconnect after BluetoothGatt.discoverServices() (Android)

Hello,

Setup: Android 4.4.2 (LG G2), nRF51822 peripherial.

I noticed that once in a while when trying to connect to my nRF51 based device it won't connect and what is worse the device gets removed from the list of bonded devices on the android phone. So I wrote an android test app that repeats the following steps (pseudo code):

BluetoothDevice.connectGatt()
wait for onConnectionSateChanged..
if BluetoothProfile.STATE_CONNECTED call BluetoothGatt.discoverServices()
wait for onServicesDiscovered()
if BluetoothGatt.GATT_SUCCESS waits for 500ms
call BluetoothGatt.disconnect()
wait for onConnectionSateChanged	
if BluetoothProfile.STATE_DISCONNECTED call BluetoothGatt.close()
wait for 500ms

Usually after repeating this 10-100 times I end up getting a disconnect right after service discovery completed. In addition the device is removed from the list of bonded devices (a ACTION_BOND_STATE_CHANGED broadcast is issued by the system).

This is the corresponding log. The disconnect happens at 33.313

....
06-05 09:23:33.193    2519-2546/? D/BtGatt.btif? btif_gattc_get_descriptor
06-05 09:23:33.193    2519-2546/? D/BtGatt.btif? btgattc_handle_event: Event 1009
06-05 09:23:33.193    2519-2546/? D/BtGatt.GattService? onGetDescriptor() - address=DA:88:2C:42:63:10, status=133, descUuid=00002902-0000-1000-8000-00805f9b34fb
06-05 09:23:33.193  27932-27945/com.me.test D/BluetoothGatt? onSearchComplete() = Device=DA:88:2C:42:63:10 Status=0
06-05 09:23:33.313    2519-2744/? E/bt-btm? btm_sec_disconnected - Clearing Pending flag
06-05 09:23:33.313    2519-2744/? W/bt-btif? bta_dm_act no entry for connected service cbs
06-05 09:23:33.313    2519-2546/? D/BtGatt.btif? btif_gattc_upstreams_evt: Event 5
06-05 09:23:33.313    2519-2546/? D/BtGatt.GattService? onDisconnected() - clientIf=5, connId=261, address=DA:88:2C:42:63:10
06-05 09:23:33.313  27932-28117/com.me.test D/BluetoothGatt? onClientConnectionState() - status=0 clientIf=5 device=DA:88:2C:42:63:10
....

Any idea what the problem might be or hints how to debug this? I'm not sure if the problem is on the nRF51 device side or Android side. The nRF51 Software doesn't seem to do anything unusual (doesn't hang, no reset etc.). Capturing the event using the sniffer also doesn't reveal anything to me:

image description

Thanks!

Parents
  • @Hung Bui: While inspecting the logcat I noticed that upon disconnect you are calling gatt.refresh(). This is not a public method, could you elaborate how (reflection?) and why are doing this?

    06-10 09:19:19.365 2519-6053/? D/BtGatt.GattService? onDisconnected() - clientIf=5, connId=5, address=EE:08:DB:5E:BE:9B 06-10 09:19:19.365 29761-29772/? D/BluetoothGatt? onClientConnectionState() - status=0 clientIf=5 device=EE:08:DB:5E:BE:9B 06-10 09:19:19.405 29761-29772/? D/BluetoothGatt? refresh() - device: EE:08:DB:5E:BE:9B 06-10 09:19:19.405 2519-6053/? D/BtGatt.GattService? refreshDevice() - address=EE:08:DB:5E:BE:9B

Reply
  • @Hung Bui: While inspecting the logcat I noticed that upon disconnect you are calling gatt.refresh(). This is not a public method, could you elaborate how (reflection?) and why are doing this?

    06-10 09:19:19.365 2519-6053/? D/BtGatt.GattService? onDisconnected() - clientIf=5, connId=5, address=EE:08:DB:5E:BE:9B 06-10 09:19:19.365 29761-29772/? D/BluetoothGatt? onClientConnectionState() - status=0 clientIf=5 device=EE:08:DB:5E:BE:9B 06-10 09:19:19.405 29761-29772/? D/BluetoothGatt? refresh() - device: EE:08:DB:5E:BE:9B 06-10 09:19:19.405 2519-6053/? D/BtGatt.GattService? refreshDevice() - address=EE:08:DB:5E:BE:9B

Children
No Data
Related