0

I'm to view as the advertiser whether or not it has been connected to a central device.

I've looked through previous issues and the design as based on everything on Microsoft's docs on this :https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile.gattcommunicationstatus. However they by design made it so that the advertiser can't view whether or not its connected without any sort of read/write/notify action. I was wondering if anyone had any work-arounds to this?

       GattServiceProviderAdvertisingParameters advParameters = new GattServiceProviderAdvertisingParameters
        {
            // IsConnectable determines whether a call to publish will attempt to start advertising and 
            // put the service UUID in the ADV packet (best effort)
            IsConnectable = peripheralSupported,

            // IsDiscoverable determines whether a remote device can query the local device for support 
            // of this service
            IsDiscoverable = true,
            ServiceData = buffer
        };

I want to view "IsConnectable" however I am unable to do so.

Thanks,

1 Answers1

0

I figured it out and here's my solution in case anyone else comes across this problem. The WM_DeviceChange comment pointed me in the right direction. Eventually I came across:

DeviceInformationCollection ConnectedBluetoothDevices =
               await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));

Which from that I was able to use:

 public static async void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        DeviceInformationCollection ConnectedBluetoothDevices =
               await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected));
        if(ConnectedBluetoothDevices.Count != 0)
        {
            Console.WriteLine("New Device Found.");
        } 
    }

I essentially put a check within a Timed Event to see if the connected BLE Devices incremented and if so, I wrote a message to the console.

For timers see: What is the best way to implement a "timer"?

I got the list of BLE devices code from here: Getting a list of already connected bluetooth devices on Windows 10