Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Trying to discover Bluetooth Low Energy Devices using C++/winRT UWP and apply a reasonable filter. In the git hub example there is code as follows:
hstring aqsAllBluetoothLEDevices = L"(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";
auto requestedProperties = single_threaded_vector<hstring>
({ L"System.Devices.Aep.DeviceAddress", L"System.Devices.Aep.Bluetooth.Le.IsConnectable",
L"System.Devices.Aep.IsPresent" });
deviceWatcher = DeviceInformation::CreateWatcher(aqsAllBluetoothLEDevices,
requestedProperties,
DeviceInformationKind::AssociationEndpoint
As long as I use the above, I discover all live BTLE devices; I also discover some devices that are not actively advertising so there are some bugs with the use of the
System.Devices.Aep.IsPresent
However, I would like to filter on just BTLE devices that follow certain BTLE health profiles. These profiles have services like
GATT - Blood pressure 18100000-0000-1000-8000-00805F9B34FB
GATT - Body composition 181B0000-0000-1000-8000-00805F9B34FB
GATT - Glucose 18080000-0000-1000-8000-00805F9B34FB
GATT - Health thermometer 18090000-0000-1000-8000-00805F9B34FB
GATT - Heart rate 180D0000-0000-1000-8000-00805F9B34FB
GATT - Pulse oximeter 18220000-0000-1000-8000-00805F9B34FB
GATT - Weight scale 181D0000-0000-1000-8000-00805F9B34FB
Anyone know how to configure the deviceWatcher() to report only those devices that advertise one of the above service UUIDs?
I have tried using them in the protocolId but that discovers nothing.
I see from your usage of DeviceInformation::CreateWatcher
that you have the simplest possible AQS string possible: it only distinguishes BLE devices, and the reason this case exists is you need something more precise than that. I also see you have a number of properties you want back listed in the array. As of now, you get every BLE device back, regardless of if they are any of the various profiles you're looking for.
There are two major components to your issue:
Knowing what the correct AQS strings are for the various health profiles listed. If you don't have that, you can't call CreateWatcher or use other methods to list currently available devices that support those profiles via AQS. For that, you need to call GattDeviceService.GetDeviceSelectorFromShortId if you're using the 16-bit ID, or GattDeviceService.GetDeviceSelectorFromUuid to get the string using the GUID.
In your code sample it isn't clear if #1 is the sole problem that stopped you, or if there was an issue with not knowing the AQS syntax sufficiently well to specify what you needed. If you don't know the name of what you need to search via AQS, the syntax of AQS will stop you. A quick example that gives a hint is at the bottom of the page to get the right string: https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/aep-service-class-ids In your case, what you need to do is to add the required OR conditions with the AND, where you always have your BLE protocol ID combined with whatever applicable System.Devices.AepService.ServiceClassId values you wish to filter. Pay close attention to the syntax of AQS. The more detailed documentation for AQS is here: https://learn.microsoft.com/en-us/windows/desktop/search/-search-3x-advancedquerysyntax
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.