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 ¶
NewPublisher return a Publisher according to the options specified
func (*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 ¶
ReadAndPublish loops infinitely to read SensorData from the SensorReader and publish the output via the Publish() method
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) ReadNext ¶
func (sr *SensorReader) ReadNext() (*SensorData, error)
ReadNext reads a line from RFLink and returns it in the form of a SensorData struct