SenML / SenSML JSON · CBOR

Turn sensor records into resolved measurements

Read, validate, and write RFC 8428 sensor measurements in Ruby. Resolve shared base fields and relative times, process SenSML JSON streams, and exchange CBOR.

Quick startRuby
require "senml"

pack = SenML::Pack.build(base_name: "room:", base_time: 1_700_000_000, base_unit: "Cel") do |p|
  p.add(n: "temperature", v: 21.5, t: 2)
  p.add(n: "temperature", v: 21.8, t: 1)
end

parsed = SenML.parse(pack.to_json)
parsed.first.name                         # => "room:temperature"
parsed.first.time                         # => 1700000002
parsed.first["t"]                         # => 2 (the original field)
resolved = parsed.resolve(now: Time.at(1_700_000_000))
resolved.map(&:value)                     # => [21.8, 21.5]
resolved.first.time_at                    # => a UTC Time

Installation

Add the gem to your Gemfile:

gem "senml"

Run bundle install, then try the quick start. Requires Ruby 3.3 or later.

For supported dependencies and optional integrations, see the installation guide.

Scope & documentation

Streaming reads apply to JSON; CBOR decoding consumes a complete input string. XML, EXI, unit conversion, CoAP transport, and RFC 9100 feature-version negotiation are outside scope. Nonintegral measurements use binary64 floating-point values.

Read the full documentation for supported formats, examples, and API details.