senml

package module
v2.0.0-alpha.2+incompa... Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: Apache-2.0 Imports: 9 Imported by: 4

README

SenML

GoDoc Build Status

RFC8428 - Sensor Measurement Lists (SenML) in Go

Note: This library is under development. Only use tagged commits for production.

Usage
package main

import (
    "github.com/linksmart/senml"
)

func main(){
    // TBA
}

Documentation

Index

Constants

View Source
const (
	MediaTypeSenmlJSON = "application/senml+json"
	MediaTypeSenmlCBOR = "application/senml+cbor"
	MediaTypeSenmlXML  = "application/senml+xml"
	MediaTypeSenmlEXI  = "application/senml-exi"
)

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"
)

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)
)

Variables

This section is empty.

Functions

func ValidateName

func ValidateName(name string) error

ValidateName validates the SenML name

Types

type Format

type Format int
const (
	JSON Format = 1 + iota
	XML
	CBOR
	CSV
	MPACK
	LINEP
	JSONLINE
)

type OutputOptions

type OutputOptions struct {
	PrettyPrint bool
	Topic       string
}

type Pack

type Pack []Record

Pack is a SenML Pack:

One or more SenML Records in an array structure.

func Decode

func Decode(msg []byte, format Format) (Pack, error)

Decode takes a SenML message in the given format and parses it and decodes it

into the returned SenML record.

func (Pack) Encode

func (p Pack) Encode(format Format, options OutputOptions) ([]byte, error)

Encode takes a SenML record, and encodes it using the given format.

func (Pack) Normalize

func (p Pack) Normalize() Pack

Normalize removes all the base items and expands records to have items that include

what previously in base items. Converts relative times to absolute times.

func (Pack) Validate

func (p Pack) Validate() error

Validate test if SenML is valid

type Record

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

	BaseName    string  `json:"bn,omitempty"  xml:"bn,attr,omitempty"`
	BaseTime    float64 `json:"bt,omitempty"  xml:"bt,attr,omitempty"`
	BaseUnit    string  `json:"bu,omitempty"  xml:"bu,attr,omitempty"`
	BaseVersion int     `json:"bver,omitempty"  xml:"bver,attr,omitempty"`

	Name       string  `json:"n,omitempty"  xml:"n,attr,omitempty"`
	Unit       string  `json:"u,omitempty"  xml:"u,attr,omitempty"`
	Time       float64 `json:"t,omitempty"  xml:"t,attr,omitempty"`
	UpdateTime float64 `json:"ut,omitempty"  xml:"ut,attr,omitempty"`

	Value       *float64 `json:"v,omitempty"  xml:"v,attr,omitempty"`
	StringValue string   `json:"vs,omitempty"  xml:"vs,attr,omitempty"`
	DataValue   string   `json:"vd,omitempty"  xml:"vd,attr,omitempty"`
	BoolValue   *bool    `json:"vb,omitempty"  xml:"vb,attr,omitempty"`

	Sum *float64 `json:"s,omitempty"  xml:"s,attr,omitempty"`
}

Record is a SenML Record:

One measurement or configuration instance in time presented using the SenML data model.

Jump to

Keyboard shortcuts

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