Crates.io | bleasy |
lib.rs | bleasy |
version | 0.3.1 |
source | src |
created_at | 2021-11-04 14:01:44.614956 |
updated_at | 2024-04-13 06:59:57.490066 |
description | High-level BLE communication library |
homepage | https://github.com/urholaukkarinen/bleasy |
repository | https://github.com/urholaukkarinen/bleasy |
max_upload_size | |
id | 476655 |
size | 69,418 |
High-level BLE communication library for Rust.
The goal of this library is to provide an easy-to-use interface for communicating with BLE devices, that satisfies most use cases.
Here is an example on how to find a device with battery level characteristic and read a value from that characteristic. For more examples, see the examples directory.
use bleasy::common::characteristics::BATTERY_LEVEL;
use bleasy::{Error, ScanConfig, Scanner};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Error> {
pretty_env_logger::init();
// Filter devices that have battery level characteristic
let config = ScanConfig::default()
.filter_by_characteristics(|uuids| uuids.contains(&BATTERY_LEVEL))
.stop_after_first_match();
// Start scanning for devices
let mut scanner = Scanner::new();
scanner.start(config).await?;
// Take the first discovered device
let device = scanner.device_stream().next().await.unwrap();
// Read the battery level
let battery_level = device.characteristic(BATTERY_LEVEL).await?.unwrap();
println!("Battery level: {:?}", battery_level.read().await?);
Ok(())
}
At the time of writing this, there is only one cross-platform BLE library for Rust, btleplug. I have been using it for various personal projects for a while, but I found that I would like to have a bit higher-level library that makes it quick and easy start working with BLE devices, something akin to bleak for Python.
As this library in its current state uses btleplug, this can be seen as a sort of conveniency wrapper for it.