establishConnection fails sometimes with status 133 GATT_ERROR
See original GitHub issueSummary
I get the following exception when calling establishConnection(false): status 133 GATT_ERROR about 1/4 times on my Android 8.0. (strange that it is a DisconnectedException while trying to connect …)
I tried to get around with a retry after such connection failure. But this doesn’t work: the next exception tells me that the device is already connected. It seems that rxandroidble got into an inconsistent state?
If I try again the code block always succeeds (the code is triggered by a button click)
Library version
1.8.0
Preconditions
Sometimes it happens when the application is just restarted (from the debugger).
Steps to reproduce actual result
Minimum code snippet reproducing the issue
return device.establishConnection(false)
.retry(2, { throwable ->
Thread.sleep(500). # retry with some patience
warn { "establishConnection() failed: " + throwable.message}
# retry if the connection fails
throwable is BleDisconnectedException &&
throwable.message?.contains("status 133 (GATT_ERROR)") ?: false
}).flatMap { rxBleConnection ->
...
Logs from the application running with setting RxBleLog.setLogLevel(RxBleLog.VERBOSE)
D/RxBle#ClientOperationQueue: QUEUED ConnectOperation(266688704)
D/RxBle#ClientOperationQueue: STARTED ConnectOperation(266688704)
V/RxBle#BleConnectionCompat: Connecting without reflection
D/BluetoothGatt: connect() - device: F5:14:59:CB:18:99, auto: false
registerApp()
D/BluetoothGatt: registerApp() - UUID=df67839d-5d9d-43fc-b086-3f62899251d6
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=7 device=F5:14:59:CB:18:99
D/RxBle#BluetoothGatt$1: onConnectionStateChange newState=0 status=133
I/RxBle#ConnectionOperationQueue: Connection operations queue to be terminated (F5:14:59:CB:18:99)
D/RxBle#Executors$RunnableAdapter: Terminated.
W/Ble: establishConnection() failed: Disconnected from F5:14:59:CB:18:99 with status 133 (GATT_ERROR)
W/Ble: establishConnection() failed: Already connected to device with MAC address F5:14:59:CB:18:99
W/MainActivity: ### FM SetupNotification failed: Already connected to device with MAC address F5:14:59:CB:18:99, cause: null
D/RxBle#ClientOperationQueue: QUEUED DisconnectOperation(83660552)
D/RxBle#ClientOperationQueue: FINISHED ConnectOperation(266688704) in 5694 ms
D/RxBle#ClientOperationQueue: STARTED DisconnectOperation(83660552)
D/BluetoothManager: getConnectionState()
getConnectedDevices
D/BluetoothGatt: close()
unregisterApp() - mClientIf=7
D/RxBle#ClientOperationQueue: FINISHED DisconnectOperation(83660552) in 20 ms
Actual result
Expected result
Would it be possible for the ‘device’ instance to not think it is connected when retrying the connection? I have a feeling that the retry might then succeed …
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
GATT error with 133 on onConnectionStateChange #18 - GitHub
I managed to fix my "status 133" error. In my case, it was happening in case when I was trying to connect to...
Read more >Android 10: GATT error with 133 - how fix? - Stack Overflow
As seen in the AOSP constants, this error is the most generic error you can get. Generally, it happens when the device is...
Read more >Android GATT 133 error - Nordic Q&A
Connection : Andoird phone hardly connect my device. It returns GATT error 133. After application try more(3~4 times more), it connects. 2.
Read more >Connection establishment fails with GATT ERROR 133 ...
When I try connecting my device with nRF mobile app, it disconnects immediately throwing Error 133 - GATT ERROR.
Read more >BLUETOOTH LE (LOW ENERGY) CONNECTION MANAGEMENT ...
9 CHALLENGES TO ESTABLISH CONNECTION. 9.1 Failed to discover services. 9.2 Gatt Error. 9.3 Failed to discover Proprietary service or service is null....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dariuszseweryn Based on your suggestion I tried
.retryWhen
with a delay mechanism. The log traces indicate that the timer is executed but the actual retry never happens. When commenting out the delays, the retry happens! Strange but Luckily, after much trying, the delay seems unnecessary.I tried these:
and this variant
I see status 133 occurs frequently but I’ve never seen in fail again after a first retry. I finally stick with this simple:
Hope it will help others.
@aptly-io Hi aptly-io, I have same issues. I try to connect ble device and it have error 133 GATT code. Have you fix it done? Lets show me code to connect ble with RxAndroidBle. Thank you so much 😄 .