adabru / BleWinrtDll

BLE for Unity 3d in Windows without UWP.
Do What The F*ck You Want To Public License
168 stars 52 forks source link

Device Filtering by Service #61

Open buggzd opened 7 months ago

buggzd commented 7 months ago

image How can I filter devices during a search based on the services they provide? This is a packet I captured in Wireshark, and I would like to filter devices that only include the 'heartrate' service class UUID. I apologize as I am still a beginner in Bluetooth development.

adabru commented 7 months ago

This is what ChatGPT suggests:

If you want to use DeviceWatcher with an Advanced Query String (AQS) filter to specifically filter devices based on a GATT (Generic Attribute Profile) service UUID, you can use the System.Devices.Aep.ProtocolId property in the AQS filter. Here's an example:

using System;
using Windows.Devices.Enumeration;

class Program
{
    static void Main()
    {
        // Specify the GATT service UUID you're interested in (e.g., Heart Rate service)
        string serviceUuid = "{0000180D-0000-1000-8000-00805F9B34FB}";

        // Construct the AQS filter for GATT services
        string aqsFilter = $"System.Devices.Aep.ProtocolId:=\"{serviceUuid}\"";

        // Create a DeviceWatcher with the specified AQS filter
        DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher(aqsFilter);
...

Taking from here: https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/aep-service-class-ids the default protocol identifier is "all ble services".