[Bluetooth Low Energy] Long re-connection if a device is not in range. RRS feed

  • Question

  • Hi all.

    We faced with a problem of a long re-initialization of the remote BLE device (fob) if it go out of the range (or was powered off).

    For example, we receive from the remote device a data from an events (having subscribed to notifications). When the device in a range - everything is excellent. But when the device was out of range, then events cease to come. And if the device appears in the range again, events from it don't come.

    Thus, we are periodically re-initialize of the device (to be re-subscribing on events), on some watchdog (e.g. to the timer with some period).

    But there are a problem, that the BluetoothGATTRegisterEvent() function is blocking on some timeout (~8 second on real PC and ~35 second on VM) in case a remote BLE device is not in range. In this case doesn't matter, whether we use the same HANDLE of opened BLE service on PC, or we re-open the service's path (CloseHandle() / CreateFile()).

    The similar behavior has and BluetoothGATTGetCharacteristicValue() function, if we want to use a polling of data instead of events.

    All these functions (GetLastError()) returns an error codes: ERROR_DEVICE_NOT_CONNECTED (after ~8 second) on real PC, and the ERROR_SEM_TIMEOUT on VM (after ~35 second)!!! o_O

    Doesn't matter, whether it was used in CreateFile() when opening a service a flag FILE_FLAG_OVERLAPPED or not. As we hoped that this flag will help to return from the BluetoothGATTRegisterEvent() or the BluetoothGATTGetCharacteristicValue() immediately. But this not happens.

    We need somehow to interrupt session (or an input/output) immediately, without waiting while these functions to return.

    From the MS site I found out mentioning about the BluetoothGATTCloseSession() function, but seems, that this function are deprecated and is not present in public API. However, I tried to use of this function by means of a dynamic resolving from the system BluetoothApis.dll library. But it did not have effect for interruption of blocking (I'm did this function from the another thread). Also doesn't have effect an invocation of CancelIo() function.

    Thus, my question is following: is there an opportunity to interrupt execution of I/O operation (or session) immediately at any time when I want? Because us does not arrange (not acceptable) such long timeout of waiting as ~8 seconds.

    PS: Using the Windows 8/8.1 32 bit && VS2013 && USB2.0 && any of BLE donges from CSR A10 or from Broadcomm (does not matter).

    Best regards, Denis.

    Monday, September 15, 2014 6:49 PM