state

package
v0.0.0-...-138a2ce Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: BSD-2-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AMQP

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

AMQP is the AMQP client.

func (*AMQP) Close

func (a *AMQP) Close() error

Close will close the channel to the AMQP broker. It will return an error if the channel fails to gracefully close.

func (*AMQP) GetRouting

func (a *AMQP) GetRouting() map[string][]string

GetRouting returns the list queues and the list of routing queues binded to each queue.

func (*AMQP) Init

func (a *AMQP) Init(log *log.Logger, id, host string) (chan AMQPMessage, error)

Init will attempt to initialize the AMQP client. It requires the AMQP broker's ID string and formatted AMQP host string. It will return the output channel or an error.

func (*AMQP) Publish

func (a *AMQP) Publish(routingKey string, payload []byte) error

Publish accept a routing key and a payload. It will attempt to publish the payload with the provided routing key. It will return an error if the payload fails to publish.

func (*AMQP) UpdateRouting

func (a *AMQP) UpdateRouting(routing map[string][]string) error

UpdateRouting replace the AMQP routing with the one provided. It will notify the AMQP broker of the changes. It may return an error if the transaction fails to complete.

type AMQPMessage

type AMQPMessage struct {
	RoutingKey string
	Payload    []byte
}

AMQPMessage is a message sent over AMQP.

type Config

type Config struct {
	AMQPUser string // AMQPUser is AMQP username
	AMQPPass string // AMQPPass is AMQP password
	MQTTUser string // MQTTUser is MQTT username
	MQTTPass string // MQTTPass is MQTT password
	SQLUser  string // SQLUser is SQL username
	SQLPass  string // SQLPass is SQL password
}

Config is the environment variable configuration for the controller.

type MQTT

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

MQTT is the MQTT client.

func (*MQTT) Close

func (m *MQTT) Close()

Close will close the connection to the MQTT broker.

func (*MQTT) Connect

func (m *MQTT) Connect() error

Connect will attempt to establish a connection with the MQTT broker. It will return an error if the connection fails to establish.

func (*MQTT) GetTopics

func (m *MQTT) GetTopics() []string

GetTopics returns the list of currently subscribed topics.

func (*MQTT) Init

func (m *MQTT) Init(log *log.Logger, host, user, pass string) (chan MQTTMessage, error)

Init will attempt to initialize the MQTT client. It requires the MQTT broker's host, username, and password. It will return the output channel or an error.

func (*MQTT) Publish

func (m *MQTT) Publish(topic string, payload []byte) error

Publish will publish a payload on the provided topic. It will return an error if the payload fails to publish.

func (*MQTT) UpdateTopics

func (m *MQTT) UpdateTopics(topics []string) error

UpdateTopics repleaces the subscribe topics list with the one provided. It will notify the MQTT broker of the changes. It may return an error if the transaction fails to complete.

type MQTTMessage

type MQTTMessage struct {
	Topic   string // Topic is the topic the message was published on
	Payload []byte // Payload is the message payload
}

MQTTMessage is a message sent over MQTT.

type State

type State struct {
	Log      *log.Logger         // Log is a structured event logger
	IsDocker bool                // IsDocker indicates if running inside Docker
	Config   *Config             // Config contains global configuration
	MQTT     *MQTT               // MQTT is the MQTT client
	MQTTCh   chan MQTTMessage    // MQTTCh is the MQTT output channel
	AMQP     [2]*AMQP            // AMQP is the AMQP client (two for duplex)
	AMQPCh   [2]chan AMQPMessage // AMQPCh is the AMQP output channel
	SQL      *sql.DB             // SQL is the SQL client
	Data     chan []byte         // Data channel is populated by AMQP and consumed by websockets
}

State is the global state for the controller.

func Provision

func Provision() (*State, error)

Provision generates a global state for the controller. It will return an error if the state fails to initialize.

type WebsocketFrame

type WebsocketFrame struct {
	UUID      string      `json:"uuid"`      // UUID is the UUID of the microcontroller
	BusAddr   int         `json:"busAddr"`   // BusAddr is the bus address where data was collected
	Timestamp string      `json:"timestamp"` // Timestamp is time which data was received by peripheral controller
	Data      interface{} `json:"data"`      // Data is the JSON payload from peripheral controller
}

WebsocketFrame is a frame emitted on the websocket connection.

Jump to

Keyboard shortcuts

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