添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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
  • Does calling GattDeviceService.GetDeviceSelectorFromShortId require already connecting to the device or is this just a static method one can use at any time to get the appropriate AQS string? If that IS the case, how can I combine the strings together in order to accept advertisements from all such devices? I had tried using the 'OR' I saw documented but to no avail. Of course what I was stringing together might have been wrong. – Brian Reinhold Apr 30, 2019 at 12:09 It would help with a code example. I tried the above and it did not work. But with no example of how to accept, say 3 uuids, there may be some syntax error I am making. THere is no error; just nothing happens. So I do not no if there is, indeed an error, or the method is not working. – Brian Reinhold May 17, 2019 at 11:29

    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.