Skip to content

Conversation

@lukipuki
Copy link
Collaborator

Summary
The available_ble_devices() is requested by many users to detect BLE devices running Meshtastic.

Also refactored BleHandler:

  • added available_peripherals method, factoring out logic out of BleHandler::find_ble_radio.
  • added comments

Related Issues
#32

Checklist

  • Tests pass locally
  • Documentation updated if needed

@lukipuki lukipuki mentioned this pull request Oct 25, 2025
2 tasks
#[cfg(feature = "bluetooth-le")]
pub async fn available_ble_devices(
scan_duration: Duration,
) -> Result<Vec<(Option<String>, BDAddr)>, Error> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewdavidmackenzie @matthewCmatt please test this new API.

  • name doesn't have to be always available, so we return Option<String>
  • you can do let ble_id = BleId::from(mac_addr); where mac_addr is BDaddr. And then use ble_id in build_ble_stream.

I decided to keep btleplug::BDaddr as part of the API but I've also considered using a different type. String is the next obvious choice but it would have to only have try_from() instead of from(), which is not so convenient . The other choice is implementing own MAC address type, which I find too tedious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it would be nicer to have a struct with two fields instead of (Option<String>, BDaddr) and I intend to do that. Please confirm first that this approach works for you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the struct, and if possible that it implements PartialEq, Eq - so that I can have a Vec of them, and use contains() to determine if an instance is in the Vec.

Also refactored BleHandler:
* added available_peripherals method, factoring out logic out of
  BleHandler::find_ble_radio.
* added comments
@andrewdavidmackenzie
Copy link
Contributor

Trying to update...

cargo update
    Updating crates.io index
    Updating git repository `https://github.com/lukipuki/meshtastic-rust.git`
error: failed to select a version for `indexmap`.
    ... required by package `toml v0.9.8`
    ... which satisfies dependency `toml = "^0.9.8"` of package `meshchat v0.1.0 (/Users/amackenz/workspace/meshchat)`
versions that meet the requirements `^2.11.4` are: 2.12.0, 2.11.4

all possible versions conflict with previously selected packages.

  previously selected package `indexmap v2.11.0`
    ... which satisfies dependency `indexmap = "=2.11.0"` of package `meshtastic v0.1.7 (https://github.com/lukipuki/meshtastic-rust.git?branch=ble-scan#4016c10a)`
    ... which satisfies git dependency `meshtastic` of package `meshchat v0.1.0 (/Users/amackenz/workspace/meshchat)`

failed to select a version for `indexmap` which could resolve this conflict

I have a direct dependency on
toml = "0.9.8"

possible to update to a newer version of toml?

@lukipuki
Copy link
Collaborator Author

Trying to update...

cargo update
    Updating crates.io index
    Updating git repository `https://github.com/lukipuki/meshtastic-rust.git`
error: failed to select a version for `indexmap`.
    ... required by package `toml v0.9.8`
    ... which satisfies dependency `toml = "^0.9.8"` of package `meshchat v0.1.0 (/Users/amackenz/workspace/meshchat)`
versions that meet the requirements `^2.11.4` are: 2.12.0, 2.11.4

all possible versions conflict with previously selected packages.

  previously selected package `indexmap v2.11.0`
    ... which satisfies dependency `indexmap = "=2.11.0"` of package `meshtastic v0.1.7 (https://github.com/lukipuki/meshtastic-rust.git?branch=ble-scan#4016c10a)`
    ... which satisfies git dependency `meshtastic` of package `meshchat v0.1.0 (/Users/amackenz/workspace/meshchat)`

failed to select a version for `indexmap` which could resolve this conflict

I have a direct dependency on toml = "0.9.8"

possible to update to a newer version of toml?

This is a consequence of #69

I think the best way forward would be bumping MSRV to 1.84 and then dropping indexmap dependency, because this is getting annoying. I'll get to it soon.

@lukipuki lukipuki changed the base branch from main to bump-msrv October 27, 2025 19:56
@lukipuki
Copy link
Collaborator Author

The MSRV fix is in #70 and this branch contains the fix too.

@andrewdavidmackenzie
Copy link
Contributor

Confirmed that fixes the conflict. But I will wait for the struct before changing my code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants