I'm using the btleplug crate on Windows 11 to scan for peripherals and print out a list of devices' MAC address and names. For some reason, all names are missing. The code I'm using is:
use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter};
use btleplug::platform::{Manager};
use std::error::Error;
use std::time::Duration;
use tokio::time;
#[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(())
}
And the output I get is
6E:A4:49:71:1C:01: []
D3:81:93:EA:E4:B9: []
2C:76:79:7E:4B:72: []
E9:84:B3:82:CF:5A: []
25:DB:2D:F0:7B:5F: []
17:EB:FE:FD:1C:1B: []
...
The example usage in the docs use the local_name attribute assuming it exists, and I've followed that. How do I get the names to appear?