BleGattCoroutines icon indicating copy to clipboard operation
BleGattCoroutines copied to clipboard

isConnected not working when i get gatt 133 error

Open MikhailNatalenko opened this issue 5 years ago • 1 comments

When my ble device disconnects me i get the gatt status 133. BleGattCoroutine throws an exception com.beepiz.bluetooth.gattcoroutines.OperationFailedException as expected, and then i want to check BLE status with isConnected() method. In this situatuion i expect 'false' but i get 'true'. Is it a bug?

I am sorry but I can't provide you a minimal sketch right now i do something like:

try{
    gatt.connect() 
    // ...Do all preparations
    //turn off ble device for example 
    gatt.readCharacteristic(characteristic)
} catch (e: Exception){
  if (!gatt.isConnected()) doSomethingWithError() // i expect that doSomethingWithError() will happend
}

MikhailNatalenko avatar May 31 '19 12:05 MikhailNatalenko

The 133 error is quite obscure (it's named GATT_ERROR in AOSP, but undocumented, and when it happens, your best bet is to close the connection and retry from a new one. You should get the OperationFailedException or the other errors BleGattCoroutines can throw, and from the status present in the exception, handle the 133 to retry after closing the connection.

LouisCAD avatar Jun 02 '19 19:06 LouisCAD