Skip to main content

Crate coapum_senml

Crate coapum_senml 

Source
Expand description

§CoAPum SenML - Sensor Measurement Lists for Rust

A Rust implementation of RFC 8428 - Sensor Measurement Lists (SenML).

SenML is a format for representing simple sensor measurements and device parameters in a structured way. This crate provides type-safe handling of SenML data with support for multiple serialization formats including JSON, CBOR, and XML.

§Features

  • RFC 8428 Compliant: Full support for SenML specification
  • Multiple Formats: JSON, CBOR, XML serialization support
  • Type Safety: Strongly typed sensor data with validation
  • Normalization: Convert SenML packs to resolved form
  • Builder Pattern: Ergonomic API for creating SenML data
  • Time Series: Specialized support for time-series sensor data

§Quick Start

use coapum_senml::{SenMLPack, SenMLRecord, SenMLBuilder, Result};

fn example() -> Result<()> {
    // Create a simple temperature reading
    let pack = SenMLBuilder::new()
        .base_name("urn:dev:sensor1")
        .base_unit("Cel")
        .add_value("temperature", 22.5)
        .build();

    // Serialize to JSON
    let json = pack.to_json()?;
    println!("{}", json);
    Ok(())
}

§SenML Data Model

SenML represents sensor data as an array of records, where each record can contain:

  • Base fields: Apply to multiple records (bn, bt, bu, bv, bs, bver)
  • Record fields: Individual measurements (n, u, v, vs, vb, vd, s, t, ut)

Base fields reduce redundancy by providing default values that apply to subsequent records in the pack.

Re-exports§

pub use builder::SenMLBuilder;
pub use error::Result;
pub use error::SenMLError;
pub use normalize::NormalizedPack;
pub use normalize::NormalizedRecord;
pub use pack::SenMLPack;
pub use record::SenMLRecord;
pub use record::SenMLValue;

Modules§

builder
Builder pattern for creating SenML packs
cbor
CBOR serialization support for SenML
content_format
SenML Content-Format identifiers for CoAP
error
Error types for SenML operations
json
JSON serialization support for SenML
normalize
SenML normalization - converting packs to resolved form
pack
SenML Pack - collection of SenML records
record
SenML Record types and values