teleinfo

package module
Version: v0.0.0-...-658b9bc Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

goteleinfo: monitor your house electrical current

Build badge GoDoc badge GoReport badge

goteleinfo is a small library capable of decoding Teleinfo frames sent by an electrical meter.

Teleinfo is the protocol used by ERDF (Electricité Réseau Distribution France) electrical meters. Using this protocol, the electrical meter sends status frames periodically (~2 per second) that gives information about your electrical current consumption and status.

The Teleinfo protocol is described in this document

In order to convert read the frames, the Micro Teleinfo or PiTinfo is needed.

Requirements

This library requires Go >= 1.13

Metrics

The library provides counters to track frame reading and decoding errors. Those are stored internally as Prometheus metrics.

  • teleinfo_frames_read_total: total number of raw Teleinfo frames read successfully.
  • teleinfo_frames_read_errors_total: total number of read errors. This metric is tagged by error_type.
  • teleinfo_frames_decoded_total: total number of decoded Teleinfo frames.
  • teleinfo_frames_decode_errors_total: total number of frame decoding errors. This is metric is tagged by error_type
Difference between reading and decoding

Bytes coming from the serial port are accumulated by the reader, looking for frame start and frame end markers to extract raw Teleinfo frames. This is called "reading".

Decoding refers to verifying checksum and extracting fields from frame (eg. OPTARIF, HPHC fields, etc...).

Example: serving Teleinfo as JSON frames

A simple HTTP server example is provided in cmd/teleinfo-json that provides the last n frames, JSON encoded. Frames are served in /frames, while Prometheus metrics can be read from /metrics URL.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenPort

func OpenPort(serialDevice string, mode string) (*serial.Port, error)

OpenPort opens and configures the serial port to read Teleinfo frames from.

Types

type Frame

type Frame interface {
	// Type returns the type of frame (see `OPTARIF` field)
	Type() string
	// Mode returns the mode of frame (historic or standard)
	Mode() string
	// GetStringField returns the value of a field as a string.
	GetStringField(string) (string, bool)
	// GetUIntField returns type value of a field as an unsigned integer.
	GetUIntField(string) (uint, bool)
}

Frame holds a single Teleinfo frame.

type Reader

type Reader interface {
	// ReadFrame reads a raw Teleinfo frame.
	ReadFrame() (Frame, error)
}

Reader defines an interface to read raw Teleinfo frames.

func NewReader

func NewReader(r io.Reader, mode *string) Reader

NewReader create a Teleinfo frame reader from a simple Reader. r is usually the struct returned by OpenPort().

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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