Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 Bluetooth Low Energy Connection c#

For a project I need to get some data from a Bluetooth device on windows 10 using C#. I'm not too familiar with the Bluetooth API and can't figure out why the following is not working:

Using the BluetoothLEAdvertisementWatcher I search for advertisements, which works fine. I do receive the advertisement from the device (local name fits) as well as it's ServiceUuids. Next I try to connect to the device using the BluetoothAddress received together with the advertisement:

private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, 
                    BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
    ulong blAdress = eventArgs.BluetoothAddress;
    BluetoothLEDevice blDevice = await 
         Windows.Devices.Bluetooth.BluetoothLEDevice.FromBluetoothAddressAsync(blAdress);
}

However, doing so results in an exception:

Element not found. (Exception from HRESULT: 0x80070490).

Is this the correct way to read data from the device? Are other options available to read the data from the services? Manually pairing the device in windows is not really an option and also seems to fail.

/Edit 1: I check for the local name of the device to make sure I only try to connect to the right one. So I guess there is a problem with connecting to this specific device, still I have no idea how to work around that. The service data was succesfully read on iOS, so it should be possible.

like image 825
Stoffel Avatar asked Oct 01 '15 16:10

Stoffel


People also ask

Does Windows 10 support Bluetooth Low Energy?

Mobile operating systems including iOS, Android, Windows Phone and BlackBerry, as well as macOS, Linux, Windows 8, Windows 10 and Windows 11, natively support Bluetooth Low Energy.

Does Windows 10 have issues with Bluetooth?

Run the Windows 10 Bluetooth troubleshooter. Windows 10 has built-in troubleshooter programs that scan a computer for specific problems and fix these issues. To begin the Bluetooth troubleshooter, open the Start menu, then select Settings > Update & Security > Troubleshoot > Bluetooth.

Why is Bluetooth low power?

The difference lies in how they distribute data for energy savings. Bluetooth can handle a lot of data but quickly consumes battery life and costs a lot more. Bluetooth Low Energy is used for applications that do not need to exchange large amounts of data and can run on battery power for years at a cheaper cost.


1 Answers

Until MS fixes this problem the only reliable solution to this I have found to connect to a BLE device is to ask the registry for a list of paired BLE devices and compare the bluetooth address in the advert with with registry list of paired able devices. My experience is that when FromBluetoothAddressAsync is called on an unpaired device Windows throws an exception and kills the watcher thread. I have some C++ code that I am happy to share that reads the registry and creates a list of paired BLE devices.

Hopefully MS will take the time to fully support BLE in the same manner Apple does.

like image 120
oregonduckman Avatar answered Sep 30 '22 10:09

oregonduckman