Expand description
ruuvi-sensor-protocol implements parser for Ruuvi Sensor Protocols used by the RuuviTag sensor beacon.
§Parsing a set of values from manufacturer specific data
Parsing may return an error due to unknown manufacturer id, unsupported data 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)));
A successful parse returns a SensorValues
structure with a set of values.
use ruuvi_sensor_protocol::{
Acceleration, AccelerationVector, BatteryPotential, Humidity, Pressure, SensorValues,
Temperature,
};
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_as_ppm(), Some(115_000));
assert_eq!(values.temperature_as_millicelsius(), Some(1690));
assert_eq!(values.pressure_as_pascals(), Some(63656));
assert_eq!(values.acceleration_vector_as_milli_g(), Some(AccelerationVector(1000, 1255, 1510)));
assert_eq!(values.battery_potential_as_millivolts(), Some(2182));
See SensorValues
documentation for a description of each value.
§Parsing Ruuvi Gateway data formats
This crate also supports parsing MQTT message payloads published by a Ruuvi Gateway.
Deserialization is implemented with Serde, and requires gateway
feature to be enabled. See
gateway
module for documentation, structures, and functions.
Modules§
- gateway
- This module implements data formats used by Ruuvi Gateway for relaying RuuviTag advertisements. At the moment, only the data format used in MQTT message payloads is implemented. For a complete description of the payload formats, read Ruuvi Gateway data format documentation.
Structs§
- Acceleration
Vector - a 3-dimensional vector which represents acceleration of each dimension in milli-G
- Sensor
Values - Represents a set of values read from sensors on the device
Enums§
- Parse
Error - Errors which can occur during parsing of the manufacturer specific data