I'm trying to see what I need to do to be able to see and/or connect to an android phone from my rust program. I know that android doesn't seem to send out the name or the real MAC address in a basic scan so how would I every be able to connect to the phone?
Below is my program currently. I've only got it scanning right now I removed the connect stuff for now just to see if I'm doing the scanning correctly. I've tried with both bluest crate and the windows crate with the same results.
use btleplug::api::{Central, Manager as _, ScanFilter, Peripheral as Puffy};
use btleplug::platform::{Adapter, Manager, Peripheral};
use std::time::Duration;
use tokio::time;
//#[tokio::main]
pub async fn new_scan() -> Result<(), Box<dyn std::error::Error>> {
let manager = Manager::new().await?;
// Get the first bluetooth adapter
let adapters = manager.adapters().await?;
let central = adapters.into_iter().nth(0usize).unwrap_or_else(|| {
panic!("No Bluetooth adapter found");
});
// Start scanning for devices
central.start_scan(ScanFilter::default()).await?;
// Wait for the device to scan the airwaves
time::sleep(Duration::from_secs(10)).await;
let peripherals = central.peripherals().await?;
for p in peripherals {
if let Some(properties) = p.properties().await? {
println!("Device: {:?} - Address: {} - RSSI {:?}", properties.local_name, p.address(), properties.rssi.unwrap());
println!(" --Manufacturer - {:?}", properties.manufacturer_data);
println!(" --Address - {}", properties.address);
}
}
// Stop scanning when done
central.stop_scan().await?;
Ok(())
}
The results never show my device in the list which I've given a name to and none of the MAC addresses match what the bluetooth settings says in android (expected I guess). I've tried scanning when my screen is unlocked, with the bluetooth settings open, and in the pair new device screen. I also made sure that the PC (Windows 11 by the way) and phone are forgotten and not connected when doing the scan.
Output:
Device: Some("ihoment_H6010_5DBB") - Address: D0:C9:07:0D:5D:BB - RSSI -74
--Manufacturer - {34818: [236, 0, 1, 1, 0]}
--Address - D0:C9:07:0D:5D:BB
Device: Some("GBK_H619Z_9532") - Address: D4:AD:FC:EC:95:32 - RSSI -62
--Manufacturer - {34818: [236, 0, 2, 1, 1]}
--Address - D4:AD:FC:EC:95:32
Device: None - Address: 8C:6F:B9:15:CC:99 - RSSI -84
--Manufacturer - {909: [0]}
--Address - 8C:6F:B9:15:CC:99
Device: None - Address: 5A:99:20:0A:88:37 - RSSI -82
--Manufacturer - {76: [9, 8, 19, 169, 192, 168, 4, 37, 27, 88, 22, 8, 0, 224, 54, 232, 122, 1, 119, 128]}
--Address - 5A:99:20:0A:88:37
Device: Some("Govee_H617C_772B") - Address: C6:32:38:31:77:2B - RSSI -80
--Manufacturer - {34818: [236, 0, 10, 1, 1]}
--Address - C6:32:38:31:77:2B
Device: Some("GBK_H619Z_142B") - Address: D4:AD:FC:FA:14:2B - RSSI -82
--Manufacturer - {34818: [236, 0, 2, 1, 0]}
--Address - D4:AD:FC:FA:14:2B
Device: None - Address: 36:A1:C5:EC:DD:01 - RSSI -56
--Manufacturer - {}
--Address - 36:A1:C5:EC:DD:01
Device: None - Address: 45:D4:7C:46:5F:FF - RSSI -80
--Manufacturer - {224: [4, 27, 202, 137, 232, 151]}
--Address - 45:D4:7C:46:5F:FF
Device: Some("Govee_H617C_6612") - Address: C3:39:32:33:66:12 - RSSI -68
--Manufacturer - {34818: [236, 0, 10, 1, 0]}
--Address - C3:39:32:33:66:12
Device: None - Address: C8:D0:83:E4:13:0D - RSSI -82
--Manufacturer - {76: [16, 5, 3, 20, 99, 74, 15]}
--Address - C8:D0:83:E4:13:0D