mirror of
https://codeberg.org/icewind/mitemp-rs.git
synced 2026-06-03 17:24:08 +02:00
0.3.0
This commit is contained in:
parent
68b7c2ddcc
commit
15e70d0212
4 changed files with 24 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mitemp"
|
name = "mitemp"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Read Xiaomi MI Temperature and Humidity Sensor over BLE"
|
description = "Read Xiaomi MI Temperature and Humidity Sensor over BLE"
|
||||||
|
|
@ -10,10 +10,9 @@ license = "MIT/Apache-2.0"
|
||||||
btleplug = "0.9"
|
btleplug = "0.9"
|
||||||
num_enum = "0.5"
|
num_enum = "0.5"
|
||||||
tokio-stream = "0.1"
|
tokio-stream = "0.1"
|
||||||
futures-util = "0.3"
|
|
||||||
uuid = "0.8"
|
uuid = "0.8"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
main_error = "0.1"
|
main_error = "0.1"
|
||||||
env_logger = "0.7"
|
env_logger = "0.9"
|
||||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
24
README.md
24
README.md
|
|
@ -5,20 +5,24 @@ Read Xiaomi MI Temperature and Humidity Sensor over BLE
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use mitemp::{adapter_by_mac, listen, BDAddr};
|
use btleplug::api::Manager as _;
|
||||||
use std::str::FromStr;
|
use btleplug::platform::Manager;
|
||||||
|
use mitemp::listen;
|
||||||
|
use tokio::pin;
|
||||||
|
use tokio_stream::StreamExt;
|
||||||
|
|
||||||
fn main() -> Result<(), btleplug::Error> {
|
#[tokio::main]
|
||||||
env_logger::init();
|
async fn main() -> Result<(), btleplug::Error> {
|
||||||
|
let manager = Manager::new().await?;
|
||||||
|
let adapter = manager.adapters().await?.pop().unwrap();
|
||||||
|
|
||||||
let addr = BDAddr::from_str("00:1A:7D:DA:71:08").unwrap();
|
let stream = listen(&adapter).await?;
|
||||||
let adapter = adapter_by_mac(addr)?;
|
pin!(stream);
|
||||||
|
|
||||||
let rx = listen(adapter)?;
|
while let Some(sensor) = stream.next().await {
|
||||||
loop {
|
println!("{}: {:?}", sensor.mac, sensor.data);
|
||||||
let data = rx.recv().unwrap();
|
|
||||||
println!("{}: {:?}", data.mac, data.data);
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
use btleplug::api::Manager as _;
|
use btleplug::api::Manager as _;
|
||||||
use btleplug::platform::Manager;
|
use btleplug::platform::Manager;
|
||||||
use futures_util::StreamExt;
|
|
||||||
use main_error::MainError;
|
use main_error::MainError;
|
||||||
use mitemp::{listen};
|
use mitemp::listen;
|
||||||
|
|
||||||
use tokio::pin;
|
use tokio::pin;
|
||||||
|
use tokio_stream::StreamExt;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MainError> {
|
async fn main() -> Result<(), MainError> {
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ const UUID: Uuid = Uuid::from_bytes([
|
||||||
/// Listen for sensor data
|
/// Listen for sensor data
|
||||||
///
|
///
|
||||||
/// Returns an iterator that will block waiting for new sensor data
|
/// Returns an iterator that will block waiting for new sensor data
|
||||||
pub async fn listen<'a, A: Central + 'static>(
|
pub async fn listen<A: Central>(
|
||||||
adapter: &'a A,
|
adapter: &A,
|
||||||
) -> Result<impl Stream<Item = Sensor> + 'a, btleplug::Error> {
|
) -> Result<impl Stream<Item = Sensor>, btleplug::Error> {
|
||||||
let mut sensors: HashMap<BDAddr, SensorRawData> = HashMap::new();
|
let mut sensors: HashMap<BDAddr, SensorRawData> = HashMap::new();
|
||||||
|
|
||||||
let event_receiver = adapter.events().await?;
|
let event_receiver = adapter.events().await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue