teleinfo

package module
v0.0.0-...-19d10eb Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: GPL-3.0 Imports: 8 Imported by: 2

README

goteleinfo: monitor your house electrical current

Build badge Go Reference 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.16

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 serves 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)
	// GetMap returns the raw map object
	GetMap() map[string]string
}

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