Turning off peripheral causing unexpected behavior
Using both Android 4.3/Samsung BLE 2.0 SDK, it is observed that when a
peripheral is turned off, the SDK will receive onConnectionStateChange
(DEVICE_DISCONNECTED) either immediately or after ~20s delay. From my
experience this depends on the peripheral implementation, some of them
will tried to report they are being turned off and some just doesn't, so
the SDK have to wait for ~20s for the timeout.
To remove this behaviour, I tried to use a Timer to check if I can read a
certain characteristic. If the read timed out, I will call
disconnect(Android 4.3)/cancelConnection(Samsung) to terminate the
connection. The call itself is successful and the onConnectionStateChange
callback return a status GATT_SUCCESS. Then I turned the peripheral on and
connect to it immediately, discover the services , and encounter problem
when I tried to read/write/notify any notification. By using LightBlue in
iOS I can confirm that the peripheral is not connected.
After exactly 20s from turning off the peripheral, I will receive a
DEVICE_DISCONNECTED callback. I connect again afterwards, and everything
operates fine afterwards.
There are two question : 1. Are we supposed to connect to the peripheral
during the 20s delay? 2. Is there any way to get notified when a
peripheral is turned off?
Thanks in advance.
No comments:
Post a Comment