项目作者: domagalski

项目描述 :
Read DHT temperature sensor data formatted in JSON over a serial interface and log it.
高级语言: Rust
项目地址: git://github.com/domagalski/dht-logger-rs.git
创建时间: 2021-01-19T01:09:19Z
项目社区:https://github.com/domagalski/dht-logger-rs

开源协议:MIT License

下载


dht-logger

Read DHT sensor data formatted in JSON over a serial interface and log it.

This crate is still under development and is not stable.

This crate is for logging measurement from a device reading DHT sensors and
writing the measurements over a serial connection. The hardware producing the
data does not matter, but it must be logging data over serial in JSON with
fields for temperature, humidity, and heat index. Here’s a pretty version of an
example reading:

  1. {
  2. "sensor_label": {
  3. "t": 20.0,
  4. "h": 50.0,
  5. "hi": 20.0
  6. },
  7. "another_sensor": {
  8. "error": "some error message"
  9. }
  10. }

This code has been tested using
arduino-dht-logger as the
hardware source providing data over serial.

Example

The following example creates a DHT logger from a configuration file, then
reads data from the serial port and logs it to whatever logging channels are
configured.

  1. use std::path::Path;
  2. use dht_logger::DhtLogger;
  3. let config_path = Path::new("example_config.yaml");
  4. let config = DhtLoggerConfig::load_yaml(config_path);
  5. let logger = DhtLogger::from_config(&config);
  6. logger.read_sensor_and_log_data(10);

Cross compiling for the Raspberry Pi

The cross-compilation procedure for Raspberry Pi is modified from
rust-embedded/cross as libudev-dev is
required for compilation, which isn’t in the default docker images cross
provides. Currently the Raspberry Pi Zero and 4B models are supported. To set
up the cross-compilation for both the 4B and zero, run the bootstrap script:

  1. ./bootstrap.sh

After ./bootstrap.sh is finished, the build.sh script can be run with
either 4b or zero as the arguments to determine the target.