dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
530 stars 195 forks source link

Android Connection Status 133 Gatt Error - Cannot Connect #565

Open KrystofM opened 3 years ago

KrystofM commented 3 years ago

Having trouble on some older Android devices with connecting to peripheral. For example Huawei P8Lite Android 6. The connection throws Gatt Error 133:

BleError (Error code: 201, ATT error code: null, iOS error code: null, Android error code: 133, reason: Disconnected from 8C:AA:B5:A7:62:4A with status 133 (GATT_ERROR), internal message: null, device ID: 8C:AA:B5:A7:62:4A, service UUID: null, characteristic UUID: null, descriptor UUID: null)

Disconnected from 8C:AA:B5:A7:62:4A with status 133 (GATT_ERROR)

This seems to be a problem in the function connectToDevice in DeviceConnectingDelegate.

Tracked this down even further to safeConnectToDevice in BleModule in multiplatformbleadapter.

Another flutter ble library has seem to solve this issue somehow: https://github.com/pauldemarco/flutter_blue/issues/231 https://github.com/pauldemarco/flutter_blue/pull/229/files

Any ideas on how to solve this issue?

KrystofM commented 3 years ago

This seems quite relevant also: https://github.com/Polidea/RxAndroidBle/issues/530

@mikolak Any ideas?

KrystofM commented 3 years ago

The example in this repo simulates the behavior as well. This seems like an issue that can be solved either by trying to reconnect on fail or on Android 6 or less passing a an argument to gatt connection: https://stackoverflow.com/questions/25330938/android-bluetoothgatt-status-133-register-callback

D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(22598): on native side observed method: observeConnectionState
I/flutter (22598): 2020-12-22T16:36:41.761853   D   new DeviceDetailsBloc.<ac>:  Connecting to Undout_A76248
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(22598): on native side observed method: connectToDevice
I/flutter (22598): 2020-12-22T16:36:41.798351   D   new DeviceDetailsBloc.<ac>:  Observed new connection state: 
I/flutter (22598): PeripheralConnectionState.disconnected
D/BluetoothGatt(22598): connect() - device: 8C:AA:B5:A7:62:4A, auto: false
D/BluetoothGatt(22598): registerApp()
D/BluetoothGatt(22598): registerApp() - UUID=67cf31a8-cc2e-4179-b675-b0edbea2679f
D/BluetoothGatt(22598): onClientRegistered() - status=0 clientIf=5
D/BluetoothGatt(22598): onClientConnectionState() - status=133 clientIf=5 device=8C:AA:B5:A7:62:4A
D/BluetoothManager(22598): getConnectionState()
D/BluetoothManager(22598): getConnectedDevices
D/BluetoothGatt(22598): close()
D/BluetoothGatt(22598): unregisterApp() - mClientIf=5
I/flutter (22598): 2020-12-22T16:37:17.663322   E   new DeviceDetailsBloc.<ac>:  BleError (Error code: 201, ATT error code: null, iOS error code: null, Android error code: 133, reason: Disconnected from 8C:AA:B5:A7:62:4A with status 133 (GATT_ERROR), internal message: null, device ID: 8C:AA:B5:A7:62:4A, service UUID: null, characteristic UUID: null, descriptor UUID: null)
KrystofM commented 3 years ago

Okay to is seems RxAndroid lib is doing that when connecting without reflection:

private BluetoothGatt connectGattCompat(BluetoothGattCallback bluetoothGattCallback, BluetoothDevice device, boolean autoConnect) {
        RxBleLog.v("Connecting without reflection");

        if (Build.VERSION.SDK_INT >= 23 /* Build.VERSION_CODES.M */) {
            return device.connectGatt(context, autoConnect, bluetoothGattCallback, TRANSPORT_LE);
        } else {
            return device.connectGatt(context, autoConnect, bluetoothGattCallback);
        }
    }
JAICHANGPARK commented 3 years ago

I had same problem about this issues @KrystofM did you solved this problem ?

Mushroomizer commented 3 years ago

@JAICHANGPARK , @KrystofM I have the same issue, did you ever solve this?

KrystofM commented 3 years ago

@JAICHANGPARK @Mushroomizer We have whitelisted a bunch of Huawei devices, it is a known problem for these devices to be problematic and even big companies like Garmin or Fitbit have them on a whitelist.

KrystofM commented 3 years ago

Ovearll Status 133 Gatt Error is a pretty generic BLE error and could mean a lot of things. Had some similar problems with some Samsung devices and we had to change the firmware BLE stack on our device to be able to connect to it ( some really mysterious errors and issues come up with androids overall ).

matteotan commented 2 years ago

Did somebody solve this bug?

QGB commented 1 year ago

connection failed gatt status 133

ManBali commented 12 months ago

it impossible to solve this problems ,the only way to improve connect success, jus retry ,retry retry .

arbaelbarca commented 9 months ago

please helping me, theres issue the same gat status 133

DevTiago commented 7 months ago

Same here.. :/