Bluetooth LE device stopped connecting in Windows 10 v1709 - windows-10

I've created a WDK library for interacting with a Bluetooth LE device (closly following the example here). The library worked well on a previous version of Windows - I was able to connect to my device, write characteristics and get asynchronous notifications. Once I updated to Windows to version 1709 (build 16299.98), the library stopped working:
pair the device via Settings-->Devices-->Bluetooth
the BLE device blinks a led as an indication of Advertising
Run my application which uses aforesaid library
Once the application opens the paired device's handle (using hDevice = CreateFile(pInterfaceDetailData->DevicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);), the device blinks spasmodically, indicating that it connects and disconnects very fast.
Sometimes, after several long seconds, the device has solid light, indicating it is connected (the status in Windows Settings is also 'Connected')
Any access to the device from my code (e.g. by calling BluetoothGATTSetDescriptorValue() to enable BLE notification), fails with a timeout (ERROR_SEM_TIMEOUT))
For some reason, first-time pairing with the device does not exhibit these symptoms.
Any ideas?
If its relevant, my local Bluetooth device is Qualcom Atheros USB module (VID_0489&PID_E076&REV_0001).

This was an issue with Windows 10, resolved in KB4054517

Related

Establish a connection between smartphone and PC via Bluetooth automatically

I'm trying to establish a connection between my PC running Ubuntu and my iPhone via Bluetooth automatically when it becomes available, after being manually paired beforehand. I've seen this to be possible with certain peripherals, mainly audio. For example, my phone will automatically connect to a Bluetooth speaker when it is turned on and Bluetooth is active on my phone; another example is my phone automatically connects to my car's radio system via Bluetooth when I turn the car on.
I'm not able to connect my phone to my PC without first initiating the connection from the smartphone's Bluetooth menu. I'm thinking that I could possibly write an application for the PC to attempt to connect to the device every few minutes or something, but it seems that the phone needs to be the device to initiate the connection.
The only information that I need for what I'm trying to do ultimately is that the devices can pair successfully. Essentially I'm trying to build a sort of proximity trigger between my phone and my PC without using Wi-Fi and GPS - I can't use these for some specific reasons.
Is there any way to make this happen?
Yes this should be doable as long as you use the Background Processing feature for iOS apps. In the example I'll give below, we'll have the PC be the peripheral and the phone be the central, but you can really have it working either way. You will need to do the following:-
First initial connection needs to be performed in the foreground (this is due to iOS's background limitations).
On the iOS side, you need an application that acts as a central that scans and connects to the remove device (check this example as a starting point).
Upon connection, you need to bond with the PC. Bonding is important as it will prevent you from having to do the pairing again in the future. However, pairing/bonding is managed by the iPhone's OS so you cannot write it in your application, so the workaround is to have an encrypted characteristic on the PC side that will force the iPhone to bond (this is covered later).
On the PC side, you need to have a BlueZ script that acts as a peripheral that is always advertising. You can do this using bluetoothctl (check the examples here and here).
Before you start advertising, you need to have a GATT server on the PC side (to do this, check this example).
When registering characteristics, ensure that one of them has the encrypt-read property (you can find a full list of the properties here).
Now when you attempt to read this characteristic from the iOS side, the two devices should bond (make sure that your PC is bondable which you can do this via these commands).
Once the devices are paired, your iOS app needs to be working in the background constantly scanning and attempting to connect to the same peripheral (have a look at this and this example).
You can find more useful information at the links below:-
Getting started with Bluetooth Low Energy
The Ultimate Guide to CoreBluetooth Development
How to manage Bluetooth devices on Linux using bluetoothctl

Windows 10 IoT and Adafruit M0 BLE comminication [duplicate]

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.

Windows 10 IoT Bluetooth LE

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.

Bluetooth Dongle and iOS Simulator

I have bought an IOGEAR GBU521 bluetooth dongle as per the instruction on Apple's technote:
http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
I have also configured it as instructed and I'm trying to get the temperaturesensor demo to work but the Bluetooth under settings never seems to turn on (keeps spinning). Looking at the console, here is what I see:
2012-11-02 4:17:08.114 PM Preferences[862]: BTM: setting discoverable status enabled
2012-11-02 4:17:08.114 PM Preferences[862]: BTM: setting connectable enabled
2012-11-02 4:17:08.115 PM Preferences[862]: BTM: enabling device scanning
2012-11-02 4:17:08.115 PM Preferences[862]: BTM: failed to start scanning with error 111
Any thoughts? I've seen people ask about this but has anyone got this approach to work?
Best,
Throw away the IOGEAR and pick up a Cirago BTA8000.
I bought the IOGEAR you mention, in addition to the Cirago BTA8000, and the MediaLink 4.0 adapter. Turns out that anything based on the Broadcom chip won't work despite my MacBook having the exact same one built in, which means the MediaLink and IOGEAR don't work. My Cirago shipment just arrived this morning, and the Bluetooth slider in the iOS Simulator flicks to "ON" in less than a second.
If you want to experiment, I'd love to hear if other non-Broadcom chips work too.
I just bought a GBU521 from amazon to upgrade the BT in my MacBook8,3
I had the same problem of it not showing up. Reading the same article you referenced (TN2295) I did a sudo nvram bluetoothHostControllerSwitchBehavior="always" which tells the system to ALWAYS switch to a bluetooth controller if one is plugged in.
The default option:
when a new HCI is connected, the built-in driver only disconnects from the built in HCI and attaches to the external HCI if the new module is not an Apple module.
I presume that because the vendor IDs matched (0xa5c) that it was not switching over to the new dongle. Setting it to always causes OSX to always switch to a new BT adapter. This is confirmed by the following statement in TN2295:
Open the System Information application to verify that the system Bluetooth driver is matched to the built-in Bluetooth host controller interface (HCI). For the Hardware->Bluetooth setting, verify that the Vendor ID is "0x5AC".
Rebooting after the nvram update and I was able to re-pair all of my devices without incident.
HOWEVER this will not work for iOS BT LE development due to the following statement in TN2295:
If the system Bluetooth controller is matched to the Bluetooth LE USB adapter, then the iOS simulator will not be able to use the external Bluetooth controller for Bluetooth LE services.
Actually, you can mod the Info.plist inside the BroadcomBluetoothHostControllerUSBTransport.kext found here:
/System/Library/Extensions/IOBluetoothFamily.kext/Contents/PlugIns/BroadcomBluetoothHostControllerUSBTransport.kext/Contents/Info.plist...
Just copy another Broadcom dictionary and modify it or use the following additon to the Info.plist. You'll need to do this as an admin (i.e. sudo nano or vi this file after making a copy of the original).
<key>Add an appropriate name here</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport</string>
<key>IOClass</key>
<string>BroadcomBluetoothHostControllerUSBTransport</string>
<key>IOProviderClass</key>
<string>IOUSBDevice</string>
<key>idProduct</key>
<integer>8680</integer>
<key>idVendor</key>
<integer>2652</integer>
</dict>
May need to reboot after the edit. Did this on 2012 MacBook Pro, ran XCode, and it allowed access to the Bluetooth dongle in iOS Simulator!
I hope this helps!

Configuring BT support in Linux (Android)

I'm trying bring up Bluetooth over USB support on a new ARM-based Android device. I think I'm missing some magic piece of configuration in order to successfully open a BT socket connection.
BT is provided through a USB dongle (vs. UART in most Android devices)
I can successfully run "hcitool scan" to discover devices.
I can open a socket via libbluetooth in C
When I try to establish an RFCOMM connection the connection, the connection
is refused because an L2CAP connection cannot be established.
Also,
for some OS's, I'm required to approve a pairing. (Older Ubuntu, some flavors of Windows' BT stack.)
the peripheral device doesn't require a PIN, but in some cases I'm requested to provide one. (Windows has asked for this. Older version of Ubuntu has asked for this. It may also be when using BT 2.0 dongles, vs. BT 2.1 and up?).
Bluetooth provided with Ubuntu 10 on my PC requires neither PIN nor pairing.
Am I missing a piece of config that says, i) auto-pair devices, ii) don't request a PIN if none is required?
Is there a guide to this online? Documentation seems limited.

Resources