BluetoothLEDevice PairAsync intermittantly fails

EbbeK 1 Reputation point
2020-06-16T19:40:04.663+00:00

Working on an application that connects to a bluetooth low energy device that requires an initial pairing before the device characteristics and services can be subscribed or read etc.

Sometimes the pairing of the device fails, unfortunately, the result from the pairing call does not give any useful information as to why the pairing fails.

Pairing failed for Device Id: [BluetoothLE#BluetoothLE50:e0:85:82:1b:ca-88...] Status: [Failed] ProtectionLevelUsed: [None]

Here is the code that performs the pairing process with the device.

/// <inheritdoc/>
public async Task PairAsync()
{
await OperationExceptionHandler.ExecuteOperation(nameof(NativeBleDevice), async () =>
{
if (!_bluetoothLeDevice.DeviceInformation.Pairing.CanPair)
{
throw new BleDeviceException($"[{nameof(NativeBleDevice)}] Id: {_bluetoothLeDevice.BluetoothDeviceId} CanPair: [{_bluetoothLeDevice.DeviceInformation.Pairing.CanPair}]");
}

            try
            {
                if (!_bluetoothLeDevice.DeviceInformation.Pairing.IsPaired)
                {
                    _bluetoothLeDevice.DeviceInformation.Pairing.Custom.PairingRequested += CustomOnPairingRequested;

                    var result = await _bluetoothLeDevice.DeviceInformation.Pairing.Custom.PairAsync(
                          DevicePairingKinds.ConfirmOnly, DevicePairingProtectionLevel.Encryption);

                    if (result.Status != DevicePairingResultStatus.Paired)
                    {
                        throw new EkoDeviceNotPairedException($"Pairing failed for Device Id: [{_bluetoothLeDevice.DeviceId}] Status: [{result.Status}] ProtectionLevelUsed: [{result.ProtectionLevelUsed}]");
                    }
                }
            }
            finally
            {
                _bluetoothLeDevice.DeviceInformation.Pairing.Custom.PairingRequested -= CustomOnPairingRequested;
            }
        });
    }
    private void CustomOnPairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
    {
        args.Accept();
    }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,709 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MSFT-RobinChen 1 Reputation point
    2020-06-18T11:39:24.52+00:00

    Refer to https://learn.microsoft.com/en-us/uwp/api/windows.devices.enumeration.devicepairingresultstatus?view=winrt-19041, Status Failed means "An unknown failure occurred.".

    For more details about the exact reason, we usually need more details ETL trace about the issue. And analyzing etl trace needs private symbols.


  2. EbbeK 1 Reputation point
    2020-08-18T00:52:03.44+00:00

    Hi @MSFT-RobinChen ,

    Please find the ETl trace at the following https://www.dropbox.com/s/qhu1tpwtnnq54pc/BthTracing_CPU_2.etl?dl=0

    Main issue using Lenovo X1 Carbon Gen 7 after attempting to fix bluetooth through "Fix bluetooth"..

    Attempt to connect/pair to ble 4.2 device using windows bluetooth menu: Unsuccessful.
    Attempt to connect/pair to ble 4.2 device using wpf windows application: unsuccessful.

    I have noticed that IsConnectable and IsConnected switch from true to false intermittently at a millisecond interval.

    Please let me know if you need more information. Thank you for your help.

    Regards,
    Konrad

    0 comments No comments

  3. EbbeK 1 Reputation point
    2020-10-30T21:54:50.187+00:00

    Hi @MSFT-RobinChen ,

    Any update on this issue?

    Regards,
    Konrad

    0 comments No comments