rflink

package
v0.0.3-beta Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoRFLinkInit

func GoRFLinkInit() error

GoRFLinkInit Entry point for calling

func SendData

func SendData(data chan *SensorData, p *SensorData)

func SendError

func SendError(err chan error, error error)

Types

type Options

type Options struct {
	// MQTT options
	Publish struct {
		Host              string `envconfig:"default=localhost:1883"` // host:port
		Scheme            string `envconfig:"default=tcp"`
		MqttUsername      string `envconfig:"default=username"`
		MqttPassword      string `envconfig:"default=password"`
		ProtocolVersion   uint   `envconfig:"default=4"`
		InfinityReconnect bool   `envconfig:"default=true"`
		ClientID          string `envconfig:"default=gorflink"`
		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 {
	C     mqtt.Client
	Topic string
}

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)

Not implemented yet

var messageHandler mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
	// fixme
}

NewPublisher return a Publisher according to the options specified

func (*Publisher) Disconnect

func (p *Publisher) Disconnect()

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(rflinkChans *rflinkChannels)

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

type SensorChannel

type SensorChannel struct {
	Message chan *SensorData
	Error   chan error
}

SensorChannel Struct for Channels of Sensor messages

func NewSensorChannels

func NewSensorChannels() (event *SensorChannel)

NewSensorChannels Initialization

type SensorData

type SensorData struct {
	Hwid         string   `json:"hwid"`
	Model        string   `json:"model"`
	Id           string   `json:"id"`
	FriendlyName string   `json:"name,omitempty"`
	Temperature  *float32 `json:"temp,omitempty"`
	Humidity     *uint16  `json:"hum,omitempty"`
	Bat          string   `json:"bat,omitempty"`
	Switch       string   `json:"switch,omitempty"`
	Cmd          string   `json:"cmd,omitempty"`
	Timestamp    string   `json:"timestamp"`
}

SensorData represents one message received from RFLink. 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 SerialChannel

type SerialChannel struct {
	Message chan string
	Error   chan error
}

SerialChannel Struct for Channels of Serial messages

func NewSerialChannels

func NewSerialChannels() (event *SerialChannel)

NewSerialChannels Initialization

type SerialReader

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

SerialReader reads SensorData from the serial connection with RFLink

func NewSerialReader

func NewSerialReader(o *Options) (*SerialReader, error)

NewSerialReader returns a SensorReader according to the options specified

func (*SerialReader) Close

func (sr *SerialReader) Close() error

Close closes the serial port

Jump to

Keyboard shortcuts

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