Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 817
Vikas C Avatar asked Jun 20 '16 11:06

Vikas C


People also ask

How do I reconnect a Bluetooth device that is disconnected?

Select Remotes & Accessories — Bluetooth device name — Connect. (Android 10) Select Remotes & Accessories — Bluetooth settings — Registered devices — Bluetooth device name — Connect.

How do I get my Bluetooth to automatically reconnect?

A headset or a speaker doesn't reconnect automaticallyReturn to Settings, search for Bluetooth auto-connect and enable this feature. Make sure that the other device is within the effective Bluetooth range from your smartphone and restart it. Re-enable Bluetooth on the phone and check if the issue is fixed*.

How do I reconnect my Bluetooth device after forgetting it Windows 10?

Make sure the Bluetooth function on the both devices to pair. In the PC, right-click on the Bluetooth icon and select the option to add a new connection or device, which will make the computer search for available Bluetooth devices. When another device appears, select it to connect/pair it to your laptop.


1 Answers

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.

like image 110
Carter Avatar answered Nov 14 '22 23:11

Carter