Git Product home page Git Product logo

senml's Introduction

SenML: Sensor Measurement Lists

GoDoc Test Go Report Card

SenML package is an implementation of RFC8428 - Sensor Measurement Lists (SenML) in Go.

It provides fully compliant data model and functionalities for:

Documentation

Documentation and various usage examples are availabe as Go Docs: senml, codec

Usage

Install

go get github.com/farshidtz/senml/v2

Simple Example

More examples are available in the documentation.

Decode JSON bytes into a SenML Pack, validate, normalize, and encode it as pretty XML:

package main

import (
	"fmt"
	"github.com/farshidtz/senml/v2/codec"
)

func main() {
	input := `[{"bn":"room1/temp","u":"Cel","t":1276020076,"v":23.5},{"u":"Cel","t":1276020091,"v":23.6}]`

	// decode JSON
	pack, err := codec.DecodeJSON([]byte(input))
	if err != nil {
		panic(err) // handle the error
	}

	// validate the SenML Pack
	err = pack.Validate()
	if err != nil {
		panic(err) // handle the error
	}

	// normalize the SenML Pack
	pack.Normalize()

	// encode the normalized SenML Pack to XML
	dataOut, err := codec.EncodeXML(pack, codec.SetPrettyPrint)
	if err != nil {
		panic(err) // handle the error
	}
	fmt.Printf("%s", dataOut)
	// Output:
	// <sensml xmlns="urn:ietf:params:xml:ns:senml">
	//   <senml n="room1/temp" u="Cel" t="1.276020076e+09" v="23.5"></senml>
	//   <senml n="room1/temp" u="Cel" t="1.276020091e+09" v="23.6"></senml>
	// </sensml>
}

Go Playground

senml's People

Contributors

dborovcanin avatar dschowta avatar farshidtz avatar fluffy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bahadorsaket

senml's Issues

Add Base Value (bv)

From https://tools.ietf.org/html/rfc8428:

Base Value: A base value is added to the value found in an entry,
similar to Base Time.

If the Base Value or Value is not present, the missing field(s) is
considered to have a value of zero. The Base Value and Value are
added together to get the value of the measurement.

Base version in resolved records

From the (standard)[https://tools.ietf.org/html/rfc8428]:

Base Version: Version number of the media type format. This field
is an optional positive integer and defaults to 10 if not present.

All SenML Records in a Pack MUST have the same version number. This
is typically done by adding a Base Version field to only the first
Record in the Pack or by using the default value.

The Base Version field MUST NOT be present in resolved Records if the
SenML version defined in this document is used; otherwise, it MUST be
present in all the resolved SenML Records.

Use mediaType for serialization format

The encoding and decoding format may correspond to media types:

SenML

  • application/senml+json
  • application/senml+cbor
  • application/senml+xml
  • application/senml-exi

SenSML

  • application/sensml+json
  • application/sensml+cbor
  • application/sensml+xml
  • application/sensml-exi

https://tools.ietf.org/html/rfc8428#section-12.3

We currently use the following constants:

  • JSON
  • XML
  • CBOR
  • CSV
  • MPACK
  • LINEP
  • JSONLINE

Normalize pack in place

The Normalize function returns a pack but the the normalization also affects the original object. This is because some record fields are pointers and the iterator copies their address rather than the underlying value. Also, it will be more memory efficient to normalize in place.

Add Base Sum (bs)

From https://tools.ietf.org/html/rfc8428:

Base Sum: A base sum is added to the sum found in an entry, similar
to Base Time.

If only one of the Base Sum or Sum value is present, the missing
field is considered to have a value of zero. The Base Sum and Sum
values are added together to get the sum of measurement. If neither
the Base Sum nor the Sum is present, then the measurement does not
have a Sum value.

Add support for non-float CSV encoding

Currently, CSV encoding is only possible with floats (SenML Value). The encoding could be extended to support strings, booleans, and data arrays (base64 encoded).

Note: CSV encoding is not part of RFC8428.

Add support for non-float LINEP encoding

Currently, the line protocol encoding is only possible with floats (SenML Value). The encoding could be extended to support strings, booleans, and data arrays (base64 encoded).

Note: line protocol encoding is not part of RFC8428.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.