rflink

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// MQTT options
	Publish struct {
		Host     string `envconfig:"default=localhost:1883"` // host:port
		Scheme   string `envconfig:"default=tcp"`
		ClientID string `envconfig:"default=rflink"`
		Topic    string `envconfig:"default=rflink"`
	}

	// Serial connection options
	Serial struct {
		Device string `envconfig:"default=/dev/ttyUSB0"`
		Baud   int    `envconfig:"default=57600"`
	}
}

Options stores the options needed to communicate with RFLink and the message queue

func GetOptions

func GetOptions() *Options

GetOptions reads the options from the environment and returns an Options struct

type Publisher

type Publisher struct {
	Topic       string
	SensorInput *SensorReader
	// contains filtered or unexported fields
}

Publisher takes input from a SensorReader and publishes the SensorData that has been read in an MQTT topic

func NewPublisher

func NewPublisher(o *Options) (*Publisher, error)

NewPublisher return a Publisher according to the options specified

func (*Publisher) Disconnect

func (p *Publisher) Disconnect() error

Disconnect properly disconnects the MQTT network connection

func (*Publisher) Publish

func (p *Publisher) Publish(sd *SensorData) error

Publish formats the input SensorData into JSON and publishes it to the configured MQTT topic

func (*Publisher) ReadAndPublish

func (p *Publisher) ReadAndPublish() error

ReadAndPublish loops infinitely to read SensorData from the SensorReader and publish the output via the Publish() method

func (*Publisher) Terminate

func (p *Publisher) Terminate()

Terminate kills the MQTT client

type SensorData

type SensorData struct {
	Model        string   `json:"model"`
	Id           string   `json:"id"`
	FriendlyName string   `json:"name,omitempty"`
	Temperature  *float32 `json:"t,omitempty"`
	Humidity     *uint16  `json:"h,omitempty"`
}

SensorData represents one message received from RFLink. It can only contain Temperature or Humidity values and exposes the model id of the sending device. A friendly name can be added to the data so that the Publisher can tag it before sending it to the MQTT topic.

func SensorDataFromMessage

func SensorDataFromMessage(msg string) (*SensorData, error)

SensorDataFromMessage crafts a SensorData struct from a message read from RFLink

func (*SensorData) String

func (sd *SensorData) String() string

String outputs a string representing the SensorData

type SensorReader

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

SensorReader reads SensorData from the serial connection with RFLink

func NewSensorReader

func NewSensorReader(o *Options) (*SensorReader, error)

NewSensorReader returns a SensorReader according to the options specified

func (*SensorReader) Close

func (sr *SensorReader) Close()

Close closes the serial port

func (*SensorReader) ReadNext

func (sr *SensorReader) ReadNext() (*SensorData, error)

ReadNext reads a line from RFLink and returns it in the form of a SensorData struct

Jump to

Keyboard shortcuts

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