dsmr4p1

package module
v0.0.0-...-762b440 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2020 License: MIT Imports: 10 Imported by: 3

README

dsmr4p1

A basic Go library for reading (and parsing) data from the P1 port of dutch smart meters. Do note that this library has only been tested with a limited number of smartmeters (i.e., one), so it might not work with yours.

GoDoc

Documentation

Overview

Package dsmr4p1 is a library for reading (and parsing) data from the P1 port of dutch smart meters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorParseTimestamp indicates that there was an error parsing a timestamp.
	ErrorParseTimestamp = errors.New("error parsing timestamp: missing DST indicator")
	// ErrorParseValueWithUnit indicates that there was an error parsing a value string
	// (i.e., a string containing both a value and a unit)
	ErrorParseValueWithUnit = errors.New("error parsing string that should contain both a value and a unit")
)

Functions

func ParseTimestamp

func ParseTimestamp(timestamp string) (time.Time, error)

ParseTimestamp parses the timestamp format used in the dutch smartmeters. Do note this function assumes the CET/CEST timezone.

func ParseValueWithUnit

func ParseValueWithUnit(input string) (value float64, unit string, err error)

ParseValueWithUnit parses the provided string into a float and a unit. If the unit starts with "k" the value is multiplied by 1000 and the "k" is removed from the unit.

func Poll

func Poll(input io.Reader) chan Telegram

Poll starts polling the P1 port represented by input (an io.Reader). It will start a goroutine and received telegrams are put into returned channel. Only telegrams whose CRC value are correct are put into the channel.

func RateLimit

func RateLimit(input io.Reader, delay time.Duration) io.Reader

RateLimit takes a io.Reader (typically the output of a os.Open) and delay the output of each Telegram (delimited by a '/') at a certain rate (delay). The main purpose is for testing/simulation. Simply save the output of an actual smartmeter to a file. Then in your test program open the file and use the resulting io.Reader with this function. The resulting io.Reader will mimick a real smart-meter that outputs a telegram every n seconds (typically 10).

Types

type Telegram

type Telegram []byte

Telegram holds the a P1 telegram. It is essentially a slice of bytes.

func (Telegram) Identifier

func (t Telegram) Identifier() string

Identifier returns the identifier in the telegram.

func (Telegram) Parse

func (t Telegram) Parse() (map[string][]string, error)

Parse attempts to parse the telegram. It returns a map of strings to string slices. The keys in the map are the ID-codes, the strings in the slice are are the value between brackets for that ID-code.

Directories

Path Synopsis
Simple example program that illustrates how to use the dsmr4p1 library.
Simple example program that illustrates how to use the dsmr4p1 library.

Jump to

Keyboard shortcuts

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