senml

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: BSD-2-Clause Imports: 9 Imported by: 0

README

Disco SenML is cisco/senml with bugfixes

SenML

RFC 8428 Sensor Measurement Lists (SenML) defines a format for representing simple sensor measurements and device parameters in Sensor Measurement Lists.

Disco SenML

Disco SenML is a fork of cisco/senml that resolves various issues. Programs are 4 MB smaller, CBOR representation no longer violates RFC 8428, and all unit tests pass.

All features are the same as cisco/senml except MessagePack support is removed.

Disco SenML was created on Nov 23, 2019 using cisco/senml (4d43ea8) dated Oct 10, 2019.

Special thanks:

  • Cullen Jennings for his work on RFC 8428 (SenML) and cisco/senml. He did the heavy lifting in those, so changes made by this project are trivial by comparison.
  • Faye Amacker for adding requested features to her CBOR library that made this easy.

Release Notes

Disco SenML initial release on Nov 24, 2019.

This project fixes open issues in cisco/senml (d5a3c66, Dec 11, 2019):

  • cisco/senml #2 (2016) "CBOR does not encode or decode numeric field names". <-- RFC 8428 violation.
  • cisco/senml #18 (2017) "Base Value and Base Sum missing from the model.
  • cisco/senml #22 (2019) "CBOR support uses go-codec which adds bloat to the binary.
  • cisco/senml #25 (2019) "cisco/senml does not pass unit tests"

There are no changes to core cisco/senml features except removal of MessagePack.

MessagePack was removed because it:

  • increased bloat (cisco/senml #22) and attack surface.
  • isn't mentioned in SenML RFC 8428.
  • prevented having a CBOR library (fxamacker/cbor) as the only external dependency.

Changes to cisco/senml (4d43ea8, Oct 10, 2019):

  • Compiled programs are each 4 MB smaller (senmlCat and senmlServer).
  • CBOR representation uses integers for labels, so it no longer violates SenML RFC 8428.
  • Missing Base Value and Base Sum are added to the model.
  • Fixed bad test data in unit tests and added new CBOR test using example from SenML RFC 8428 so all unit tests pass.
  • Removed MessagePack feature for reasons cited in README.md.
  • Replaced ugorji/go with fxamacker/cbor.
  • Use Go modules and have at least one tagged release.
  • Require Go 1.12
  • Added name to LICENSE.
  • Updated README.md with new name "Disco SenML"

Limitations

Known limitations:

  • There are no unit tests for senmlCat or senmlServer. Using senmlCat or senmlServer is not recommended.
  • Security Audit: I didn't conduct a security audit of cisco/senml or this project. A security audit is recommended.
  • Code Review and Refactoring: I didn't perform any code review or refactoring beyond the minimum changes required to resolve cisco/senml issues 2, 18, 22 and 25. Code review and refactoring is recommended.

Requirements

Go 1.12+ is required.

senmlCat

Tool to convert SenML between formats and act as gateway server to other services

usage

convert JSON SenML to XML

senmlCat -json -i data.json > data.xml

convert JSON SenML to CBOR

senmlCat.go -ijson -cbor data.json > data.cbor

convert to Excel spreadsheet CSV file

senmlCat -expand -ijsons -csv -print data.json > foo.csv

Note that this moves times to excel times that are days since 1900

listen for posts of SenML in JSON and send to influxdb

This listens on port 880 then writes to an influx instance at localhost where to the database called "junk"

The -expand is needed to expand base values into each line of the Line Protocol

senmlCat -ijsons -http 8880 -expand -linp -print -post http://localhost:8086/write?db=junk

License

Copyright 2019-present Montgomery Edwards⁴⁴⁸ (github.com/x448)
Copyright 2016-2019 Cullen Jennings

x448/senml is licensed under the BSD 2-Clause "Simplified" License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(s SenML, format Format, options OutputOptions) ([]byte, error)

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

func IsValid

func IsValid(senml SenML) bool

Test if SenML is valid

Types

type Format

type Format int
const (
	JSON Format = 1 + iota
	XML
	CBOR
	CSV

	LINEP
	JSONLINE
)

type OutputOptions

type OutputOptions struct {
	PrettyPrint bool
	Topic       string
}

type SenML

type SenML struct {
	XMLName *bool  `json:"_,omitempty" xml:"sensml"`
	Xmlns   string `json:"_,omitempty" xml:"xmlns,attr"`

	Records []SenMLRecord ` xml:"senml"`
}

func Decode

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

Decode takes a SenML message in the given format and parses it and decodes it into the returned SenML record.

func Normalize

func Normalize(senml SenML) SenML

Removes all the base items and expands records to have items that include what previosly in base iterms. Convets relative times to absoltue times.

type SenMLRecord

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

	BaseName    string  `json:"bn,omitempty"  xml:"bn,attr,omitempty"  cbor:"-2,keyasint,omitempty"`
	BaseTime    float64 `json:"bt,omitempty"  xml:"bt,attr,omitempty"  cbor:"-3,keyasint,omitempty"`
	BaseUnit    string  `json:"bu,omitempty"  xml:"bu,attr,omitempty"  cbor:"-4,keyasint,omitempty"`
	BaseVersion int     `json:"bver,omitempty"  xml:"bver,attr,omitempty"  cbor:"-1,keyasint,omitempty"`
	BaseValue   float64 `json:"bv,omitempty"  xml:"bv,attr,omitempty"  cbor:"-5,keyasint,omitempty"`
	BaseSum     float64 `json:"bs,omitempty"  xml:"bs,attr,omitempty"  cbor:"-6,keyasint,omitempty"`

	Link string `json:"l,omitempty"  xml:"l,attr,omitempty"`

	Name       string  `json:"n,omitempty"  xml:"n,attr,omitempty"  cbor:"0,keyasint,omitempty"`
	Unit       string  `json:"u,omitempty"  xml:"u,attr,omitempty"  cbor:"1,keyasint,omitempty"`
	Time       float64 `json:"t,omitempty"  xml:"t,attr,omitempty"  cbor:"6,keyasint,omitempty"`
	UpdateTime float64 `json:"ut,omitempty"  xml:"ut,attr,omitempty"  cbor:"7,keyasint,omitempty"`

	Value       *float64 `json:"v,omitempty"  xml:"v,attr,omitempty"  cbor:"2,keyasint,omitempty"`
	StringValue string   `json:"vs,omitempty"  xml:"vs,attr,omitempty"  cbor:"3,keyasint,omitempty"`
	DataValue   string   `json:"vd,omitempty"  xml:"vd,attr,omitempty"  cbor:"8,keyasint,omitempty"`
	BoolValue   *bool    `json:"vb,omitempty"  xml:"vb,attr,omitempty"  cbor:"4,keyasint,omitempty"`

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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