Im trying to read the RSSI values of a connected BLE device using btmgmt rust library, and always getting 127
.
我正在尝试使用btmgmt rust库读取连接的BLE设备的RSSI值,但总是得到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:
我确信该设备已连接,并已解决服务问题,下面是BluToothctl输出:
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:
我尝试使用CLI呼叫btmgmt,但它抱怨设备未连接:
$ 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:
只是为了检查,我比较了我连接的Bose QC3(也是BLE设备)的输出:
$ 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
- What am I missing?
- Why
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
BlueZ-5.53内核-5.15.0-83-通用
更多回答
At least for the cmd tool: try pass -t 1
for BLE public address and -t 2
for BLE random address. Otherwise it defaults to Bluetooth Classic.
至少对于cmd工具:尝试使用PASS-t1表示BLE公共地址,使用-t2表示BLE随机地址。否则,它将默认为蓝牙经典。
Thanks @Emil, tryied your suggestion, no success there"
谢谢@Emil,尝试了您的建议,但没有成功“
优秀答案推荐
After all @Emil was right, thanks!
毕竟@Emil是对的,谢谢!
If I failed to get conn-info
at first because I called:
如果我一开始因为打电话而无法获得conn-info:
sudo btmgmt -t 2 conn-info DA:A4:58:46:AE:9F
But After reading this.
The -t 2
flag location is imported:
但在读完这篇文章后。导入-t 2标志位置:
$ 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!
更多回答
我是一名优秀的程序员,十分优秀!