Using the Android 4.3 / Samsung BLE 2.0 SDK, it is observed that when the peripheral device is turned off, the SDK will accept onConnectionStateChange (DEVICE_DISCONNECTED) either immediately or after a delay of ~ 20 s. In my experience, this depends on the peripheral implementation, some of them will try to report that they are disabled, and some simply do not, so the SDK should wait ~ 20 seconds for a timeout.
To remove this behavior, I tried using a timer to check if I can read a specific symptom. If the timeout is disconnected, I will call disconnect (Android 4.3) / cancelConnection (Samsung) to end the connection. The call itself is successful, and the callback onConnectionStateChange returns the GATT_SUCCESS status. Then I turned on the peripheral device and immediately connected to it, discovered the services and ran into a problem when I tried to read / write / notify about any notification. Using LightBlue in iOS, I can confirm that the peripheral device is not connected.
After exactly 20 seconds from turning off the peripheral device, I get a DEVICE_DISCONNECTED callback. After that, I reconnect and everything works fine.
There are two questions: 1. Do we need to connect to peripherals within a 20 second delay? 2. Is there a way to get notified when the peripheral is turned off?
Thanks in advance.
android android bluetooth bluetooth-lowenergy
reTs
source share