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::{characteristics::BATTERY_LEVEL, Error, Filter, ScanConfig, Scanner};
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Error> {
rsutil::log::Log4rsConfig::default().initialize().unwrap();
// Create a filter for devices that have battery level characteristic
let config = ScanConfig::default()
.with_filters(&[Filter::Characteristic(BATTERY_LEVEL)])
.filter_by_characteristics(|characters, bat_lvl| characters.contains(bat_lvl))
.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();
println!("{:?}", device);
// Read the battery level
let battery_level = device.characteristic(BATTERY_LEVEL).await?.unwrap();
println!("Battery level: {:?}", battery_level.read().await?);
Ok(())
}
Modules§
Structs§
- BDAddr
- Stores the 6 byte address used to identify Bluetooth devices.
- Characteristic
- Device
- Peripheral
Properties - The properties of this peripheral, as determined by the advertising reports we’ve received for it.
- Scan
Config - Scanner
Enums§
- Device
Event - Error
- The main error type returned by most methods in btleplug.
- Filter