6 releases

0.3.1 Apr 13, 2024
0.3.0 Jan 21, 2024
0.2.2 Jun 4, 2022
0.2.1 Feb 7, 2022
0.1.0 Nov 4, 2021

#310 in Asynchronous


Used in blehr

MIT license

32KB
645 lines

bleasy

Latest version Documentation MIT

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.

Usage

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(())
}

Background

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.

Dependencies

~5–34MB
~514K SLoC