How to programmatically connect to a paired Bluetooth device when the connection is lost in Windows 10 UWP

I have a Windows 10 UWP application that can be programmed using a bluetooth LE device. Once pairing is successful, a connection to the device will be established.

If at some point the device turned off, I could not read any of the GattCharacteristics characteristics from the LE device. I can check if the connection is present or not, but I cannot reconnect.

DeviceInformation deviceInfo = await DeviceInformation.CreateFromIdAsync("deviceId", "additionalProperties", "DeviceInformationKind"); if(deviceInfo.ConnectionStatus != BluetoothConnectionStatus.Connected) { // re-establish the connection } 

Thanks.

+5
source share
1 answer

Problem

The Bluetooth LE device does not save the connection information created during the pairing process. The pairing information allows two previously paired devices to initiate new connections if they were disconnected.

Solution for Windows 10

Using the APIs in the application , you can programmatically tell the system about a connection to a Bluetooth LE device (it looks like you're already doing this). To work around the communication problem described above, the value of DevicePairingProtectionLevel should be set to None . Thus, your connection code in the application may look like this:

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

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

Peripheral solution

Alternatively, if you have access to peripheral firmware, you can install it to remember connection information. Then your current pairing calls with Windows 10 should work.

+7
source

All Articles