BlueBus is a Rust library for interacting with Bluetooth devices using the zbus. It provides an async-first interface for scanning, managing, and communicating with Bluetooth devices on Linux systems.
✅ Device Discovery: Scan for available Bluetooth devices.
✅ Device Management: Connect, pair, unpair, and trust devices.
✅ GATT Support: Read and write Bluetooth characteristics.
✅ Low Energy Advertisement: Manage Bluetooth LE advertisements.
✅ Async Support: Fully compatible with tokio and async/await.
Add bluebus to your Cargo.toml:
[dependencies]
bluebus = "0.1.10"This example scans for Bluetooth devices and prints their addresses:
#[tokio::main]
async fn main() -> zbus::Result<()> {
let conn = bluebus::get_system_connection().await.unwrap();
let adapter = bluebus::AdapterProxy::builder(&conn)
.path(bluebus::ADAPTER_PATH)?.build().await?;
if !adapter.powered().await? {
adapter.set_powered(true).await?;
}
adapter.start_discovery().await?;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
adapter.stop_discovery().await?;
let monitor = Arc::new(bluebus::Monitor::new(conn.clone(), manager).await);
let monitor_clone = Arc::clone(&monitor);
bluebus::print_avaiable_devices(&objects);
tokio::spawn(async move {monitor.monitor_device_added().await;});
tokio::spawn(async move {monitor_clone.monitor_device_removed().await;});
Ok(())
}Detailed API documentation is available on docs.rs.
BlueBus is licensed under either:
Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.