6

I have a windows 10 UWP app that is able to pair with a bluetooth LE device programmatically. Once the pairing is successful, a connection to the device is also established.

If at some point, the device gets disconnected, I am not able to read any of the GattCharacteristics from the LE device. I'm able to check if the connection is present or not but I'm unable to re-establish the connection.

DeviceInformation deviceInfo = await DeviceInformation.CreateFromIdAsync("deviceId", "additionalProperties", "DeviceInformationKind");

if(deviceInfo.ConnectionStatus != BluetoothConnectionStatus.Connected) { // re-establish the connection }

Thanks.

Vikas C
  • 155
  • 2
  • 9
  • similar [question](https://stackoverflow.com/questions/62502414/how-to-connect-to-the-paired-audio-bluetooth-device-using-windows-uwp-api). Looks like UWP API doesn't provide "Connect" method. It only allows to pair/unpair. I have implemented connection in my [utility](https://github.com/PolarGoose/BluetoothDevicePairing) by first unpairing a device and then pairing again. But I don't know if it always works properly because to pair again your device needs to be in the pairing mode. – PolarBear Dec 20 '20 at 14:42

1 Answers1

7

The Problem

The Bluetooth LE device is not storing the bonding information created during the pairing process. Bonding information allows two previously paired devices to initiate new connections if they have become disconnected.

The Windows 10 Solution

Using the in-app pairing APIs, you can programmatically tell the system to pair with the Bluetooth LE device (it sounds like you are already doing this). To work around the bonding problem described above, the DevicePairingProtectionLevel must be set to None. So your in-app pairing code could look like:

var result = await someDevice.Pairing.PairAsync(DevicePairingProtectionLevel.None);

Setting the DevicePairingProtectionLevel to None tells the system to ignore bonding information and just look for a matching device.

The Peripheral Solution

Alternatively, if you have access to the peripheral's firmware, you can set it to remember the bonding information. Then your current pairing calls on Windows 10 should work.

Carter
  • 3,053
  • 1
  • 17
  • 22
  • +1 Thanks for the explanation. Setting the DevicePairingProtectionLevel to None seems to help in accessing the data. Although I did notice at some point the connection seemed to go off. I'm testing to check consistency. Unfortunately I do not have access to the peripheral's firmware so I'll proceed with the Windows 10 solution you've explained above. Thanks! – Vikas C Jun 21 '16 at 06:11
  • I too am unable to re-establish the connection in my program. It works fine after initial paring, but at a later time it never connects again. I am not using in-app pairing, but as a test, I modified the Windows Universal Samples Scenario8_PairDevice.xaml.cs code to use DevicePairingProtectionLevel.None. I paired my device using the modified sample code. Back in my program, I was still unable to re-establish the connection at a later time. Is this DevicePairingProtectionLevel.None globally saved so any program can later re-establish the connection? – JFar Mar 29 '17 at 00:04
  • @JFar I'm not sure how the Windows 10 Creative update changes this (I expect there to be some BT updates in it), but I think that `DevicePairingProtectionLevel.None` is global. It may be that the peripheral you are trying to reconnect to is not advertising as connectable- are you able to see it with another device? – Carter Apr 17 '17 at 06:29