none
Bluetooth LE services disappear after inserting bluetooth adapter in another USB port RRS feed

  • Question

  • Hi. I create a Bluetooth Low Energy app that connects to BLE devices.

    I noticed that the services discovered does not seem to be bound to a particular BLE device, but rather a combination of USB port, Bluetooth adapter and the BLE device which seems very strange.

    Usually if you only use your Bluetooth adapter in one port all the time there will be no problems. Then the services are discovered immediately after pairing and will remain cached even if you reboot your machine. But if you move your adapter to another USB port, by looking at the Windows Device Manager with the option "View -> Devices by connection" and "View -> Show hidden devices" the BLE devices are now shown as a different node in the tree with no services and an exclamation mark and the status is "STATUS_DEVICE_POWER_FAILURE". It appears the system tries to connect to the divece and do service discovery and gives up forever (until replugged) after 20 seconds if the device is not advertising. If the device is advertising and is connectable at the same time you insert the adapter, the service discovery succeeds. But that would probably be a quite unusual case since most BLE devices are not advertising all the time in order to save power, and it is also a big chance it isn't near the computer at the time you insert the adapter. Even when the device becomes present and you intend to connect to it, you won't have any services visible to interact with. The only user friendly option we can tell the user in the app seems to be to tell to re-pair the device, which is not very nice.

    My vote is that you simply do not redo the service discovery when inserting the Bluetooth adapter in another USB port since there should really be no reason for doing so. If you still want the tree-formed device structure, just copy over the services from the other place in the tree where the adapter was inserted last time.

    A simple sample code that shows the problem is the following:

    var bleDev = await BluetoothLEDevice.FromBluetoothAddressAsync(0xabcdefabcdef);
    var services = bleDev.GattServices.ToArray();
    foreach (var service in services)
    {
        Console.Out.WriteLine(service);
    }

    If you run that when the adapter is plugged in to the same port as when the device was paired, it prints all the services. If you then plug the adapter into another port (without the device advertising) and run the program again, it prints no services.

    This is how it looks in my device manager (in Swedish):


    Monday, May 30, 2016 9:51 AM

All replies

  • Use BLE adapter that has a "USB serial number". Then it will be recognized as same adapter in any port.

    -- pa

    Monday, May 30, 2016 12:05 PM
  • While that might work for a few USB adapters that have a "serial number", it will not solve the problem for all the users that will use my app, think how many different bluetooth adapters there are on the market.

    On the bluetooth level, the bdaddr of the adapter should be treated as the unique identifier.

    FYI: the one I have is a CSR8510 A10 chipset, which seems to be a pretty common one.
    • Edited by EmilenL Monday, May 30, 2016 1:40 PM
    Monday, May 30, 2016 1:38 PM