Skip to main content

BluerAdapter

Struct BluerAdapter 

Source
pub struct BluerAdapter { /* private fields */ }
Expand description

Linux/BlueZ BLE adapter

Implements the BleAdapter trait using the bluer crate for BlueZ D-Bus communication.

Implementations§

Source§

impl BluerAdapter

Source

pub async fn new() -> Result<Self>

Create a new BlueZ adapter

This connects to the system D-Bus and gets the default Bluetooth adapter.

Source

pub async fn with_adapter_name(name: &str) -> Result<Self>

Create adapter with a specific adapter name (e.g., “hci0”)

Source

pub fn adapter_name(&self) -> &str

Get the adapter name (e.g., “hci0”)

Source

pub async fn set_adapter_alias(&self, alias: &str) -> Result<()>

Set the adapter’s alias (used for scan response device name)

Source

pub async fn register_node_address(&self, node_id: NodeId, address: Address)

Register node ID to address mapping

Source

pub async fn get_node_address(&self, node_id: &NodeId) -> Option<Address>

Get address for a node ID

Source

pub async fn get_connection(&self, node_id: &NodeId) -> Option<BluerConnection>

Get a clone of a stored connection by node ID

Returns the BluerConnection for a connected peer, allowing direct GATT operations (read/write characteristics) on the remote device.

Source

pub async fn set_sync_data_callback<F>(&self, callback: F)
where F: Fn(Vec<u8>) + Send + Sync + 'static,

Set callback for when sync data is received from a connected peer

This is invoked when a remote device writes to the sync_data characteristic. Use this to feed received documents into HiveMesh::on_ble_data_received_anonymous.

Source

pub async fn clear_sync_data_callback(&self)

Clear the sync data callback

Source

pub async fn update_sync_state(&self, data: &[u8])

Update the sync state data that connected peers can read

Call this with the output of HiveMesh::tick() or HiveMesh::build_document() to make the current mesh state available to connected peers.

Source

pub async fn get_sync_state(&self) -> Vec<u8>

Get current sync state data

Source

pub async fn get_peer_mtu(&self, address: &Address) -> Option<u16>

Get the negotiated MTU for a connected peer (by BLE address)

Returns the MTU captured from the peer’s last GATT operation. This is populated when the peer performs read/write operations on our GATT server.

Source

pub async fn get_all_peer_mtus(&self) -> HashMap<Address, u16>

Get all known peer MTUs (for debugging/monitoring)

Source

pub fn get_device(&self, address: Address) -> Result<Device, Error>

Get a device handle by address for direct GATT operations

This is useful when you need to connect to a device directly.

Source

pub async fn connect_device( &self, address: Address, address_type: AddressType, ) -> Result<Device, Error>

Connect to a device with explicit address type

This is needed for devices using random BLE addresses (common in BLE peripherals like WearOS watches). The address type can be determined from the address itself:

  • If first byte MSBs are 11 (0xC0+ range), it’s typically a random static address
  • Use AddressType::LeRandom for random addresses
  • Use AddressType::LePublic for public addresses
Source

pub fn is_random_address(address: &Address) -> bool

Determine if a BLE address is a random address based on its structure

In BLE, random addresses have specific patterns in the two MSBs of the first byte:

  • 11: Random static address
  • 01: Resolvable private address (RPA)
  • 00: Non-resolvable private address

Public addresses don’t follow this pattern and are manufacturer-assigned.

Source

pub async fn stop_discovery(&self) -> Result<()>

Stop BLE discovery temporarily

This is useful before connecting to avoid the “le-connection-abort-by-local” error that can happen when BlueZ tries to scan and connect simultaneously.

Source

pub async fn resume_discovery(&self) -> Result<()>

Resume BLE discovery

Source

pub async fn remove_device(&self, address: Address) -> Result<()>

Remove a device from BlueZ’s cache

This can help clear stale state that causes connection failures. Use this when repeated connection attempts fail.

Trait Implementations§

Source§

impl BleAdapter for BluerAdapter

Source§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, config: &'life1 BleConfig, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Initialize the adapter with the given configuration
Source§

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the adapter (begin advertising and/or scanning)
Source§

fn stop<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the adapter
Source§

fn is_powered(&self) -> bool

Check if the adapter is powered on
Source§

fn address(&self) -> Option<String>

Get the adapter’s Bluetooth address
Source§

fn start_scan<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 DiscoveryConfig, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Start scanning for devices
Source§

fn stop_scan<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop scanning
Source§

fn start_advertising<'life0, 'life1, 'async_trait>( &'life0 self, _config: &'life1 DiscoveryConfig, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Start advertising
Source§

fn stop_advertising<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop advertising
Source§

fn set_discovery_callback(&mut self, callback: Option<DiscoveryCallback>)

Set callback for discovered devices
Source§

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, peer_id: &'life1 NodeId, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn BleConnection>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Connect to a peer by node ID
Source§

fn disconnect<'life0, 'life1, 'async_trait>( &'life0 self, peer_id: &'life1 NodeId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Disconnect from a peer
Source§

fn get_connection(&self, peer_id: &NodeId) -> Option<Box<dyn BleConnection>>

Get an existing connection
Source§

fn peer_count(&self) -> usize

Get the number of connected peers
Source§

fn connected_peers(&self) -> Vec<NodeId>

Get list of connected peer IDs
Source§

fn set_connection_callback(&mut self, callback: Option<ConnectionCallback>)

Set callback for connection events
Source§

fn register_gatt_service<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register the HIVE GATT service
Source§

fn unregister_gatt_service<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Unregister the HIVE GATT service
Source§

fn supports_coded_phy(&self) -> bool

Check if Coded PHY is supported
Source§

fn supports_extended_advertising(&self) -> bool

Check if extended advertising is supported
Source§

fn max_mtu(&self) -> u16

Get maximum supported MTU
Source§

fn max_connections(&self) -> u8

Get maximum number of connections
Source§

fn write_to_peer<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, peer_id: &'life1 NodeId, char_uuid: Uuid, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write data to a peer’s GATT characteristic Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.