bleasy/lib.rs
1//! High-level BLE communication library.
2//!
3//! The goal of this library is to provide an easy-to-use interface
4//! for communicating with BLE devices, that satisfies most use cases.
5//!
6//! ## Usage
7//!
8//! Here is an example on how to find a device with battery level characteristic and read
9//! a value from that characteristic:
10//!
11//! ```rust,no_run
12//! use bleasy::common::characteristics::BATTERY_LEVEL;
13//! use bleasy::{Error, ScanConfig, Scanner};
14//! use futures::StreamExt;
15//!
16//! #[tokio::main]
17//! async fn main() -> Result<(), Error> {
18//! pretty_env_logger::init();
19//!
20//! // Create a filter for devices that have battery level characteristic
21//! let config = ScanConfig::default()
22//! .filter_by_characteristics(|uuids| uuids.contains(&BATTERY_LEVEL))
23//! .stop_after_first_match();
24//!
25//! // Start scanning for devices
26//! let mut scanner = Scanner::new();
27//! scanner.start(config).await?;
28//!
29//! // Take the first discovered device
30//! let device = scanner.device_stream().next().await.unwrap();
31//! println!("{:?}", device);
32//!
33//! // Read the battery level
34//! let battery_level = device.characteristic(BATTERY_LEVEL).await?.unwrap();
35//! println!("Battery level: {:?}", battery_level.read().await?);
36//!
37//! Ok(())
38//! }
39//!```
40
41#![warn(clippy::all, future_incompatible, nonstandard_style, rust_2018_idioms)]
42
43pub use btleplug::{api::BDAddr, Error, Result};
44
45pub use characteristic::Characteristic;
46pub use device::{Device, DeviceEvent};
47pub use scanner::{Filter, ScanConfig, Scanner};
48
49mod device;
50mod scanner;
51
52mod characteristic;
53pub mod common;