3 releases
new 0.1.2 | Mar 14, 2025 |
---|---|
0.1.1 | Mar 12, 2025 |
0.1.0 | Mar 10, 2025 |
#444 in Unix APIs
148 downloads per month
38KB
597 lines
BlueBus
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.
Features
✅ 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
.
Installation
Add bluebus
to your Cargo.toml
:
[dependencies]
bluebus = "0.1.2"
Example Usage
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(())
}
Documentation
Detailed API documentation is available on docs.rs.
License
BlueBus is licensed under either:
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.
Acknowledgments
Special thanks to REM Vision Lab and Sezai Acer for their support in improving this library.
Dependencies
~11–23MB
~358K SLoC