Crate bleasy

Source
Expand description

High-level BLE communication library.

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:

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

    // Create a filter for 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().await?;
    scanner.start(config).await?;

    // Take the first discovered device
    let device = scanner.device_stream().next().await.unwrap();
    println!("{:?}", device);

    // Read the battery level
    let battery_level = device.characteristic(BATTERY_LEVEL).await?.unwrap();
    println!("Battery level: {:?}", battery_level.read().await?);

    Ok(())
}

Modules§

common

Structs§

BDAddr
Stores the 6 byte address used to identify Bluetooth devices.
Characteristic
Device
ScanConfig
Scanner
Service

Enums§

DeviceEvent
Error
The main error type returned by most methods in btleplug.

Type Aliases§

Result
Convenience type for a result using the btleplug Error type.