modbridge

package module
v0.0.0-...-652411f Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 5 Imported by: 0

README

Modbridge

Build Status Coverage Status Go Report Card

A tool for polling a modbus instance and pushing updates over MQTT.

Quickstart

Setup uses plain golang build for building the binaries. Pre-built binaries are availble on the releases page. Docker images shall be made available on docker hub.

Custom configuration can be added by changing the config.yml file. The current example configuration is for a unipi neuron L303. Currently only polling the coil values is implemented.

Documentation

Index

Constants

View Source
const (
	Read      ModbusMode = "R"  // Read-only
	ReadWrite            = "RW" // Both read and write allowed
	Write                = "W"  // Write-only. Added for own purposes
)

Modbus mode constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ByAddress

type ByAddress []Coil

ByAddress implements sorter interface, for sorting an array of coils based on Address

func (ByAddress) Len

func (coils ByAddress) Len() int

func (ByAddress) Less

func (coils ByAddress) Less(i, j int) bool

func (ByAddress) Swap

func (coils ByAddress) Swap(i, j int)

type Coil

type Coil struct {
	Address uint16
	Slug    string
	// contains filtered or unexported fields
}

Coil represents the state we keep about a modbus coil

func (*Coil) Update

func (coil *Coil) Update(value bool, mqttClient mqtt.Client)

Update handles checking a new value against the current and previous retained state we have for a coil

type CoilConfig

type CoilConfig struct {
	Address uint16
	Mode    ModbusMode
	Slug    string
}

CoilConfig holds the description of the coil part of a device modbus map

type CoilGroup

type CoilGroup struct {
	ModbusClient modbus.Client
	MQTTClient   mqtt.Client
	// contains filtered or unexported fields
}

CoilGroup represents an array of coils which have contiguous Addresses

func GroupCoils

func GroupCoils(coils []Coil) []CoilGroup

GroupCoils groups an array of coils into an array coil groups

func (*CoilGroup) Update

func (coilGroup *CoilGroup) Update() (err error)

Update call the modbus group range and update the corresponding coils

type CoilGroupUpdater

type CoilGroupUpdater interface {
	Update() (err error)
}

CoilGroupUpdater exposes the required interfaces for polling CoilGroups

type CoilUpdater

type CoilUpdater interface {
	Update()
}

CoilUpdater represents a coil to be polled

type Configuration

type Configuration struct {
	Coils           []CoilConfig
	MQTTBrokerURI   string `yaml:"mqtt_broker_uri"`
	MQTTClientID    string `yaml:"mqtt_client_id"`
	ModbusServerURI string `yaml:"modbus_server_uri"`
}

Configuration of modbridge

func (*Configuration) CoilGroupsList

func (c *Configuration) CoilGroupsList() []CoilGroup

CoilGroupsList generates a list of groups, out of the filtered list obtained from the config

func (*Configuration) CoilsList

func (c *Configuration) CoilsList() (coils []Coil)

CoilsList generates a list of non-write only coils from a configuration object

func (*Configuration) CoilsMap

func (c *Configuration) CoilsMap() (coils map[string]Coil)

CoilsMap generates a reverse mapping of the Slugs back to the original coil

type ModbusMode

type ModbusMode string

ModbusMode indicates whether the involved register or coil is read-only or read and write allowed

type SwitchType

type SwitchType int

SwitchType indicates how to interpret the switch

const (
	NO SwitchType = iota // Normally Open
	NC                   // Normally Closed
)

Switch type constants

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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