Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 726 Bytes

README.md

File metadata and controls

45 lines (33 loc) · 726 Bytes

GoSenML

Go (golang) library for SenML

TODO

  • XML encoder
  • Binary (exi/cbor) encoder
  • Message 'compaction'
  • Proper message validation

Example

package main

import (
	"fmt"
	"github.com/krylovsk/gosenml"
)

func main() {
	e := gosenml.Entry{
		Name:  "sensor1",
		Units: "degC",
	}
	v := 42.0
	e.Value = &v

	m1 := gosenml.NewMessage(e)
	m1.BaseName = "http://example.com/"

	encoder := gosenml.NewJSONEncoder()
	decoder := gosenml.NewJSONDecoder()

	b, _ := encoder.EncodeMessage(m1)
	fmt.Println(string(b))

	m2, _ := decoder.DecodeMessage(b)

	m3 := m2.Expand()
	b, _ = encoder.EncodeMessage(&m3)
	fmt.Println(string(b))
}