#bluetooth #ble #bthome

btsensor

A library for decoding sensor readings from BLE advertisements, including the BTHome format

2 releases

0.1.1 May 17, 2024
0.1.0 Sep 2, 2023

#1091 in Hardware support


Used in mijia-homie

MIT/Apache

65KB
1.5K SLoC

BLE sensor advertisement library

crates.io page docs.rs page

A library for decoding sensor readings from BLE advertisements.

Currently supports:

The actual BLE scanning is up to you, so this library doesn't depend on any particular Bluetooth library or platform. It just provides types and functions to decode the data you give it.

Usage

use std::collections::HashMap;
use btsensor::{bthome, Reading};

// In a real program, this service data would be obtained from a BLE scan.
let service_data: HashMap<Uuid, Vec<u8>> = [(
    bthome::v1::UNENCRYPTED_UUID,
    vec![0x23, 0x02, 0xC4, 0x09, 0x03, 0x03, 0xBF, 0x13],
)]
.into_iter()
.collect();

let decoded = Reading::decode(&service_data).unwrap();
println!("{}", decoded);

For a more complete example, see the examples directory.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–1MB
~23K SLoC