Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Multiple BLE Connections | Latency on Observe Functionality #503

Open
ercan opened this issue Jun 14, 2023 · 1 comment
Open

Android Multiple BLE Connections | Latency on Observe Functionality #503

ercan opened this issue Jun 14, 2023 · 1 comment

Comments

@ercan
Copy link

ercan commented Jun 14, 2023

Hi,

I'm working on an Android app which connects 5 to 8 devices and these devices have a service which emits a simple ByteArray in each ~(4 to 10ms).

When I start observing this service for each devices, I start seeing huge package losses (80% or even heigher) for some devices (for some of them package loss is pretty acceptable like 0.48%). But when I connect only 1 or 2 devices, I see almost no package loss.

Is there any restriction with device count or do you if I miss a point?

@twyatt
Copy link
Member

twyatt commented Jun 14, 2023

There isn't any known restrictions.

Kable feeds all characteristic changes (from the BluetoothGattCallback) into a MutableSharedFlow with an "unlimited" buffer:

val characteristicChanges = MutableSharedFlow<ObservationEvent<T>>(extraBufferCapacity = Int.MAX_VALUE)

If you're slow on the consuming side, you should just see memory usage grow rather than packets being dropped.

I can't really speak as to limitations there might be in the underlying Android BLE system though. Not sure how Android might handle a peripheral updating a characteristic faster than Android can retrieve the updated characteristic data.

If you enable Kable logging (level = Data), then you can see all data that goes through the callback. If you see all expected data in the logs but not what you get from the Kable's observe flow, then that could definitely be a bug in Kable.


What version of Android is this? Before Android 26 the threading model for BLE was wonky. 🤷 If you see different behavior pre vs. post Android 26 it might hint at a possible cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants