#ruuvi #ruuvitag

no-std ruuvi-sensor-protocol

Ruuvi sensor protocol parser implementation

4 releases (2 breaking)

✓ Uses Rust 2018 edition

0.3.0 Apr 10, 2019
0.2.0 Aug 9, 2018
0.1.1 Aug 8, 2018
0.1.0 Aug 8, 2018

25 downloads per month
Used in 2 crates

MIT license

16KB
270 lines

ruuvi-sensor-protocol-rs Crates.io Docs.rs Crates.io

Ruuvi sensor protocol parser implementation

Requirements

  • Rust >=1.31
    • This crate can be compiled without std by disabling default features

Crate Features

  • std (default) enables features that depend on std crate

Documentation

Documentation is available online at docs.rs. Documentation can be built from source with cargo doc. Examples are included in the documentation.

Changes

  • 0.3.0
    • Requires 2018 Edition (Rust >=1.31)
    • Adds option to compile without std create

License

This project is licensed under MIT license.


lib.rs:

ruuvi-sensor-protocol implements parser for Ruuvi Sensor Protocols used by RuuviTag sensor beacon.

Parsing a set of values from manufacturer specific data

Parsing return an error due to unknown manufacturer id, unsupported tdata format version or invalid data in value field.

use ruuvi_sensor_protocol::{ParseError, SensorValues};

let id = 0x0499;
let value = &[
0x07, 0x17, 0x01, 0x45, 0x35, 0x58, 0x03, 0xE8, 0x04, 0xE7, 0x05, 0xE6, 0x08, 0x86,
];
let result = SensorValues::from_manufacturer_specific_data(id, value);
assert_eq!(result, Err(ParseError::UnsupportedFormatVersion(7)));

Successful parse returns a SensorValue structure with a set of values.

use ruuvi_sensor_protocol::{AccelerationVector, SensorValues};
# use ruuvi_sensor_protocol::ParseError;

# fn run() -> Result<(), ParseError> {
let id = 0x0499;
let value = &[
0x03, 0x17, 0x01, 0x45, 0x35, 0x58, 0x03, 0xE8, 0x04, 0xE7, 0x05, 0xE6, 0x08, 0x86,
];
let values = SensorValues::from_manufacturer_specific_data(id, value)?;

assert_eq!(values.humidity, Some(115_000));
assert_eq!(values.temperature, Some(1690));
assert_eq!(values.pressure, Some(63656));
assert_eq!(values.acceleration, Some(AccelerationVector(1000, 1255, 1510)));
assert_eq!(values.battery_potential, Some(2182));
# Ok(())
# }
# run().unwrap();

See SensorValues documentation for a description of each value.

No runtime deps