Crates.io | pzem004t |
lib.rs | pzem004t |
version | 0.1.7 |
source | src |
created_at | 2020-03-12 11:42:57.470532 |
updated_at | 2020-03-12 15:48:07.726851 |
description | An embedded-hal driver for the PZEM004T energy monitor. |
homepage | |
repository | https://github.com/iostapyshyn/pzem004t |
max_upload_size | |
id | 217835 |
size | 33,551 |
An embedded-hal driver for the PZEM004T energy monitor.
A CLI for the library is available and can be run on all major operating systems (uses serialport crate).
Examples can be found in the examples/
directory.
let mut pzem = pzem004t::Pzem::new(serial, None).unwrap();
let mut m = pzem004t::Measurement::default();
loop {
match pzem.read(&mut m, Some((&mut tim, TIMEOUT))) {
Err(e) => hprintln!("Could not read PZEM004T: {}", e).unwrap(),
Ok(()) => {
hprintln!("Voltage: {:.1} V", m.voltage).unwrap();
hprintln!("Current: {:.3} A", m.current).unwrap();
hprintln!("Power: {:.1} W", m.power).unwrap();
hprintln!("Energy: {:.3} kWh", m.energy).unwrap();
hprintln!("Frequency: {:.1} Hz", m.frequency).unwrap();
hprintln!("Power factor: {:.2}", m.pf).unwrap();
hprintln!("Alarm: {}\n", m.alarm).unwrap();
}
}
tim.start(1.hz());
block!(tim.wait()).unwrap();
}
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in hexi by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.