HubbellCorp / SweetBlue

BLE on Android the easy way
Apache License 2.0
23 stars 8 forks source link

Getting GATT_ERROR(133) for Samsung device #28

Open ujjvaljoshi4 opened 1 year ago

ujjvaljoshi4 commented 1 year ago

I am getting an error (GATT_ERROR 133) while trying to connect with an already bonded/paired device. It fails to connect around 9 out of 10 times.

Here is the scenario:

  1. Scan for devices
  2. Connect and bond/pair to a particular device
  3. Disconnect the device
  4. Kill the application
  5. Reopen the application
  6. Try to connect the same device and get GATT ERROR 133

Here is the log from Android Studio:

2022-12-01 13:02:07.441 22470-22598 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  registerApp()
2022-12-01 13:02:07.441 22470-22598 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  registerApp() - UUID=1ca54f53-1c38-4470-a1df-ec9f8d7960ff
2022-12-01 13:02:07.446 22470-23408 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  onClientRegistered() - status=0 clientIf=16
2022-12-01 13:02:07.679 22470-22470 GestureDetector         com.idevicesinc.sweetblue.toolbox    I  handleMessage TAP
2022-12-01 13:02:12.474 22470-22486 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  onClientConnectionState() - status=133 clientIf=16 device=5D:FA:A5:0A:C5:10
2022-12-01 13:02:12.518 22470-22486 P_BleDevic...r [Native] com.idevicesinc.sweetblue.toolbox    W  ABE(22486) onConnectionStateChange() [5D:FA:A5:0A:C5:10] - GATT_ERROR(133) STATE_DISCONNECTED(0)
2022-12-01 13:02:12.520 22470-22598 P_BleDevic...iveManager com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) updateNativeConnectionState() - STATE_DISCONNECTED(0)
2022-12-01 13:02:12.521 22470-22598 PA_Task                 com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) setState() - Connect(FAILED kd01rba1168_C510 148399736 ) - 3316
2022-12-01 13:02:12.521 22470-22598 P_TaskManager           com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) print() - no current task []
2022-12-01 13:02:12.523 22470-22598 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  close()
2022-12-01 13:02:12.531 22470-22598 BluetoothGatt           com.idevicesinc.sweetblue.toolbox    D  unregisterApp() - mClientIf=16
2022-12-01 13:02:12.537 22470-22598 P_ConnectionFailManager com.idevicesinc.sweetblue.toolbox    W  UPDATE(22598) onConnectionFailed() - NATIVE_CONNECTION_FAILED, timing=EVENTUALLY
2022-12-01 13:02:12.542 22470-22598 P_TaskManager           com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) addTask() - Adding task to queue: Connect(CREATED kd01rba1168_C510 199015095 )
2022-12-01 13:02:12.543 22470-22598 P_TaskManager           com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) print() - no current task [Connect(QUEUED kd01rba1168_C510 199015095 )]
2022-12-01 13:02:12.547 22470-22598 P_TaskManager           com.idevicesinc.sweetblue.toolbox    I  UPDATE(22598) print() - Connect(EXECUTING kd01rba1168_C510 199015095 ) []

I have tested the same scenario on 3 Android devices and here are the results:

  1. OnePlus 8T (Android 12): 100% working fine
  2. Samsung Galaxy M51 (Android 12): 90% failure (fails 9 out of 10 times, not getting connected after 6-8 tries)
  3. Samsung Galaxy A13 (Android 12): 20% failure (fails 2 out of 10 times, getting GATT_ERROR 133 but successfully connected after 3-4 tries)

@ryanhubbell Could you please help me with this issue?

ryanhubbell commented 1 year ago

Are you using any non-default configuration options?

Do you see any similar behavior when using iOS? (if applicable)

Unfortunately, bonding on android is a mixed bag like you are seeing. The library does it's best to try to smooth it out, but there's only so much it can do. That's why there is so much reconnecting code in the library. Even with that, sometimes it will not connect.

One thing you can try (which the library does automatically for Sony devices), is to always re-bond. For some reason on Sonys (and some Motorolas) in particular, in order to get more successful connections, this was the only "solution" found to work (and even then, it's not perfect).