Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlueR does not report RSSI correctly #50

Closed
MaxG87 opened this issue Sep 29, 2022 · 5 comments
Closed

BlueR does not report RSSI correctly #50

MaxG87 opened this issue Sep 29, 2022 · 5 comments
Labels
external caused by bluetoothd or kernel

Comments

@MaxG87
Copy link

MaxG87 commented Sep 29, 2022

For a little toy project I need to obtain the strength of a signal from a Bluetooth device. I do not think this is relevant, but for the record, the devices are

  • Google Pixel 4a with latest Android
  • ASUSTek Computer, Inc. Broadcom BCM20702A0 Bluetooth (as reported by lsusb)

I am running Kernel 5.9.11, self compiled. I am using BlueR 0.13.3, because Debian's Cargo only provides Rust 1.54.

I am able to get the information I want using hcitool rssi <addr>. It seems as if my phone needs to be connected via Bluetooth, but once it is I get reliable connection strengths.

When I try to run the example discover_devices.rs, the connection strength is always reported as None. If I try to run discover_devices with --changes, sometimes I get a change RSSI event, but only once in a while, while I would need it regularly.

I even tried to write my own loop, but to no avail.

use bluer::Address;
use std::{collections::HashSet, env};

#[tokio::main(flavor = "current_thread")]
async fn main() -> bluer::Result<()> {
    // let with_changes = env::args().any(|arg| arg == "--changes");
    let filter_addr: HashSet<_> = env::args()
        .filter_map(|arg| arg.parse::<Address>().ok())
        .collect();

    env_logger::init();
    let session = bluer::Session::new().await?;
    let adapter = session.default_adapter().await?;
    loop {
        for cur_addr in &filter_addr {
            let device = adapter.device(*cur_addr)?;
            let rssi = device.rssi().await?;
            println!("{cur_addr}: {rssi:?}");
        }
    }
}

Is there something I do miss? How would I get the RSSI of a connection reliably, without relying on ChangeEvents?

@MaxG87
Copy link
Author

MaxG87 commented Sep 29, 2022

I need to correct myself. Running discover_devices --changes <addr> does not show any RSSI change for my phone. If I leave off <addr> it shows RSSI changes for other devices, though.

Using hcitool rssi the connection strength changed from 0 to -21 and took some values in between.

@surban
Copy link
Collaborator

surban commented Oct 1, 2022

Hi,

I cannot reproduce that issues. Testing on Kernel 5.19 with BlueZ 5.64 I can see the RSSI each time a device is discovered and lot's of RSSI change events:

Device changed: 03:3B:98:CA:B2:6D
    Rssi(-87)
Device changed: C0:48:E6:F2:08:BA
    Rssi(-67)
Device changed: BC:14:85:B9:34:6B
    Rssi(-86)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-75)
Device changed: 9C:8C:6E:E7:30:33
    ManufacturerData({117: [66, 4, 1, 32, 126, 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 29: [0, 1, 76]})
Device changed: 0D:AC:27:8F:85:1D
    Rssi(-84)
Device changed: 03:3B:98:CA:B2:6D
    Rssi(-86)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-71)
Device changed: C0:48:E6:F2:08:BA
    Rssi(-67)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-74)
Device changed: 9C:8C:6E:E7:30:33
    ManufacturerData({29: [0, 1, 76], 117: [66, 4, 1, 1, 126, 156, 140, 110, 231, 48, 51, 158, 140, 110, 231, 48, 50, 1, 0, 0, 0, 0, 0, 0]})
Device changed: 63:3E:F0:7A:7A:D1
    Rssi(-60)
Device changed: FC:F1:36:2A:66:3F
    Rssi(-78)
Device changed: 06:B5:84:21:53:05
    Rssi(-90)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-80)
Device changed: 64:6F:E1:D4:7C:A9
    Rssi(-81)
Device changed: FC:F1:36:2A:66:3F
    Rssi(-79)
Device changed: 9C:8C:6E:E7:30:33
    ManufacturerData({117: [66, 4, 1, 32, 126, 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 29: [0, 1, 76]})
Device changed: 0D:AC:27:8F:85:1D
    Rssi(-89)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-75)
Device changed: C0:48:E6:F2:08:BA
    Rssi(-67)
Device changed: FC:F1:36:2A:66:3F
    Rssi(-82)
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-72)
Device changed: 9C:8C:6E:E7:30:33
    ManufacturerData({29: [0, 1, 76], 117: [66, 4, 1, 1, 126, 156, 140, 110, 231, 48, 51, 158, 140, 110, 231, 48, 50, 1, 0, 0, 0, 0, 0, 0]})
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-72)
Device changed: 64:6F:E1:D4:7C:A9
    Rssi(-81)
Device changed: 03:3B:98:CA:B2:6D
    Rssi(-72)
Device changed: 0D:AC:27:8F:85:1D
    Rssi(-89)
