messenger

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package messenger ferries data between serial port, mqtt, and the postgresql

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GatewayStatus

type GatewayStatus struct {
	OK        bool      // generic message
	Timestamp time.Time // time message was sent by the gateway
}

GatewayStatus sends "OK" message at regular intervals

func (*GatewayStatus) Process

func (gs *GatewayStatus) Process() ([]byte, error)

Process turn gateway status message into mqtt payload

type Message

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

type Messenger

type Messenger struct {
	Data chan *Message // Actual data packets
	// contains filtered or unexported fields
}

Messenger receives Message from serial port, publishes to paho and stores locally

func NewMessenger

func NewMessenger(client paho.Client, db *localdb.LocalDB) (*Messenger, error)

NewMessenger gets a new messenger

func (*Messenger) NewMessage

func (m *Messenger) NewMessage(packet *tlv.TLV) (*Message, error)

NewMessage makes a new message from a tlv packet mqtt topic and logs the entry to the postgresql in the background

func (*Messenger) Start

func (m *Messenger) Start()

Start waits for packet to publish or to receive signal interrupt

func (*Messenger) Stop

func (m *Messenger) Stop()

Stop kills the main loop

type Payload

type Payload interface {
	Process() ([]byte, error)
}

Payload generic type of message we'll send over MQTT

type RainEvent

type RainEvent struct {
	Millimeters float64   // amount of rain in millimeters
	Timestamp   time.Time // timestamp when rain was measured on the gateway
}

RainEvent sends message about rain event

func (*RainEvent) Process

func (r *RainEvent) Process() ([]byte, error)

Process turn rain event into mqtt payload

type SensorEvent

type SensorEvent struct {
	Tag       int       // tag code for the event
	Value     int       // value, generally 1
	Event     string    //  human readable event, matches 1-to-1 with Tag
	Timestamp time.Time // timestamp as the event actually was recorded on the gateway
}

SensorEvent gives static message about what's happening to the sensor

func (*SensorEvent) Process

func (s *SensorEvent) Process() ([]byte, error)

Process turn static value into mqtt payload

type SensorStatus

type SensorStatus struct {
	OK        bool      // generic message
	Timestamp time.Time // time message was sent by the gateway
}

SensorStatus sends "OK" if sensor is reachable, else "Bad"

func (*SensorStatus) Process

func (ss *SensorStatus) Process() ([]byte, error)

Process turn sensor status message into mqtt payload

type TemperatureEvent

type TemperatureEvent struct {
	TempC     int       // tempC value
	Timestamp time.Time // timestamp when temp was recorded on the gateway
}

TemperatureEvent sends current temperature in Celsius

func (*TemperatureEvent) Process

func (t *TemperatureEvent) Process() ([]byte, error)

Process turn temp into mqtt payload

Jump to

Keyboard shortcuts

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