weliem / blessed-android-coroutines

BLESSED Coroutines, a Bluetooth Low Energy (BLE) library for Android using Kotlin Coroutines
MIT License
128 stars 34 forks source link

observeConnectionState - 5 second delay #41

Closed bmartinezdev closed 1 year ago

bmartinezdev commented 1 year ago

Hi, First off, Thank you for writing this library. It has made dealing with BLE a much better experience.

My question is, is there a faster way to get feedback from observeConnectionState? I have a total of 6 BLE devices that I am connected to and my requirement is to stop all of the connections if any of the devices gets disconnected.

The callback works great and I am able to disconnect all of the devices if 1 becomes disconnected but there's about a 5 second delay from when I pull the battery off 1 device until the time the callback gets called?

weliem commented 1 year ago

The 5 seconds delay is called the Connection Timeout and is a lowlevel BLE thing. You can also see this number in de logs when the connection parameters are negotiated between central and peripheral. Basically it is the time they agree on to determine if a connection must be considered dropped.

In other words, there is nothing we can do about it in this library.