Device changed: 9C:8C:6E:E7:30:33
    ManufacturerData({117: [66, 4, 1, 32, 126, 23, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 29: [0, 1, 76]})
Device changed: 9C:8C:6E:E7:30:33
    Rssi(-74)
Device changed: BC:14:85:B9:34:6B
    Rssi(-76)

Maybe try another Bluetooth adapter?

Also, hcitool is accessing the Bluetooth adapter directly and bypassing bluetoothd. Could you check what bluetoothctl is reporting for the RSSI?

@MaxG87
Copy link
Author

MaxG87 commented Oct 1, 2022

Thank you for your reply.

I tested the situation very thoroughly on my Thinkpad T470p:

  • its Bluetooth adapter, as reported by lsusb, is Intel Corp. Bluetooth wireless interface
  • I use Kernel 5.19 and BlueZ 5.65, both from Debian Testing's package repository
  • I also directly used BlueR 0.15.0 (rev. c935112)

On this setup I can reproduce the issue. RSSI changes are not detected for my Pixel 4a by discover_devices. At the same time, hcitool rssi shows plausible fluctuations. I tried to dig deeper by connecting a Fairphone 3. For the Fairphone 3 discover_devices picks up some RSSI fluctuations, but not as many as hcitool rssi does.

As requested I ran bluetoothctl | grep -Fe $RSSI_PIXEL -e "$RSSI_FairPhone and then started discover_devices again. For the Fairphone, all RSSI changes were reported by both tools, but no RSSI changes were reported for the Pixel 4a by neither of the two commands.

If this boils down to that I do not properly use bluetoothctl or need to change some configuration, I would be very glad if you could provide me a pointer. I'd open a new issue / question on SO if desired.

Thank you very much for your help.

@surban
Copy link
Collaborator

surban commented Oct 2, 2022

Could you try adding rssi: Some(1) to the DiscoveryFilter at https://github.com/bluez/bluer/blob/master/bluer/src/adapter.rs#L205 and retry?

However, if BlueR and bluetoothctl show the same behavior, then your problem is caused by bluetoothd which is used by both BlueR and bluetoothctl. You could try adjusting the scan filter (menu scan) in bluetoothctl or ask in the BlueZ slack if somebody has an idea.

@MaxG87
Copy link
Author

MaxG87 commented Oct 4, 2022

The line did not change anything. I will reach out to the BlueZ community then. Thank you for your help!

@MaxG87 MaxG87 closed this as completed Oct 4, 2022
@surban surban added the external caused by bluetoothd or kernel label Oct 4, 2022
otaviojr added a commit to otaviojr/bluer that referenced this issue May 10, 2023
# This is the 1st commit message:

BLE Passive Scanning

# This is the commit message #2:

monitor

# This is the commit message bluez#3:

monitor

# This is the commit message bluez#4:

monitor

# This is the commit message bluez#5:

monitor

# This is the commit message bluez#6:

monitor

# This is the commit message bluez#7:

monitor

# This is the commit message bluez#8:

monitor

# This is the commit message bluez#9:

monitor

# This is the commit message bluez#10:

monitor

# This is the commit message bluez#11:

monitor

# This is the commit message bluez#12:

monitor

# This is the commit message bluez#13:

monitor

# This is the commit message bluez#14:

monitor

# This is the commit message bluez#15:

monitor

# This is the commit message bluez#16:

monitor

# This is the commit message bluez#17:

monitor

# This is the commit message bluez#18:

monitor

# This is the commit message bluez#19:

monitor

# This is the commit message bluez#20:

monitor

# This is the commit message bluez#21:

monitor

# This is the commit message bluez#22:

monitor

# This is the commit message bluez#23:

monitor

# This is the commit message bluez#24:

monitor

# This is the commit message bluez#25:

monitor

# This is the commit message bluez#26:

monitor

# This is the commit message bluez#27:

monitor

# This is the commit message bluez#28:

monitor

# This is the commit message bluez#29:

monitor

# This is the commit message bluez#30:

monitor

# This is the commit message bluez#31:

monitor

# This is the commit message bluez#32:

monitor

# This is the commit message bluez#33:

monitor

# This is the commit message bluez#34:

monitor

# This is the commit message bluez#35:

monitor

# This is the commit message bluez#36:

monitor

# This is the commit message bluez#37:

monitor

# This is the commit message bluez#38:

monitor

# This is the commit message bluez#39:

monitor

# This is the commit message bluez#40:

monitor

# This is the commit message bluez#41:

monitor

# This is the commit message bluez#42:

monitor

# This is the commit message bluez#43:

monitor

# This is the commit message bluez#44:

monitor

# This is the commit message bluez#45:

monitor

# This is the commit message bluez#46:

monitor

# This is the commit message bluez#47:

monitor

# This is the commit message bluez#48:

monitor

# This is the commit message bluez#49:

monitor

# This is the commit message bluez#50:

monitor

# This is the commit message bluez#51:

monitor

# This is the commit message bluez#52:

monitor

# This is the commit message bluez#53:

monitor

# This is the commit message bluez#54:

monitor

# This is the commit message bluez#55:

monitor

# This is the commit message bluez#56:

monitor

# This is the commit message bluez#57:

monitor

# This is the commit message bluez#58:

monitor

# This is the commit message bluez#59:

monitor

# This is the commit message bluez#60:

monitor

# This is the commit message bluez#61:

monitor

# This is the commit message bluez#62:

monitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external caused by bluetoothd or kernel
Projects
None yet
Development

No branches or pull requests

2 participants