Browse Source

Add Temp+Pressure node.

master
flabbergast 2 years ago
parent
commit
6dda6dbcf7
  1. 30
      Cargo.lock
  2. 4
      Cargo.toml
  3. 5
      jee_config.yml
  4. 7
      jeethru.code-workspace
  5. 54
      src/decode_jee.rs
  6. 3
      src/sensordata.rs

30
Cargo.lock

@ -315,7 +315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -434,7 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jeethru"
version = "0.0.17"
version = "0.1.0"
dependencies = [
"bson 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bus 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -442,7 +442,7 @@ dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"config 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mongodb 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -515,7 +515,7 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.6"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -528,7 +528,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -566,7 +566,7 @@ dependencies = [
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -742,7 +742,7 @@ dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -980,7 +980,7 @@ dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonwebtoken 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mqtt311 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1018,7 +1018,7 @@ version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1324,7 +1324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1335,7 +1335,7 @@ dependencies = [
"crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1387,7 +1387,7 @@ dependencies = [
"crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1420,7 +1420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1436,7 +1436,7 @@ dependencies = [
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1653,7 +1653,7 @@ dependencies = [
"checksum linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd"
"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
"checksum loggerv 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6b0664956d197c6e0223870c1cd1ec4117aea282b4c0bd5ab01119d31d708d"
"checksum md-5 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9402eaae33a9e144ce18ef488a0e4ca19869673c7bcdbbfe2030fdc3f84211cd"
"checksum md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48"

4
Cargo.toml

@ -1,12 +1,12 @@
[package]
name = "jeethru"
version = "0.0.17"
version = "0.1.0"
authors = ["flabbergast <flabbergast@drak.xyz>"]
[dependencies]
clap = { version = "~2.32.0", features = ["yaml"] }
config = "0.9"
log = "0.4.6"
log = "0.4.8"
loggerv = "0.7.1"
failure = "~0.1.5"
bus = "~2.2.0"

5
jee_config.yml

@ -24,3 +24,8 @@ devices:
name: "outside/node/front/"
dev_type:
type: TempHumBattV1
"22":
id: 22
name: "sittingroom/node/mid/"
dev_type:
type: TempPressBattV1

7
jeethru.code-workspace

@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}

54
src/decode_jee.rs

@ -22,11 +22,13 @@ pub enum DeviceType {
TempBattV1,
TempBattV2,
TempHumLuxBattV1,
TempPressBattV1,
}
// message types (first byte of the message)
pub enum MessageType {
RegularMessage = 0,
TickMessage = 8,
}
impl DeviceType {
@ -41,9 +43,9 @@ impl DeviceType {
bail!("Not enough bytes in message from TempHumBattV1 type.")
} else { // TODO: perhaps should also implement sanity checks on the resulting values
Ok(vec![
SensorDatum::Temperature(le64fs(&bytes[2..4],100)),
SensorDatum::Humidity(le64f(&bytes[4..6],100)),
SensorDatum::BatteryVolts(le64f(&bytes[6..8],1000)),
SensorDatum::Temperature(le16s_f64(&bytes[2..4],100)),
SensorDatum::Humidity(le16u_f64(&bytes[4..6],100)),
SensorDatum::BatteryVolts(le16u_f64(&bytes[6..8],1000)),
])
}
},
@ -57,8 +59,8 @@ impl DeviceType {
bail!("Not enough bytes in message from TempHumBattV2 type.")
} else {
Ok(vec![
SensorDatum::Temperature(le64f(&bytes[2..4],100)),
SensorDatum::Humidity(le64f(&bytes[4..6],100)),
SensorDatum::Temperature(le16u_f64(&bytes[2..4],100)),
SensorDatum::Humidity(le16u_f64(&bytes[4..6],100)),
SensorDatum::BatteryVolts((bytes[6] as f64)/100.0),
])
}
@ -72,8 +74,8 @@ impl DeviceType {
bail!("Not enough bytes in message from TempBattV1 type.")
} else {
Ok(vec![
SensorDatum::Temperature(le64f(&bytes[2..4],1000)),
SensorDatum::BatteryVolts(le64f(&bytes[4..6],1000)),
SensorDatum::Temperature(le16u_f64(&bytes[2..4],1000)),
SensorDatum::BatteryVolts(le16u_f64(&bytes[4..6],1000)),
])
}
},
@ -86,8 +88,8 @@ impl DeviceType {
bail!("Not enough bytes in message from TempBattV2 type.")
} else {
Ok(vec![
SensorDatum::Temperature(le64f(&bytes[2..4],16)),
SensorDatum::BatteryVolts(le64f(&bytes[4..6],1000)),
SensorDatum::Temperature(le16u_f64(&bytes[2..4],16)),
SensorDatum::BatteryVolts(le16u_f64(&bytes[4..6],1000)),
])
}
},
@ -102,13 +104,30 @@ impl DeviceType {
bail!("Not enough bytes in message from TempBattV2 type.")
} else {
Ok(vec![
SensorDatum::Temperature(le64f(&bytes[2..4],100)),
SensorDatum::Humidity(le64f(&bytes[4..6],100)),
SensorDatum::Light(le64f(&bytes[6..8],1)),
SensorDatum::BatteryVolts(le64f(&bytes[8..10],1000)),
SensorDatum::Temperature(le16u_f64(&bytes[2..4],100)),
SensorDatum::Humidity(le16u_f64(&bytes[4..6],100)),
SensorDatum::Light(le16u_f64(&bytes[6..8],1)),
SensorDatum::BatteryVolts(le16u_f64(&bytes[8..10],1000)),
])
}
},
//TempPressBattV1
//- 2bytes|LE|temp*100
//- 4bytes|LE|pressure*1
//- 2bytes|LE|volt*1000 {1.5--4.0}
DeviceType::TempPressBattV1 => {
if bytes.len() < 8 {
bail!("Not enough bytes in message from TempHumBattV1 type.")
} else { // TODO: perhaps should also implement sanity checks on the resulting values
Ok(vec![
SensorDatum::Temperature(le16s_f64(&bytes[2..4],100)),
SensorDatum::Pressure(le32u_f64(&bytes[4..8],1)),
SensorDatum::BatteryVolts(le16u_f64(&bytes[8..10],1000)),
])
}
},
}
}
}
@ -214,11 +233,16 @@ pub fn process_gw_incoming(msg: &str,
// helpers
fn le64f( bs: &[u8], div: u16 ) -> f64 {
fn le16u_f64( bs: &[u8], div: u16 ) -> f64 {
(((bs[0] as u16) + 256 * (bs[1] as u16)) as f64) / (div as f64)
}
fn le64fs( bs: &[u8], div: u16 ) -> f64 {
fn le16s_f64( bs: &[u8], div: u16 ) -> f64 {
let res = (bs[0] as i32) + 256 * (bs[1] as i32);
((if res > 32767 { res - 65536 } else { res }) as f64) / (div as f64)
}
fn le32u_f64( bs: &[u8], div: u32 ) -> f64 {
(((bs[0] as u32) + 256 * (bs[1] as u32) + (256*256) * (bs[2] as u32)
+ (256*256*256) * (bs[3] as u32)) as f64) / (div as f64)
}

3
src/sensordata.rs

@ -17,6 +17,7 @@ pub enum SensorDatum {
Temperature(f64),
Humidity(f64),
Light(f64),
Pressure(f64),
BatteryVolts(f64),
BatteryPercent(f64),
}
@ -27,6 +28,7 @@ impl SensorDatum {
SensorDatum::Temperature(_) => "temp",
SensorDatum::Humidity(_) => "hum",
SensorDatum::Light(_) => "lux",
SensorDatum::Pressure(_) => "press",
SensorDatum::BatteryVolts(_) => "batt",
SensorDatum::BatteryPercent(_) => "batt_pc",
}
@ -37,6 +39,7 @@ impl SensorDatum {
SensorDatum::Temperature(value)
| SensorDatum::Humidity(value)
| SensorDatum::Light(value)
| SensorDatum::Pressure(value)
| SensorDatum::BatteryVolts(value)
| SensorDatum::BatteryPercent(value) => value.to_string(),
}

Loading…
Cancel
Save