Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/farshidtz/senml
Sensor Measurement Lists (SenML) in Go
https://github.com/farshidtz/senml
golang rfc8428 senml sensor-measurement-lists
Last synced: about 1 month ago
JSON representation
Sensor Measurement Lists (SenML) in Go
- Host: GitHub
- URL: https://github.com/farshidtz/senml
- Owner: farshidtz
- License: mit
- Created: 2018-11-02T12:39:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-11T14:41:06.000Z (10 months ago)
- Last Synced: 2024-06-20T03:51:44.475Z (7 months ago)
- Topics: golang, rfc8428, senml, sensor-measurement-lists
- Language: Go
- Homepage:
- Size: 283 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SenML: Sensor Measurement Lists
[![GoDoc](https://godoc.org/github.com/farshidtz/senml?status.svg)](https://godoc.org/github.com/farshidtz/senml)
[![Test](https://github.com/farshidtz/senml/workflows/Test/badge.svg)](https://github.com/farshidtz/senml/actions?query=workflow%3ATest)
[![Go Report Card](https://goreportcard.com/badge/github.com/farshidtz/senml)](https://goreportcard.com/report/github.com/farshidtz/senml)SenML package is an implementation of [RFC8428](https://tools.ietf.org/html/rfc8428) - Sensor Measurement Lists (SenML) in Go.
It provides fully compliant data model and functionalities for:
* Validation of various SenML fields
* [Normalization](https://tools.ietf.org/html/rfc8428#section-4.6)
* [SenML Units](https://tools.ietf.org/html/rfc8428#section-12.1)
* [SenML Media Types](https://tools.ietf.org/html/rfc8428#section-12.3)
* Encoding/Decoding (codec package)
* [JSON](https://tools.ietf.org/html/rfc8428#section-5)
* [XML](https://tools.ietf.org/html/rfc8428#section-7)
* [CBOR](https://tools.ietf.org/html/rfc8428#section-6)
* CSV (custom)
* Protobuf (experimental)
## Documentation
Documentation and various usage examples are availabe as Go Docs: [senml](https://pkg.go.dev/github.com/farshidtz/senml/v2), [codec](https://pkg.go.dev/github.com/farshidtz/senml/v2/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:
```go
package mainimport (
"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:
//
//
//
//
}
```
[Go Playground](https://play.golang.org/p/T_Nb7lcF_zg)