senml

package module
v0.0.0-...-e4008e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package senml is an implementation of RFC8428 - Sensor Measurement Lists (SenML): https://tools.ietf.org/html/rfc8428

The sub-package codec provides various encoding/decoding functions for senml.Pack. The documentation for codec package is available at: https://pkg.go.dev/github.com/farshidtz/senml/v2/codec

Index

Constants

View Source
const (
	MediaTypeSenmlJSON = "application/senml+json"
	MediaTypeSenmlCBOR = "application/senml+cbor"
	MediaTypeSenmlXML  = "application/senml+xml"
	MediaTypeSenmlEXI  = "application/senml-exi"
	// Custom types
	MediaTypeCustomSenmlCSV = "text/vnd.senml.v2+csv"
)

Sensor Measurement Lists (SenML) Media Types

View Source
const (
	MediaTypeSensmlJSON = "application/sensml+json"
	MediaTypeSensmlCBOR = "application/sensml+cbor"
	MediaTypeSensmlXML  = "application/sensml+xml"
	MediaTypeSensmlEXI  = "application/sensml-exi"
	// Custom types
	MediaTypeCustomSensmlCSV = "text/vnd.sensml.v2+csv"
)

Sensor Streaming Measurement Lists (SenSML) Media Types

View Source
const (
	UnitMeter                   = "m"        // meter
	UnitKilogram                = "k"        // kilogram
	UnitGram                    = "g"        // gram - NOT RECOMMENDED
	UnitSecond                  = "s"        // second
	UnitAmpere                  = "A"        // ampere
	UnitKelvin                  = "K"        // kelvin
	UnitCandela                 = "cd"       // candela
	UnitMole                    = "mol"      // mole
	UnitHertz                   = "Hz"       // hertz
	UnitRadian                  = "rad"      // radian
	UnitSteradian               = "sr"       // steradian
	UnitNewton                  = "N"        // newton
	UnitPascal                  = "Pa"       // pascal
	UnitJoule                   = "J"        // joule
	UnitWatt                    = "watt"     // watt
	UnitCoulomb                 = "C"        // coulomb
	UnitVolt                    = "V"        // volt
	UnitFarad                   = "F"        // farad
	UnitOhm                     = "Ohm"      // ohm
	UnitSiemens                 = "S"        // siemens
	UnitWeber                   = "Wb"       // weber
	UnitTesla                   = "T"        // tesla
	UnitHenry                   = "H"        // henry
	UnitCelsius                 = "Cel"      // degrees Celsius
	UnitLumen                   = "lm"       // lumen
	UnitLux                     = "lx"       // lux
	UnitBecquerel               = "Bq"       // becquerel
	UnitGray                    = "Gy"       // gray
	UnitSievert                 = "Sv"       // sievert
	UnitKatal                   = "kat"      // katal
	UnitSquareMeter             = "m2"       // square meter (area)
	UnitCubicMeter              = "m3"       // cubic meter (volume)
	UnitLiter                   = "l"        // liter (volume) - NOT RECOMMENDED
	UnitMeterPerSecond          = "m/s"      // meter per second (velocity)
	UnitMeterPerSquareSecond    = "m/s2"     // meter per square second (acceleration)
	UnitCubicMeterPerSecond     = "m3/s"     // cubic meter per second (flow rate)
	UnitLiterPerSecond          = "l/s"      // liter per second (flow rate) - NOT RECOMMENDED
	UnitWattPerSquareMeter      = "W/m2"     // watt per square meter (irradiance)
	UnitCandelaPerSquareMeter   = "cd/m2"    // candela per square meter (luminance)
	UnitBit                     = "bit"      // bit (information content)
	UnitBitPerSecond            = "bit/s"    // bit per second (data rate)
	UnitLat                     = "lat"      // degrees latitude
	UnitLon                     = "lon"      // degrees longitude
	UnitpHValue                 = "pH"       // pH value (acidity; logarithmic quantity)
	UnitDecibel                 = "dB"       // decibel (logarithmic quantity)
	UnitDecibelWatt             = "dBW"      // decibel relative to 1 W (power level)
	UnitBel                     = "Bspl"     // bel (sound pressure level; logarithmic quantity) - NOT RECOMMENDED
	UnitCount                   = "count"    // 1 (counter value)
	UnitRatio                   = "/"        // 1 (ratio, e.g., value of a switch)
	UnitAbsoluteRatio           = "%"        // 1 (ratio, e.g., value of a switch) - NOT RECOMMENDED
	UnitRelativeHumidity        = "%RH"      // percentage (relative humidity)
	UnitEnergyLevelPercentage   = "%EL"      // percentage (remaining battery energy level)
	UnitEnergyLevelSeconds      = "EL"       // seconds (remaining battery energy level
	UnitEventRateOnePerSecond   = "1/s"      // 1 per second (event rate)
	UnitEventRateOnePerMinute   = "1/min"    // 1 per minute (event rate, "rpm") - NOT RECOMMENDED
	UnitHeartRateBeatsPerMinute = "beat/min" // 1 per minute (heart rate in beats per minute) - NOT RECOMMENDED
	UnitHeartBeats              = "beats"    // 1 (cumulative number of heart beats) - NOT RECOMMENDED
	UnitSiemensPerMeter         = "S/m"      // siemens per meter (conductivity)
)

SenML Units Registry: https://tools.ietf.org/html/rfc8428#section-12.1

View Source
const DefaultBaseVersion = 10

DefaultBaseVersion is the default version of the SenML data model based on: https://tools.ietf.org/html/rfc8428

Variables

This section is empty.

Functions

func ValidateName

func ValidateName(name string) error

ValidateName validates the SenML name

Types

type Pack

type Pack []Record

Pack is a SenML Pack which is one or more SenML Records in an array structure.

func (Pack) Clone

func (p Pack) Clone() (clone Pack)

Clone returns a deep copy of the SenML Pack

func (Pack) GetBoolValue

func (p Pack) GetBoolValue(fn RecordFinder) (bool, bool)

func (Pack) GetLatLon

func (p Pack) GetLatLon() (float64, float64, bool)

func (Pack) GetRecord

func (p Pack) GetRecord(fn RecordFinder) (Record, bool)

func (Pack) GetStringValue

func (p Pack) GetStringValue(fn RecordFinder) (string, bool)

func (Pack) GetSum

func (p Pack) GetSum(fn RecordFinder) (float64, bool)

func (Pack) GetTime

func (p Pack) GetTime(fn RecordFinder) (time.Time, bool)

func (Pack) GetValue

func (p Pack) GetValue(fn RecordFinder) (float64, bool)

func (Pack) GetValueWithUnit

func (p Pack) GetValueWithUnit(fn RecordFinder) (float64, string, bool)

func (Pack) Normalize

func (p Pack) Normalize()

Normalize converts the SenML Pack to to the resolved format according to: https://tools.ietf.org/html/rfc8428#section-4.6

Normalize must be called on a validated pack only.

func (Pack) Validate

func (p Pack) Validate() error

Validate tests if the SenML Pack is valid

type Record

type Record struct {
	XMLName *bool `json:"_,omitempty" xml:"senml"`

	// BaseName is a string that is prepended to the names found in the entries.
	BaseName string `json:"bn,omitempty"  xml:"bn,attr,omitempty" cbor:"-2,keyasint,omitempty"`
	// BaseTime is added to the time found in an entry.
	BaseTime float64 `json:"bt,omitempty"  xml:"bt,attr,omitempty" cbor:"-3,keyasint,omitempty"`
	// BaseUnit is assumed for all entries, unless otherwise indicated.
	BaseUnit string `json:"bu,omitempty"  xml:"bu,attr,omitempty" cbor:"-4,keyasint,omitempty"`
	// BaseVersion is a positive integer and defaults to 10 if not present.
	BaseVersion *int `json:"bver,omitempty"  xml:"bver,attr,omitempty" cbor:"-1,keyasint,omitempty"`
	// BaseValue is added to the value found in an entry, similar to BaseTime.
	BaseValue *float64 `json:"bv,omitempty"  xml:"bv,attr,omitempty" cbor:"-5,keyasint,omitempty"`
	// BaseSum is added to the sum found in an entry, similar to BaseTime.
	BaseSum *float64 `json:"bs,omitempty"  xml:"bs,attr,omitempty" cbor:"-6,keyasint,omitempty"`

	// Name of the sensor or parameter.
	Name string `json:"n,omitempty"  xml:"n,attr,omitempty" cbor:"0,keyasint,omitempty"`
	// Unit for a measurement value.
	Unit string `json:"u,omitempty"  xml:"u,attr,omitempty" cbor:"1,keyasint,omitempty"`
	// Time in seconds when the value was recorded.
	Time float64 `json:"t,omitempty"  xml:"t,attr,omitempty" cbor:"6,keyasint,omitempty"`
	// UpdateTime is the maximum seconds before there is an updated reading for a measurement.
	UpdateTime float64 `json:"ut,omitempty"  xml:"ut,attr,omitempty" cbor:"7,keyasint,omitempty"`

	// Value is the float value of the entry.
	Value *float64 `json:"v,omitempty"  xml:"v,attr,omitempty" cbor:"2,keyasint,omitempty"`
	// StringValue is the string value of the entry.
	StringValue string `json:"vs,omitempty"  xml:"vs,attr,omitempty" cbor:"3,keyasint,omitempty"`
	// DataValue is a base64-encoded string value of the entry with the URL-safe alphabet.
	DataValue string `json:"vd,omitempty"  xml:"vd,attr,omitempty" cbor:"8,keyasint,omitempty"`
	// BoolValue is the boolean value of the entry.
	BoolValue *bool `json:"vb,omitempty"  xml:"vb,attr,omitempty" cbor:"4,keyasint,omitempty"`
	// Sum is the integrated sum of the float values over time.
	Sum *float64 `json:"s,omitempty"  xml:"s,attr,omitempty" cbor:"5,keyasint,omitempty"`
}

Record is a SenML Record which is one measurement or configuration instance in time presented using the SenML data model.

func (Record) GetTime

func (r Record) GetTime() (time.Time, bool)

func (Record) GetValue

func (r Record) GetValue() (float64, bool)

type RecordFinder

type RecordFinder = func(r Record) bool

func FindByName

func FindByName(n string) RecordFinder

func FindByNormalizedName

func FindByNormalizedName(bn, n string) RecordFinder

func FindByUnit

func FindByUnit(u string) RecordFinder

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL