deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Peripheral names are missing on Windows 11

rsclip opened this issue · comments

Describe the bug
When getting a list of peripherals after scanning, all names are None even though they should have names. Other properties are available, only local_name is missing.

Expected behavior
All peripherals with names should have their names discovered in their properties.

Actual behavior
All peripherals have their local_name property as None.

Additional context
Using Windows 11 might be a problem. The code I'm using is:

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let manager = Manager::new().await?;

    // get adapter
    let adapters = manager.adapters().await?;
    let central = adapters.into_iter().nth(0).unwrap();

    // start scanning for devices
    central.start_scan(ScanFilter::default()).await?;
    time::sleep(Duration::from_secs(2)).await;

    // get a list of devices that have been discovered
    let devices = central.peripherals().await?;
    for device in devices {
        // print the address and name of each device
        let properties= device.properties()
            .await
            .unwrap()
            .unwrap();
        
        let names: Vec<String> = properties
            .local_name
            .iter()
            .map(|name| name.to_string())
            .collect();
        
        println!("{}: {:?}", device.address(), names);
    }

    Ok(())
}

I'm seeing this too. In another library, where the device name seems to function, it looks like it checks in two places to see if it can find the local_name. It's in C++ so it's a different language, but possibly helpful to know the local_name could be in one of two locations?

https://github.com/woodemi/quick_blue/blob/master/quick_blue_windows/windows/quick_blue_windows_plugin.cpp#L342

  auto device = co_await BluetoothLEDevice::FromBluetoothAddressAsync(args.BluetoothAddress());
  auto name = device ? device.Name() : args.Advertisement().LocalName();