inthehand / 32feet

Personal Area Networking for .NET. Open source and professionally supported
https://inthehand.com/components/32feet/
MIT License
814 stars 205 forks source link

BluetoothLE - Device Names #291

Open wagenheimer opened 1 year ago

wagenheimer commented 1 year ago

Using the command
var devices = await Bluetooth.ScanForDevicesAsync(); It founds this device :

Device ID "40D84FE277B" - Device Name = "BLE-TX R2 P3 F78 S02020"

But if I use

scan = await Bluetooth.RequestLEScanAsync(new BluetoothLEScanOptions { KeepRepeatedDevices = false, AcceptAllAdvertisements = false });

private void Bluetooth_AdvertisementReceived(object sender, BluetoothAdvertisingEvent e)
{
                Debug.WriteLine($"{e.Device.Name}");
}

Sometimes it found my device with the full name "BLE-TX R2 P3 F78 S02020", but other times it only shows "Plat. Celmi".

Using ScanForDevicesAsync I always have the correct name, but it needs to wait for the search to end. I would like to use RequestLEScanAsync because it does not need to wait for the search to end.

peterfoot commented 1 year ago

The name returned in an advertisement can be a shortened name rather than the full device name. The Windows device scan does a name lookup behind the scenes and populates the full device name. I'm looking at adding more control over the ScanForDevices method so that you can break out of it with a cancellation token or a shorter defined timeout.

acaliaro commented 4 months ago

@peterfoot is it possible to cancel RequestLEScanAsync?