mirror of
https://codeberg.org/icewind/mitemp-rs.git
synced 2026-06-03 17:24:08 +02:00
updates
This commit is contained in:
parent
b3bf6b3cf6
commit
c6efcb49ac
9 changed files with 1260 additions and 11 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
16
.github/workflows/ci.yaml
vendored
Normal file
16
.github/workflows/ci.yaml
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
name: Continuous integration
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: cachix/install-nix-action@v27
|
||||||
|
- uses: icewind1991/attic-action@v1
|
||||||
|
with:
|
||||||
|
name: ci
|
||||||
|
instance: https://cache.icewind.me
|
||||||
|
authToken: "${{ secrets.ATTIC_TOKEN }}"
|
||||||
|
- run: nix flake check --keep-going
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
result
|
||||||
|
.direnv
|
||||||
|
|
|
||||||
1108
Cargo.lock
generated
Normal file
1108
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
Cargo.toml
13
Cargo.toml
|
|
@ -1,19 +1,20 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mitemp"
|
name = "mitemp"
|
||||||
version = "0.3.1"
|
version = "0.4.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"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
rust-version = "1.70.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
btleplug = "0.9.2"
|
btleplug = "0.11.6"
|
||||||
num_enum = "0.5.7"
|
num_enum = "0.7.3"
|
||||||
tokio-stream = "0.1.8"
|
tokio-stream = "0.1.8"
|
||||||
uuid = "0.8.2"
|
uuid = "1.11.0"
|
||||||
log = "0.4.16"
|
tracing = "0.1.40"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
main_error = "0.1"
|
main_error = "0.1"
|
||||||
env_logger = "0.9"
|
tracing-subscriber = "0.3.18"
|
||||||
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
|
@ -7,7 +7,7 @@ use tokio_stream::StreamExt;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MainError> {
|
async fn main() -> Result<(), MainError> {
|
||||||
env_logger::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let manager = Manager::new().await?;
|
let manager = Manager::new().await?;
|
||||||
let adapter = manager.adapters().await?.pop().unwrap();
|
let adapter = manager.adapters().await?.pop().unwrap();
|
||||||
|
|
|
||||||
107
flake.lock
generated
Normal file
107
flake.lock
generated
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"crane": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1730060262,
|
||||||
|
"narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=",
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flakelight": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731328800,
|
||||||
|
"narHash": "sha256-gy6/aB9qY+PaOgqRXx5DQNsgKCkjjGKG1HYtth+WTlI=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flakelight",
|
||||||
|
"rev": "76fce036c5e0daf15a926de77f1410ae997c5d4c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "flakelight",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mill-scale": {
|
||||||
|
"inputs": {
|
||||||
|
"crane": "crane",
|
||||||
|
"flakelight": [
|
||||||
|
"flakelight"
|
||||||
|
],
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731858893,
|
||||||
|
"narHash": "sha256-Ugoi82xv7KOc2VdQejeVvKODP6bt7dkMsDsdRRkN4a8=",
|
||||||
|
"owner": "icewind1991",
|
||||||
|
"repo": "mill-scale",
|
||||||
|
"rev": "9cc1f1c214b1d8c85fea7d8afa56983870c5a59d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "icewind1991",
|
||||||
|
"repo": "mill-scale",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731652201,
|
||||||
|
"narHash": "sha256-XUO0JKP1hlww0d7mm3kpmIr4hhtR4zicg5Wwes9cPMg=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "c21b77913ea840f8bcf9adf4c41cecc2abffd38d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-24.05",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flakelight": "flakelight",
|
||||||
|
"mill-scale": "mill-scale",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"mill-scale",
|
||||||
|
"flakelight",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1730255392,
|
||||||
|
"narHash": "sha256-9pydem8OVxa0TwjUai1PJe0yHAJw556CWCEwyoAq8Ik=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "7509d76ce2b3d22b40bd25368b45c0a9f7f36c89",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
15
flake.nix
Normal file
15
flake.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-24.05";
|
||||||
|
flakelight = {
|
||||||
|
url = "github:nix-community/flakelight";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
mill-scale = {
|
||||||
|
url = "github:icewind1991/mill-scale";
|
||||||
|
inputs.flakelight.follows = "flakelight";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
outputs = { mill-scale, ... }: mill-scale ./. {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
pub use btleplug::api::BDAddr;
|
pub use btleplug::api::BDAddr;
|
||||||
use btleplug::api::{Central, CentralEvent, ScanFilter};
|
use btleplug::api::{Central, CentralEvent, ScanFilter};
|
||||||
use log::debug;
|
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use tokio_stream::{Stream, StreamExt};
|
use tokio_stream::{Stream, StreamExt};
|
||||||
|
use tracing::debug;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// Detected mitemp sensor and the data read from it
|
/// Detected mitemp sensor and the data read from it
|
||||||
|
|
@ -55,7 +55,7 @@ pub async fn listen<A: Central>(
|
||||||
Ok(event_receiver
|
Ok(event_receiver
|
||||||
.filter_map(|event| match event {
|
.filter_map(|event| match event {
|
||||||
CentralEvent::ServiceDataAdvertisement { service_data, id } => {
|
CentralEvent::ServiceDataAdvertisement { service_data, id } => {
|
||||||
debug!("Got service data for {:?}", id);
|
debug!(%id, "Got service data");
|
||||||
Some(service_data)
|
Some(service_data)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
@ -118,7 +118,7 @@ struct InvalidServiceData;
|
||||||
fn parse_advertising_data(
|
fn parse_advertising_data(
|
||||||
service_data: &[u8],
|
service_data: &[u8],
|
||||||
) -> Result<(BDAddr, SensorUpdate), InvalidServiceData> {
|
) -> Result<(BDAddr, SensorUpdate), InvalidServiceData> {
|
||||||
debug!("Parsing sensor data {:?}", service_data);
|
debug!(?service_data, "Parsing sensor data");
|
||||||
let sensor_type = &service_data[1..4];
|
let sensor_type = &service_data[1..4];
|
||||||
if sensor_type != [0x20, 0xaa, 0x01] {
|
if sensor_type != [0x20, 0xaa, 0x01] {
|
||||||
return Err(InvalidServiceData);
|
return Err(InvalidServiceData);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue