Struct CurrentReading

Source
pub struct CurrentReading {
Show 15 fields pub co2: u16, pub temperature: f32, pub pressure: f32, pub humidity: u8, pub battery: u8, pub status: Status, pub interval: u16, pub age: u16, pub captured_at: Option<OffsetDateTime>, pub radon: Option<u32>, pub radiation_rate: Option<f32>, pub radiation_total: Option<f64>, pub radon_avg_24h: Option<u32>, pub radon_avg_7d: Option<u32>, pub radon_avg_30d: Option<u32>,
}
Expand description

Current reading from an Aranet sensor.

This struct supports all Aranet device types:

  • Aranet4: CO2, temperature, pressure, humidity
  • Aranet2: Temperature, humidity (co2 and pressure will be 0)
  • AranetRn+ (Radon): Radon, temperature, pressure, humidity (co2 will be 0)
  • Aranet Radiation: Radiation dose, temperature (uses radiation_* fields)

Fields§

§co2: u16

CO2 concentration in ppm (Aranet4 only, 0 for other devices).

§temperature: f32

Temperature in degrees Celsius.

§pressure: f32

Atmospheric pressure in hPa (0 for Aranet2).

§humidity: u8

Relative humidity percentage (0-100).

§battery: u8

Battery level percentage (0-100).

§status: Status

CO2 status indicator.

§interval: u16

Measurement interval in seconds.

§age: u16

Age of reading in seconds since last measurement.

§captured_at: Option<OffsetDateTime>

Timestamp when the reading was captured (if known).

This is typically set by the library when reading from a device, calculated as now - age.

§radon: Option<u32>

Radon concentration in Bq/m³ (AranetRn+ only).

§radiation_rate: Option<f32>

Radiation dose rate in µSv/h (Aranet Radiation only).

§radiation_total: Option<f64>

Total radiation dose in mSv (Aranet Radiation only).

§radon_avg_24h: Option<u32>

24-hour average radon concentration in Bq/m³ (AranetRn+ only).

§radon_avg_7d: Option<u32>

7-day average radon concentration in Bq/m³ (AranetRn+ only).

§radon_avg_30d: Option<u32>

30-day average radon concentration in Bq/m³ (AranetRn+ only).

Implementations§

Source§

impl CurrentReading

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes (Aranet4 format).

The byte format is:

  • bytes 0-1: CO2 (u16 LE)
  • bytes 2-3: Temperature (u16 LE, divide by 20 for Celsius)
  • bytes 4-5: Pressure (u16 LE, divide by 10 for hPa)
  • byte 6: Humidity (u8)
  • byte 7: Battery (u8)
  • byte 8: Status (u8)
  • bytes 9-10: Interval (u16 LE)
  • bytes 11-12: Age (u16 LE)
§Errors

Returns ParseError::InsufficientBytes if data contains fewer than MIN_CURRENT_READING_BYTES (13) bytes.

Source

pub fn from_bytes_aranet4(data: &[u8]) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes (Aranet4 format).

This is an alias for from_bytes for explicit device type parsing.

§Errors

Returns ParseError::InsufficientBytes if data contains fewer than MIN_CURRENT_READING_BYTES (13) bytes.

Source

pub fn from_bytes_aranet2(data: &[u8]) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes (Aranet2 format).

The byte format is:

  • bytes 0-1: Temperature (u16 LE, divide by 20 for Celsius)
  • byte 2: Humidity (u8)
  • byte 3: Battery (u8)
  • byte 4: Status (u8)
  • bytes 5-6: Interval (u16 LE)
§Errors

Returns ParseError::InsufficientBytes if data contains fewer than MIN_ARANET2_READING_BYTES (7) bytes.

Source

pub fn from_bytes_radon(data: &[u8]) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes (Aranet Radon GATT format).

The byte format is:

  • bytes 0-1: Device type marker (u16 LE, 0x0003 for radon)
  • bytes 2-3: Interval (u16 LE, seconds)
  • bytes 4-5: Age (u16 LE, seconds since update)
  • byte 6: Battery (u8)
  • bytes 7-8: Temperature (u16 LE, divide by 20 for Celsius)
  • bytes 9-10: Pressure (u16 LE, divide by 10 for hPa)
  • bytes 11-12: Humidity (u16 LE, divide by 10 for percent)
  • bytes 13-16: Radon (u32 LE, Bq/m³)
  • byte 17: Status (u8)

Extended format (47 bytes) includes working averages:

  • bytes 18-21: 24h average time (u32 LE)
  • bytes 22-25: 24h average value (u32 LE, Bq/m³)
  • bytes 26-29: 7d average time (u32 LE)
  • bytes 30-33: 7d average value (u32 LE, Bq/m³)
  • bytes 34-37: 30d average time (u32 LE)
  • bytes 38-41: 30d average value (u32 LE, Bq/m³)
  • bytes 42-45: Initial progress (u32 LE, optional)
  • byte 46: Display type (u8, optional)

Note: If an average value >= 0xff000000, it indicates the average is still being calculated (in progress) and is not yet available.

§Errors

Returns ParseError::InsufficientBytes if data contains fewer than MIN_RADON_GATT_READING_BYTES (18) bytes.

Source

pub fn from_bytes_radiation(data: &[u8]) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes (Aranet Radiation GATT format).

The byte format is:

  • bytes 0-1: Unknown/header (u16 LE)
  • bytes 2-3: Interval (u16 LE, seconds)
  • bytes 4-5: Age (u16 LE, seconds)
  • byte 6: Battery (u8)
  • bytes 7-10: Dose rate (u32 LE, nSv/h, divide by 1000 for µSv/h)
  • bytes 11-18: Total dose (u64 LE, nSv, divide by 1_000_000 for mSv)
  • bytes 19-26: Duration (u64 LE, seconds) - not stored in CurrentReading
  • byte 27: Status (u8)
§Errors

Returns ParseError::InsufficientBytes if data contains fewer than MIN_RADIATION_READING_BYTES (28) bytes.

Source

pub fn from_bytes_for_device( data: &[u8], device_type: DeviceType, ) -> Result<Self, ParseError>

Parse a CurrentReading from raw bytes based on device type.

This dispatches to the appropriate parsing method based on the device type.

§Errors

Returns ParseError::InsufficientBytes if data doesn’t contain enough bytes for the specified device type.

Source

pub fn with_captured_at(self, now: OffsetDateTime) -> Self

Set the captured timestamp to the current time minus the age.

This is useful for setting the timestamp when reading from a device.

Source

pub fn builder() -> CurrentReadingBuilder

Create a builder for constructing CurrentReading with optional fields.

Trait Implementations§

Source§

impl Clone for CurrentReading

Source§

fn clone(&self) -> CurrentReading

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CurrentReading

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CurrentReading

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CurrentReading

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for CurrentReading

Source§

fn eq(&self, other: &CurrentReading) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CurrentReading

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for CurrentReading

Source§

impl StructuralPartialEq for CurrentReading

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,