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]
|
||||
name = "mitemp"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
description = "Read Xiaomi MI Temperature and Humidity Sensor over BLE"
|
||||
|
|
@ -10,10 +10,9 @@ license = "MIT/Apache-2.0"
|
|||
btleplug = "0.9"
|
||||
num_enum = "0.5"
|
||||
tokio-stream = "0.1"
|
||||
futures-util = "0.3"
|
||||
uuid = "0.8"
|
||||
|
||||
[dev-dependencies]
|
||||
main_error = "0.1"
|
||||
env_logger = "0.7"
|
||||
env_logger = "0.9"
|
||||
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
|
||||
|
||||
```rust
|
||||
use mitemp::{adapter_by_mac, listen, BDAddr};
|
||||
use std::str::FromStr;
|
||||
use btleplug::api::Manager as _;
|
||||
use btleplug::platform::Manager;
|
||||
use mitemp::listen;
|
||||
use tokio::pin;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
fn main() -> Result<(), btleplug::Error> {
|
||||
env_logger::init();
|
||||
#[tokio::main]
|
||||
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 adapter = adapter_by_mac(addr)?;
|
||||
let stream = listen(&adapter).await?;
|
||||
pin!(stream);
|
||||
|
||||
let rx = listen(adapter)?;
|
||||
loop {
|
||||
let data = rx.recv().unwrap();
|
||||
println!("{}: {:?}", data.mac, data.data);
|
||||
while let Some(sensor) = stream.next().await {
|
||||
println!("{}: {:?}", sensor.mac, sensor.data);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use btleplug::api::Manager as _;
|
||||
use btleplug::platform::Manager;
|
||||
use futures_util::StreamExt;
|
||||
use main_error::MainError;
|
||||
use mitemp::{listen};
|
||||
|
||||
use mitemp::listen;
|
||||
use tokio::pin;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), MainError> {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ const UUID: Uuid = Uuid::from_bytes([
|
|||
/// Listen for sensor data
|
||||
///
|
||||
/// Returns an iterator that will block waiting for new sensor data
|
||||
pub async fn listen<'a, A: Central + 'static>(
|
||||
adapter: &'a A,
|
||||
) -> Result<impl Stream<Item = Sensor> + 'a, btleplug::Error> {
|
||||
pub async fn listen<A: Central>(
|
||||
adapter: &A,
|
||||
) -> Result<impl Stream<Item = Sensor>, btleplug::Error> {
|
||||
let mut sensors: HashMap<BDAddr, SensorRawData> = HashMap::new();
|
||||
|
||||
let event_receiver = adapter.events().await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue