Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/urholaukkarinen/bleasy
High-level BLE communication library for Rust
https://github.com/urholaukkarinen/bleasy
Last synced: 17 days ago
JSON representation
High-level BLE communication library for Rust
- Host: GitHub
- URL: https://github.com/urholaukkarinen/bleasy
- Owner: urholaukkarinen
- License: mit
- Created: 2021-11-04T08:12:43.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-05T09:55:11.000Z (6 months ago)
- Last Synced: 2024-10-10T20:11:33.684Z (about 1 month ago)
- Language: Rust
- Size: 49.8 KB
- Stars: 15
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bleasy
[![Latest version](https://img.shields.io/crates/v/bleasy.svg)](https://crates.io/crates/bleasy)
[![Documentation](https://docs.rs/bleasy/badge.svg)](https://docs.rs/bleasy)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)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](./examples) directory.
```rust
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](https://github.com/deviceplug/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](https://github.com/hbldh/bleak) for Python.As this library in its current state uses btleplug, this can be seen as a sort of conveniency wrapper for it.