Skip to content

Devices continue to be reported by Adapter::peripherals() after powering off #452

Open

Description

@andrewdavidmackenzie

Describe the bug
Once a device is discovered, it is always returned in the list of devices from available_ble_devices even when it is powered off.

To Reproduce
Steps to reproduce:

  1. Power on a meshtastic device
  2. Run available_ble_devices in example or own app and print out the list of devices, in a loop
  3. Power off the device

Expected behavior
The device will cease to be reported as one of the available btle devices.

Additional context
Macos Tahoe 26.2

If you stop the app/loop, and restart it. The powered off device will not be discovered, as you would expect.

This, together with the no-MAC-on-macos issue have given me a lot of issues and debugging.
Not sure where the core issue lies, in this crate or btleplug?

This is the code I have used to debug this:

            // loop scanning for devices
            loop {
                // start scanning for MeshTastic radios
                // TODO report an error if cannot scan
                let _ = central
                    .start_scan(ScanFilter {
                        services: vec![MSH_SERVICE],
                    })
                    .await;
                tokio::time::sleep(Duration::from_secs(4)).await;

                match central.peripherals().await {
                    Ok(peripherals) => {
                        let mut ble_devices_now: HashSet<String> = HashSet::new();

                        for peripheral in peripherals {
                            ble_devices_now.insert(
                                peripheral
                                    .properties()
                                    .await
                                    .unwrap()
                                    .unwrap()
                                    .local_name
                                    .unwrap(),
                            );
                        }

                        println!("Found: {:?}", ble_devices_now);
.....

I start the app running that code and it discovers my two devices and prints:
Found : {"Meshtastic_5171", "Meshtastic_47fd"}

I power off both devices, and it continues to report the same list of devices.

If I restart the app (with the devices powered off) they are not discovered.

Activity

  1. changed the title [-]Devices continue to be reported by `central.peripherals()` after powering off[/-] [+]Devices continue to be reported by `Adapter::peripherals()` after powering off[/+] on Jan 22, 2026
  2. andrewdavidmackenzie commented on Jan 30, 2026

    @andrewdavidmackenzie
    Author

    Doing some testing on Linux I can confirm this happens on MacOS only.
    In my case: Tahoe, 26.2

  3. andrewdavidmackenzie commented on Mar 2, 2026

    @andrewdavidmackenzie
    Author

    Thoughts on this one?
    Another "this is the way this platform works" case, and I should just look for a workaround in my app?

  4. qdot commented on Mar 2, 2026

    @qdot
    Contributor

    I'm working on this right now actually (see the ble-integration-test branch). I've spent the past couple of weeks building a hardware test platform to run library tests against, and now I'm seeing this issue in the test cases. It maybe a "this is the way the platform works" deal but I want to confirm first.

    Can't really give an ETA, but work is happening.

  5. andrewdavidmackenzie commented on Mar 2, 2026

    @andrewdavidmackenzie
    Author

    Nice! Thanks for the update.

  6. qdot commented on Mar 8, 2026

    @qdot
    Contributor

    Ok, so, as of v0.12, we'll have a clear_peripherals() method that'll allow you to clear the peripheral list yourself and rescan. In lieu of building in a timeout to the library for advertisements (which I'm considering but this version is already packed), will this suffice?

  7. andrewdavidmackenzie commented on Mar 8, 2026

    @andrewdavidmackenzie
    Author
  8. qdot commented on Mar 8, 2026

    @qdot
    Contributor

    "Count" and "3 times" do not mean anything in this context? Scans are not discrete.

    A combination of clear_peripherals() and connect_with_timeout() in v0.12 should get you close enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions