BleWinrtDll icon indicating copy to clipboard operation
BleWinrtDll copied to clipboard

Would you be able to implement BluetoothLEAdvertisementWatcher, connection status ?

Open nathanrona opened this issue 4 years ago • 2 comments

Thank you very much for this great API. Thans to it was able to connect to BLE sensor and subscipe to notification, however I woud want to:

  1. Check connection status, i.e. to know if I am connected and subsciption is active.
  2. Scan only for devices that support my desired service (cycle cadance and speed service)

For the later I need to use BluetoothLEAdvertisementWatcher instead of devicewatcher. For the later I'm not sure, in Web-bluetooth (JS) I set an iternal connected varible true upon completing the pairing and set it false upon disconnect event.

Looked at the code in hope to be able to do it myself, but I'm not familiar in C++.

nathanrona avatar May 27 '21 11:05 nathanrona

For the connection status, I guess you can try using a GattSession with MaintainConnection set to true, as it is mentioned in the note on this doc page. The session has also an event in the case the connection-status changes. There already was a need for it in https://github.com/adabru/BleWinrtDll/issues/6 , but no implementation yet.

That's for the connection. Subscription is read and written (="subscribe") via the ClientCharacteristicConfigurationDescriptor, see https://github.com/adabru/BleWinrtDll/blob/main/BleWinrtDll/BleWinrtDll.cpp#L486 or ReadClientCharacteristicConfigurationDescriptorAsync. It could be that your bluetooth device would already hold the subscription with MaintainConnection. Maybe it could require one to periodically communicate, i.e. read or write some arbitrary value.

BluetoothLEAdvertisementWatcher seems good if you say so.

If you're able to create a working C#-sample I could probably help you translating it into the winrt-version. If you don't have a C# sample to start with you can use the Microsoft sample (C# and equivalent C++ code) as a starting point.

adabru avatar May 27 '21 19:05 adabru

Found an example of BluetoothLEAdvertisementWatcher here https://github.com/urish/win-ble-cpp

nathanrona avatar Jun 02 '21 13:06 nathanrona