senml

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: BSD-2-Clause Imports: 9 Imported by: 4

README

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

Documentation

Overview

SenML encoder and decoder to pare Sensor Markup Language

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
	MPACK
	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"`
	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"`

	Link string `json:"l,omitempty"  xml:"l,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"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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