CoreBluetooth devices has only default properties
felipe-dias-azevedo opened this issue · comments
Felipe Azevedo commented
I made a simple straight forward script to scan devices and list their local_name attribute and if their connected or not.
use std::error::Error;
use std::time::Duration;
use tokio::time;
use btleplug::api::{Central, Manager as _, Peripheral, ScanFilter};
use btleplug::platform::Manager;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
//pretty_env_logger::init();
let manager = Manager::new().await?;
let adapter_list = manager.adapters().await?;
if adapter_list.is_empty() {
eprintln!("No Bluetooth adapters found");
}
for adapter in adapter_list.iter() {
println!("Starting scan on {}...", adapter.adapter_info().await?);
adapter
.start_scan(ScanFilter::default())
.await
.expect("Can't scan BLE adapter for connected devices...");
time::sleep(Duration::from_secs(20)).await;
let peripherals = adapter.peripherals().await?;
if peripherals.is_empty() {
eprintln!("->>> BLE peripheral devices were not found, sorry. Exiting...");
} else {
// All peripheral devices in range
for peripheral in peripherals.iter() {
let properties = peripheral.properties().await?;
let is_connected = peripheral.is_connected().await?;
let local_name = properties
.unwrap()
.local_name
.unwrap_or(String::from("(peripheral name unknown)"));
println!(
"Peripheral {:?} is connected: {:?}",
local_name, is_connected
);
}
}
}
Ok(())
}
But it doesn't show correctly its properties. (And the devices has correct name properties, as shown on bluetooth MacOS Settings)
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `target/debug/bluetooth-scan`
Starting scan on CoreBluetooth...
Peripheral "(peripheral name unknown)" is connected: false
Peripheral "(peripheral name unknown)" is connected: false
Peripheral "(peripheral name unknown)" is connected: false
Am I doing something wrong or forgetting to do something?
Or is it CoreBluetooth's fault?
(And yes, terminal is enabled for bluetooth usage on privacy settings already.)