Windows 10 Bluetooth LE Reconnecting Without Pairing?

0

I am unable to reconnect to my Bluetooth Low Energy Only Device using the Windows 10 API for Bluetooth without repairing each time (Windows 8.1 works). I am able to pair to the custom device through code, and am able to connect and subscribe for notifications but when I disconnect and try to reconnect again later, I get the following exception when trying to subscribe for notifications.

The semaphore timeout period has expired. (Exception from HRESULT: 0x80070079)

and sometimes I get:

'System.Exception' in mscorlib.ni.dll There is no user session key for the specified logon session. (Exception from HRESULT: 0x80070572)

In my code, I am settings DevicePairingProtectionLevel to None when I pair through the code, so I am not sure why it might want stored bond information that my device doesn't store. Furthermore, the same code works on Windows 8.1, you only have to pair once and it connects automatically after. Here is my code:

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("FE25C237-0ECE-443C-B0AA-E02033E7029D")));
if (devices.Count == 1)
  bleDevice = devices[0];
else
  Console.WriteLine("There was more than one Bluetooth device!");

accService = await GattDeviceService.FromIdAsync(bleDevice.Id);
accConfig = accService.GetCharacteristics(new Guid("27B7570B-359E-45A3-91BB-CF7E70049BD2"))[0];
accConfig.ValueChanged += rxCharacteristicValueChanged;
await accConfig.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

Here in the Microsoft docs it says (at the bottom) "This feature is not available for Bluetooth Low Energy (GATT Client), so you will still have to pair either through the Settings page or using the Windows.Devices.Enumeration APIs in order access these devices." at the bottom, does that mean I have to pair and unpair every time I connect? I can pair and unpair through code, but pairing takes about 20-30 seconds which is too long to expect my users to wait for that long.

c#
bluetooth
win-universal-app
windows-10
bluetooth-lowenergy
asked on Stack Overflow Oct 13, 2016 by daniel metlitski • edited Oct 13, 2016 by daniel metlitski

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0