none
BluetoothLE: Problem enabling notification with BluetoothGATTSetDescriptorValue() RRS feed

  • Question

  • I'm trying to monitor Bluetooth LE device's characteristic value change using notification.

    As a part of that, I use BluetoothGATTSetDescriptorValue() API to set IsSubscribeToNotification bit in the Client Characteristic Configuration Descriptor.  It works fine if the target device is connected.  But, when the device is disconnected, this API stalls for about 10 seconds and fails with HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED).  Because many Bluetooth LE device automatically disconnect when there is no communication to save battery, I often need to keep calling this API repeatedly until it succeeds.

    Is there a better way to enable notification?  I'm particularly wondering if any of the following is possible:

    1) Instruct Windows to enable notification, and Windows enable it asynchronously when the connection is restored.

    2) Get a notification when the connection.

    3) Force reconnect to the device.

    Thanks,

    Susumu Arai

    Wednesday, March 22, 2017 5:39 AM

Answers

  • Our Universal APIs are async and handle subscribing to events. The BluetoothLEClient sample shows how to connect to the device async and subscribe to a value change using an event. The Universal APIs handle the remote device connecting/disconnect if you keep a valid reference to the BluetoothLEDevice.

    Our Win32 APIs as you noticed are not async and very low level; requiring the developer to do as you described. To my knowledge there is no way using the Win32 Gatt APIs to force a connection.

    Is there a reason you've selected the Win32 APIs vs. Universal APIs?

    • Marked as answer by sarai2 Wednesday, March 22, 2017 6:19 PM
    Wednesday, March 22, 2017 7:17 AM

All replies

  • Our Universal APIs are async and handle subscribing to events. The BluetoothLEClient sample shows how to connect to the device async and subscribe to a value change using an event. The Universal APIs handle the remote device connecting/disconnect if you keep a valid reference to the BluetoothLEDevice.

    Our Win32 APIs as you noticed are not async and very low level; requiring the developer to do as you described. To my knowledge there is no way using the Win32 Gatt APIs to force a connection.

    Is there a reason you've selected the Win32 APIs vs. Universal APIs?

    • Marked as answer by sarai2 Wednesday, March 22, 2017 6:19 PM
    Wednesday, March 22, 2017 7:17 AM
  • Thanks for your reply.  It answers my question (for now:).

    So, what is the positioning of Win32 API (at least for Bluetooth support)?  Will it stay functionally limited, compared to Universal API?  Or, will it eventually catch up?  I understand that Win32 API is lower-level API and tends to require much more lines of code to do what higher level API does, but I'm hoping everything high-level API can do can be done with Win32 APIs....

    Wednesday, March 22, 2017 6:19 PM