I got an issue with reconnection to my BLE device.
Senario that works - BLE Device is not paired - Pi boots and start my App, find's the BLE device, pair and connect, receiving data - Boot Pi and start my App, it will not pair as its already paired, it connects fine and receiving data.
Senario that does not work - BLE Device is not pair or pair, does not matter - If my BLE device disconnect due to power loss or out of range and gets powered up or back in range the Pi will reconnect and throw: 'System.Exception' in mscorlib.ni.dll There is no user session key for the specified logon session. (Exception from HRESULT: 0x80070572)
If I try to reboot the Pi, the same message is thrown when I try to execute: await _readCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
The only thing that works is if I unpair the device every time it disconnect.
This is the same issue that this guy has: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b98d77f2-bf5e-45fc-9495-1c444b54450e/uwpreconnecting-to-a-ble-csac-device-causes-exception?forum=wpdevelop
Maybe there is anyone here that has seen the same issue and solved it ?
Thanks
The reason for this particular error you are receiving is almost certainly that the BLE device itself is not storing the bonding information that is negotiated during the pairing process. For an existing BLE pairing to be re-used, the device must retain the bonding with its partner for future communication sessions.
Developers can sometimes work around this device shortcoming in their (non-Windows) PC or phone application by having the PC or Mobile app delete any previous pairings with the device already retained, and negotiate a new pairing each time it sees the Bluetooth device. This is possible because many Bluetooth devices have a static PIN, require no interaction for pairing, and remain in open pairing mode. So the app creates a new device pairing upon each communication. The Mac BLE API requires no user interaction for pairing and un-pairing as well.
But this solution is unworkable under Windows BLE API, because unlike regular Bluetooth, the Bluetooth Low Energy API requires user interaction during both the pairing, and un-pairing "ceremonies". The user must agree to every pairing, and must agree to every un-pairing. This makes this workaround solution a non-starter from a UX standpoint on Windows. My guess is the BLE device manufacturer isn't storing the bonding.
We ran into such a situation ourselves developing our own BLE driver to speak with our own BLE board; we had to re-do the firmware running our BLE device because while it would work under Mac OS and Android with the method described above, the BLE API available on the Microsoft UWP requires user interaction during the pairing ceremony. This seems the right way to do things, anyway.
in Microsoft all not far mind. To read the bluetooth device you need to do so many actions. Level of abstraction rolls over. They do work for the sake of work. Thoughtful architecture and does not smell. The world of development is slowly moving to Linux. Increasingly every year. Soon the day will come when the MS will lose users.
来源:https://stackoverflow.com/questions/37884150/windows-10-iot-and-adafruit-m0-ble-comminication