Windows 10 1909 BLE Connecting Without Pairing

Derek 1 Reputation point
2020-06-19T00:23:43.767+00:00

I am trying to design a Windows UWP app and I am trying to connect to a BLE device without the need to explicitly pair.

To verify that the problem is not on the BLE device side I confirmed that I can connect to the BLE device with the 'Just Works' option through the NRF connect app on Android, and on iOS.

Some info about my setup and things I have done so far:

I have Bluetooth capabilities enabled in the Manifest. I have tested that bluetooth works when pairing directly with a separate device that uses BLE such as some headphones. I have made sure that Bluetooth is turned on. I can connect to my BLE device when I used the pairing option however it displays a popup each time and I don't want that popup, I want it to just work without any interaction. When PairAsync is not used the result of FromBluetoothAddressAsync or FromIdAsync is 'Disconnected'. I am using Windows 10 1909 18363.900. I should note that this used to work on 1803. All of my bluetooth drivers are up to date. I tried this on another laptop and it did not work without the pairing popup also.

Here is my code:

private string DEVICE_ADDRESS_TEST = "C7:9C:0C:EE:EA:D1";
// Create BLE watcher
var bleWatcher = new BluetoothLEAdvertisementWatcher() { ScanningMode = BluetoothLEScanningMode.Active };

// add received callback
bleWatcher.Received += async (BluetoothLEAdvertisementWatcher w, BluetoothLEAdvertisementReceivedEventArgs btAdv) => {
    try
    {
        /// SCAN FIND DEVICE
        ulong longAgain = ulong.Parse(this.DEVICE_ADDRESS_TEST.Replace(":", ""), System.Globalization.NumberStyles.HexNumber);
        if (btAdv.BluetoothAddress != longAgain)
        {
            Logging.info($"Found device: {btAdv.BluetoothAddress}");
            return;
        }
        else
        {
            Logging.info($"Found BLE device [{DEVICE_ADDRESS_TEST}]");
            bleWatcher.Stop();
        }

        // This causes a popup to appear! I don't want this.
        //DevicePairingResult result = await di.Pairing.PairAsync(DevicePairingProtectionLevel.Encryption); 
        // This causes a popup to appear! I don't want this.
        //DevicePairingResult result = await di.Pairing.PairAsync(DevicePairingProtectionLevel.None); 

        /// CONNECT TO DEVICE
        Logging.info("Connecting...");
        var device = await BluetoothLEDevice.FromBluetoothAddressAsync(longAgain);


        var log1 = $"Connection state: [{device.ConnectionStatus}]";
        Logging.info(log1);
        if (device.ConnectionStatus != BluetoothConnectionStatus.Connected)
        {
            throw new Exception("FromBluetoothAddressAsync did not connect successfully.");
        }

        /// GET ALL SERVICES
        Logging.info("Getting services..");
        // 2) SERVICES!!
        var result = await device.GetGattServicesAsync();

        if (result.Status != GattCommunicationStatus.Success)
        {
            throw new Exception($"GetGattServicesAsync failed with result: status[{result.Status}], error[{result.ProtocolError}]");
        }

        Logging.info($"[{result.Services.Count}] services found");
    }
    catch (Exception e)
    {
        Logging.error(e.Message);
    }

};
bleWatcher.Start();

What am I doing wrong? There has to be a way to connect to devices without needing to interact with a popup. Is there a new API I am missing? Please help!

UPDATE:

I found that performing a GetGattServicesForUuidAsync or GetGattServicesAsync results in the device connecting however they both return the status 'Unreachable'. This is odd because I can see a light on that denotes if a device is connected or not. Again I have to reiterate that this behavior is only on the window platform as I can easily connect and get services using the 'just workings' on android and ios.

Universal Windows Platform (UWP)
{count} votes