Vikas C
Vikas C

Reputation: 185

How to programmatically connect to paired Bluetooth device once connection is lost in Windows 10 UWP

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.

Upvotes: 6

Views: 8009

Answers (1)

Carter
Carter

Reputation: 3093

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.

Upvotes: 7

Related Questions