bleasy

Crates.iobleasy
lib.rsbleasy
version0.3.1
sourcesrc
created_at2021-11-04 14:01:44.614956
updated_at2024-04-13 06:59:57.490066
descriptionHigh-level BLE communication library
homepagehttps://github.com/urholaukkarinen/bleasy
repositoryhttps://github.com/urholaukkarinen/bleasy
max_upload_size
id476655
size69,418
Urho Laukkarinen (urholaukkarinen)

documentation

README

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.

Commit count: 16

cargo fmt