Comments (18)
Now, the tester report that we are facing the BleGattCallbackTimeoutException on all BLE write commands that we send to device randomly. That means if we write a BLE command to device 10 times, each command 1 second apart, we can observe the timeout exception at least 1 time (1/10 tries).
But it is odd that the bug is only observed in testers's environment with their Samsung S23 and S23 Ultra.
I tried to reproduce with my Samsung S22 Ultra and Google Pixel 7A, but I don't observe the issue.
I think I should check bluetooth HCI log on their phone.
from rxandroidble.
Hey, thanks for using the library!
This looks like an Android BLE stack error/unhandled situation. Most probably a HCI log would have hints on what is going on.
Are those long writes you make related somehow to configuring your peripheral's BLE configuration?
from rxandroidble.
Are those long writes you make related somehow to configuring your peripheral's BLE configuration?
Thanks for your replying.
Yes, I use long writes the characteristic with different data payload to configuring my peripheral's BLE.
The BLE connection is automatically disconnect after the BleGattCallbackTimeoutException.
Could you guide me some tips to workaround this issue?
Can we refresh the Gatt cache or do something in case of exception instead of disconnect the BLE?
from rxandroidble.
First of all – what configuration are you setting specifically? Maybe it's not needed or timed wrong?
As for the refresh, there is a topic about it already — it's possible
from rxandroidble.
Thanks for your tips.
I think I should optimize the way to configuring peripheral device. Instead of writing many time in a short period of time, I will try to write sequentially.
from rxandroidble.
I don't think queuing these writes sequentially will help as they are executed sequentially FIFO anyway.
If you could share what these individual writes are configuring it could help understand what is going on.
Additional questions:
- How many bytes have the individual commands?
- Are these writes scheduled right after the connection is established or later?
- Is the peripheral paired/bonded?
from rxandroidble.
If you could share what these individual writes are configuring it could help understand what is going on.
It is a feature called feature A of the peripheral device, when the application start or resume (move from background to foreground), I try to write/read configurations of this feature A, for example: get/set volume, get/set status (on or off),...
1.How many bytes have the individual commands?
There are 5 different commands with data payload from 2 to 9 bytes.
- Are these writes scheduled right after the connection is established or later?
No, I just try to write/read when the connection already is established. I also checked the BLE connection is connected or not before write/read.
- Is the peripheral paired/bonded?
It is already paired/bonded
I am trying to write/read 5 different BLE commands when the application moves from background to foreground. The app and peripheral are always paired/bonded while app is in background.
If I try to repeat the steps to move the app from background to foreground 10 times. There is at least 1 time that I observe the issue BLE disconnect.
from rxandroidble.
It is a feature called feature A of the peripheral device, when the application start or resume (move from background to foreground), I try to write/read configurations of this feature A, for example: get/set volume, get/set status (on or off),...
What does it change from the Bluetooth perspective? Are there changes in the bluetooth services available? Connection timings change?
There are 5 different commands with data payload from 2 to 9 bytes.
If so, I see no need in using rxBleConnection.createNewLongWriteBuilder()
, standard rxBleConnection.writeCharacteristic()
should work since no command exceeds the default 20 byte payload size (unless you concatenate multiple commands in one write). Or rather not work as I suspect the problem you face to be either a BLE stack related or a Peripheral implementation issue.
from rxandroidble.
Thanks for your support.
I have changed from the .createNewLongWriteBuilder() to .writeCharacteristic() for any commands less than 20 bytes payload size. It works as expected in my environment. But I am waiting for testers to confirm in their environment.
from rxandroidble.
Thanks @dariuszseweryn.
The change to use .writeCharacteristic() does not work in the testers environment. They still receive the same error about BleGattCallbackTimeoutException.
But the error is not always observed. They tried 10 times, there are 2 times observe the error.
Their phone are: Samsung S23, S23 Ultra. Both are running Android 13.
After the timeout exception, the bluetooth is disconnected automatically with either:
- Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 0 (GATT_SUCCESS)
- Or Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 22 (GATT_CONN_TERMINATE_LOCAL_HOST)
I wonder why the library automatically disconnect bluetooth in this case? Why don't we keep the connection and the application can handle the connection by itself?
from rxandroidble.
The change to use .writeCharacteristic() does not work in the testers environment. They still receive the same error about BleGattCallbackTimeoutException.
But the error is not always observed. They tried 10 times, there are 2 times observe the error.
That was expected.
I wonder why the library automatically disconnect bluetooth in this case? Why don't we keep the connection and the application can handle the connection by itself?
The library does not disconnect by itself but only reports what the Android BLE Stack is doing.
You still did not share what Bluetooth connection configuration can change with those 5 commands you write so I cannot give you more suggestions apart of looking into the BLE Stack. To get more insight on what the Android BLE Stack is doing (or rather what it is not handling correctly) you would need to check the Bluetooth HCI Log.
from rxandroidble.
Sorry for making you confuse about the changing of BLE connection configuration by those 5 commands I write to the BLE device. The 5 commands just change settings for a function in the device that doesn't relate to Bluetooth configuration.
What does it change from the Bluetooth perspective? Are there changes in the bluetooth services available? Connection timings change?
The commands don't change anything relate to Bluetooth.
from rxandroidble.
HI @dariuszseweryn ,
I have received Bluetooth HCI log from the tester and analyzed it.
But I think the issue come from the Android BLE Stack. Because when the timeout was observed, the peripheral device did not receive any command from the phone.
The HCI log are:
// The normal flow
26325 6893.223687 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26326 6893.255955 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26327 6893.285384 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26328 6893.289968 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 15 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26329 6893.315779 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26330 6893.345345 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26331 6893.353423 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26332 6893.375894 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26333 6893.405442 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26334 6893.410812 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26335 6893.437157 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26336 6893.437374 remote () SamsungElect_98:70:f8 (My S23) L2CAP 489 Rcvd Connection oriented channel
26337 6893.465926 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26338 6893.472595 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26339 6893.495650 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26340 6893.525569 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26341 6893.530448 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 16 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26342 6893.555489 controller host HCI_EVT 8 Rcvd Number of Completed Packets
26343 6893.585602 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 10 Rcvd Write Response, Handle: 0x0020 (Unknown: Unknown)
26344 6893.586548 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 18 Rcvd Handle Value Notification, Handle: 0x0022 (Unknown: Unknown)
26345 6893.587030 Peripheral_Device_00:00:45 (Tester) SamsungElect_98:70:f8 (My S23) ATT 15 Rcvd Handle Value Notification, Handle: 0x0022 (Unknown: Unknown)
----------------------------------------------------------------------------------------
// ERROR FROM HERE
// The error flow, the Timeout Exception is observed after this command without any Response
26675 6972.433380 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26676 6972.463480 controller host HCI_EVT 8 Rcvd Number of Completed Packets
// After 30 seconds, it leads to disconnect BLE.
26796 7002.434506 host controller HCI_CMD 7 Sent Disconnect
26797 7002.450666 controller host HCI_EVT 7 Rcvd Command Status (Disconnect)
26798 7002.450860 remote () SamsungElect_98:70:f8 (My S23) L2CAP 485 Rcvd Connection oriented channel
26799 7002.450982 remote () SamsungElect_98:70:f8 (My S23) L2CAP 482 Rcvd Connection oriented channel
26800 7002.451075 remote () SamsungElect_98:70:f8 (My S23) L2CAP 485 Rcvd Connection oriented channel
26801 7002.451244 remote () SamsungElect_98:70:f8 (My S23) L2CAP 489 Rcvd Connection oriented channel
26802 7002.453561 remote () SamsungElect_98:70:f8 (My S23) L2CAP 495 Rcvd Connection oriented channel
26803 7002.453714 remote () SamsungElect_98:70:f8 (My S23) L2CAP 486 Rcvd Connection oriented channel
26804 7002.456320 controller host HCI_EVT 7 Rcvd Disconnect Complete
from rxandroidble.
How do you verify that the peripheral did not received the write request?
Is the write request successful in the HCI log?
If yes, you could verify that the packet is actually (not) sent using a BLE sniffer.
from rxandroidble.
How do you verify that the peripheral did not received the write request?
There are not any log line from the peripheral device's log when the write request is sent from the app via BLE.
Is the write request successful in the HCI log?
From my understanding, the HCI log about write request is successful be like:
26675 6972.433380 SamsungElect_98:70:f8 (My S23) Peripheral_Device_00:00:45 (Tester) ATT 32 Sent Write Request, Handle: 0x0020 (Unknown: Unknown)
26676 6972.463480 controller host HCI_EVT 8 Rcvd Number of Completed Packets
If yes, you could verify that the packet is actually (not) sent using a BLE sniffer.
It is hard for me to sniff the BLE packets. Because I don't have the Samsung S23 phone.
Anyway, What do you think if I do a trick to command read characteristic before a command write? To make sure that the Gatt client is working.
from rxandroidble.
There are not any log line from the peripheral device's log when the write request is sent from the app via BLE.
Depending on the log level (stack/driver vs application) this may not be a decisive proof. i.e. it is possible the peripheral could receive the request but either stack failed on delivering the request to the application or the application itself did fail to create a log due to some silent failure.
I haven't seen so far the issue you're experiencing therefore I am inclined to think that the problem lies in peripheral's firmware (I have seen a lot of them).
Anyway, What do you think if I do a trick to command read characteristic before a command write? To make sure that the Gatt client is working.
This could help if the problem is somehow related to timing of commands — it is rather a blind shot, though.
It is hard for me to sniff the BLE packets. Because I don't have the Samsung S23 phone.
If you (or some tester) would be able to sniff BLE (I usually used an nRF dev-kit based solution) you could have a very concrete proof if the Android Stack is the problem or the peripheral side. If the Android would be the problem you could file a bug to Samsung. If the peripheral you would be sure that the firmware needs to be fixed (or peripheral's MCU vendor [TI, nRF, etc.] needs to fix their stack)
Have you tested with other Android phone vendors? Google Pixels, etc.?
from rxandroidble.
I haven't seen so far the issue you're experiencing therefore I am inclined to think that the problem lies in peripheral's firmware (I have seen a lot of them).
But the tester reported that they did not observe the issue on IOS (My application is running on Android and IOS).
Have you tested with other Android phone vendors? Google Pixels, etc.?
I also checked with other Android phones like: Google Pixel 7A, Samsung A52, Samsung S22 Ultra. But I didn't observe the issue.
from rxandroidble.
iOS has a completely different BLE stack and does implicitly different things than Android so it's hard to compare the behaviour between them.
If extensive testing on other vendors's phones did not show the problem it seems that its model specific.
HCI log you posted lacks a bit in the context of the requests that happened right before the failed one. You could compare if the only difference is the lack of the response or there is something more there.
from rxandroidble.
Related Issues (20)
- It is not possible to disconnect the Bluetooth while it is in the process of connecting. HOT 1
- BleGattCharacteristicException while readCharacteristic HOT 12
- scanResult.bleDevice.name not showing Ble updated name HOT 1
- BLUETOOTH_SCAN set usesPermissionFlags="neverForLocation",Is there a problem? HOT 2
- GenericFailure<CharacteristicValueUpdateError> HOT 11
- Send long bytes twice HOT 2
- Write request is not processed in the random order HOT 2
- Long Bytes Send HOT 8
- Creating a Fork HOT 2
- Set Preferred PHY / Read PHY HOT 2
- RxBleClient mulit connections HOT 4
- Is the library still maintained? HOT 3
- Android 14 breaking change HOT 15
- Google Pixel 5 loses bonding info after BT adapter cycle HOT 4
- Metode readcharacteristic not stream HOT 2
- Unable to readCharacteristic after writeCharacteristic HOT 5
- In the case of unsuccessful Bluetooth connection, actively disconnect without executing context. unregisterReceiver (receiver); At this point, there may be multiple Bluetooth broadcast registrarReceivers, which may crash on some Huawei phones due to a broadcast limit of approximately 1000. Suggest fixing this issue. HOT 2
- Can't scan after connect dispose/clear HOT 1
- Add `advertisingSid` property to `ScanResult` and `RxBleInternalScanResult` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxandroidble.