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
impl BluerAdapter
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create a new BlueZ adapter
This connects to the system D-Bus and gets the default Bluetooth adapter.
Sourcepub async fn with_adapter_name(name: &str) -> Result<Self>
pub async fn with_adapter_name(name: &str) -> Result<Self>
Create adapter with a specific adapter name (e.g., “hci0”)
Sourcepub fn adapter_name(&self) -> &str
pub fn adapter_name(&self) -> &str
Get the adapter name (e.g., “hci0”)
Sourcepub async fn set_adapter_alias(&self, alias: &str) -> Result<()>
pub async fn set_adapter_alias(&self, alias: &str) -> Result<()>
Set the adapter’s alias (used for scan response device name)
Sourcepub async fn register_node_address(&self, node_id: NodeId, address: Address)
pub async fn register_node_address(&self, node_id: NodeId, address: Address)
Register node ID to address mapping
Sourcepub async fn get_node_address(&self, node_id: &NodeId) -> Option<Address>
pub async fn get_node_address(&self, node_id: &NodeId) -> Option<Address>
Get address for a node ID
Sourcepub async fn get_connection(&self, node_id: &NodeId) -> Option<BluerConnection>
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.
Sourcepub async fn set_sync_data_callback<F>(&self, callback: F)
pub async fn set_sync_data_callback<F>(&self, callback: F)
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.
Sourcepub async fn clear_sync_data_callback(&self)
pub async fn clear_sync_data_callback(&self)
Clear the sync data callback
Sourcepub async fn update_sync_state(&self, data: &[u8])
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.
Sourcepub async fn get_sync_state(&self) -> Vec<u8> ⓘ
pub async fn get_sync_state(&self) -> Vec<u8> ⓘ
Get current sync state data
Sourcepub async fn get_peer_mtu(&self, address: &Address) -> Option<u16>
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.
Sourcepub async fn get_all_peer_mtus(&self) -> HashMap<Address, u16>
pub async fn get_all_peer_mtus(&self) -> HashMap<Address, u16>
Get all known peer MTUs (for debugging/monitoring)
Sourcepub fn get_device(&self, address: Address) -> Result<Device, Error>
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.
Sourcepub async fn connect_device(
&self,
address: Address,
address_type: AddressType,
) -> Result<Device, Error>
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::LeRandomfor random addresses - Use
AddressType::LePublicfor public addresses
Sourcepub fn is_random_address(address: &Address) -> bool
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.
Sourcepub async fn stop_discovery(&self) -> Result<()>
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.
Sourcepub async fn resume_discovery(&self) -> Result<()>
pub async fn resume_discovery(&self) -> Result<()>
Resume BLE discovery
Sourcepub async fn remove_device(&self, address: Address) -> Result<()>
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.