Im trying to read the RSSI values of a connected BLE device using btmgmt rust library, and always getting 127
.
pub fn get_rssi(&self) -> Result<i8, Box<std::error::Error>> {
let btmgmt = btmgmt::BTMgmt::new()?;
let address = btmgmt::address::Address::from_string(
self.addr.as_str(),
btmgmt::address::AddressType::LeRandom,
)
.ok_or("invalid address")?;
let ci = btmgmt.get_connection_info(u16::from(self.adapter_id), &address)?;
Ok(ci.rssi)
}
I know for sure that the device is connected, and had services resolved, here's bluetoothctl
output:
Device DA:A4:58:46:AE:9F (random)
Name: Device_name
Alias: Device_name
Paired: no
Trusted: yes
Blocked: no
Connected: yes #<------------------------------- Connecter yey 🙂
LegacyPairing: no
UUID: Vendor specific (********-****-****-****-************)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
RSSI: -33 #<------------------------------------ We even have RSSI here.
AdvertisingFlags:
I've tryied to call btmgmt using cli, yet it complains that the devices is not connected:
$ sudo btmgmt conn-info DA:A4:58:46:AE:9F
Get Conn Info for DA:A4:58:46:AE:9F (BR/EDR) failed. status 0x02 (Not Connected)
Just for sanity check, I've compared to my connected Bose QC3's (Also BLE device) output:
$ sudo btmgmt conn-info 4C:87:5D:0C:B5:FC
Connection Information for 4C:87:5D:0C:B5:FC (BR/EDR)
RSSI 0 TX power -3 maximum TX power 12
btmgmt
cant get connection info, while it seems everything is resolved as expected by the output of bluetoothctl
?Bluez - 5.53
Kernel - 5.15.0-83-generic
After all @Emil was right, thanks!
If I failed to get conn-info
at first because I called:
sudo btmgmt -t 2 conn-info DA:A4:58:46:AE:9F
But After reading this.
The -t 2
flag location is imported:
$ sudo btmgmt conn-info -t 2 DA:A4:58:46:AE:9F
Connection Information for DA:A4:58:46:AE:9F (LE Random)
RSSI -48 TX power 7 maximum TX power 7 <------------- Got result!