Hello,
using DeviceWatcher and AQS I can build a query to enumerate all BLE devices, for example "System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\"" .
How can I write a query to enumerate BLE devices with a given service GUID?
Currently to find a BLE device which exposes a service with GUID 0a02ece0-e0e0-4f58-a796-36fe6b457e10 (for example) I follow the steps below
I create a query for BLE devices
string aqAllBluetoothLeDevices = "System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\"";
I create a DeviceWatcher and I start it (Added event attached)
DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher(aqAllBluetoothLeDevices, requestedProperties, DeviceInformationKind.AssociationEndpoint);
when a device is added I look for the GattDeviceService with the given GUID
BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceInformation.Id);
GattDeviceServicesResult gattDeviceServicesResult = await device.GetGattServicesAsync();
if (gattDeviceServicesResult == null || gattDeviceServicesResult.Status != GattCommunicationStatus.Success) return;
IReadOnlyList<GattDeviceService> gattDeviceServices = gattDeviceServicesResult.Services;
foreach (GattDeviceService gattDeviceService in gattDeviceServices)
{
if (gattDeviceService.Uuid == new Guid("0a02ece0-e0e0-4f58-a796-36fe6b457e10"))
{
// device with the given service found
}
}
I would like to know if I could create a query with AQS that allowed me to find the device hosting a service with a given GUID without enumerating all BLE devices.