unipitt

package module
v0.0.0-...-d2ec5d3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: GPL-3.0 Imports: 12 Imported by: 0

README

unipitt

GoDoc Go Report Card Build Status Coverage Status

Poll and push out events for unipi neuron platform over MQTT.

Why unipiTT? I don't know, I've sort of ran out of good names ¯_(˶′◡‵˶)_/¯.

Documentation

Index

Constants

View Source
const (
	// DiFilename to check for
	DiFilename = "di_value"
	// DiTrueValue is the value considered to be true
	DiTrueValue = "1"
	// DiFolderRegex represents to regular expression used for finding the required file to read from
	DiFolderRegex = "di_[0-9]_[0-9]{2}"
)
View Source
const (
	// DoFilename to check for
	DoFilename = "do_value"
	// DoTrueValue digital output true value to write
	DoTrueValue = "1\n"
	// DoFalseValue digital output false value to write
	DoFalseValue = "0\n"
	// DoFolderRegex regular expression used for finding folders which contain digital output
	DoFolderRegex = "do_[0-9]_[0-9]{2}"
)
View Source
const (
	// SysFsRoot default root folder to search for digital inputs
	SysFsRoot = "/sys/devices/platform/unipi_plc"
	// MsgTrueValue is the MQTT true value to check for
	MsgTrueValue = "ON"
)

Variables

This section is empty.

Functions

func FindDigitalOutputWriters

func FindDigitalOutputWriters(root string) (writerMap map[string]DigitalOutputWriter, err error)

FindDigitalOutputWriters generates the output writes from a given path

func NewTLSConfig

func NewTLSConfig(caFile string) (*tls.Config, error)

NewTLSConfig generates a TLS config instance for use with the MQTT setup

Types

type Configuration

type Configuration struct {
	Topics map[string]string
}

Configuration represents the topic name for the MQTT message for a given instance name

func (*Configuration) Name

func (c *Configuration) Name(topic string) string

Name reverse mapping of topic for given name. In case nothing is found, just return the topic itself, hoping there's a mapped instance for it

func (*Configuration) Topic

func (c *Configuration) Topic(name string) string

Topic gets a topic (value) for a given name (key). Return the name itself as fallback

type DigitalInput

type DigitalInput interface {
	Update(chan *DigitalInput) error
	Poll(chan *DigitalInput, int)
	Close()
}

DigitalInput interface for doing the polling

type DigitalInputReader

type DigitalInputReader struct {
	Name  string
	Value bool
	Path  string
	Err   error
	// contains filtered or unexported fields
}

DigitalInputReader implements the digital input interface

func FindDigitalInputReaders

func FindDigitalInputReaders(root string) (readers []DigitalInputReader, err error)

FindDigitalInputReaders crawls the root (sys) folder to find any matching digial inputs and creates corresponding DigitalInputReader instances from these.

func NewDigitalInputReader

func NewDigitalInputReader(folder string, name string) (d *DigitalInputReader, err error)

NewDigitalInputReader creates a new DigitalInput and opens the file handle

func (*DigitalInputReader) Close

func (d *DigitalInputReader) Close() error

Close closes the current open file handle

func (*DigitalInputReader) Poll

func (d *DigitalInputReader) Poll(events chan *DigitalInputReader, interval int)

Poll continuously updates the instance

func (*DigitalInputReader) Update

func (d *DigitalInputReader) Update(events chan *DigitalInputReader) (err error)

Update reads the value and sets the new value

type DigitalOutput

type DigitalOutput interface {
	Update(bool) error
}

DigitalOutput represents the digital outputs of the unipi board

type DigitalOutputWriter

type DigitalOutputWriter struct {
	Name string
	Path string
}

DigitalOutputWriter implements the digital output specifically for writing outputs to files

func NewDigitalOutputWriter

func NewDigitalOutputWriter(folder string) (d *DigitalOutputWriter)

NewDigitalOutputWriter creates a new digital output writer instance from a a given matching folder

func (*DigitalOutputWriter) Update

func (d *DigitalOutputWriter) Update(value bool) (err error)

Update writes the updated value to the digital output

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler implements handles all unipi to MQTT interactions

func NewHandler

func NewHandler(broker string, clientID string, caFile string, sysFsRoot string, configFile string) (h *Handler, err error)

NewHandler prepares and sets up an entire unipitt handler

func (*Handler) Close

func (h *Handler) Close()

Close loose ends

func (*Handler) Poll

func (h *Handler) Poll(done chan bool, interval int, payload string) (err error)

Poll starts the actual polling and pushing to MQTT

type Unipitt

type Unipitt interface {
	Poll(pollingInterval int) error
	Close()
}

Unipitt defines the interface with unipi board

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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