mqtt

package
v0.0.0-...-461d2ee Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// CmdOn represents command for lighting the stands
	CmdOn byte = iota
	// CmdOff represents command for disabling lights on stands
	CmdOff
	// CmdAnimate represents command for lighting stand led by led
	CmdAnimate
	// CmdSensor represents command for getting sensor data
	CmdSensor
	// CmdFade represents command for slowly lighting the stand
	CmdFade
	// CmdOffAll represents command for disabling lights on all stands
	CmdOffAll
)

List of commands that can be sent.

Variables

This section is empty.

Functions

func DisconnectTimeout

func DisconnectTimeout(sec time.Duration) func(*Config)

DisconnectTimeout is a functional option for creating MQTT clients.

func KeepAlive

func KeepAlive(sec time.Duration) func(*Config)

KeepAlive is a functional option for creating MQTT clients.

func Timeout

func Timeout(sec time.Duration) func(*Config)

Timeout is a functional option for creating MQTT clients.

Types

type BrokerError

type BrokerError string

BrokerError informs about possible failures when connecting to the broker.

const (
	// BrokerConnectionError when client can not connect to broker.
	BrokerConnectionError BrokerError = "BROKER_CONNECTION_ERROR - Could not connect to the MQTT broker"
)

func (BrokerError) Error

func (e BrokerError) Error() string

Error returns error as a string.

type Command

type Command struct {
	Platform byte
	Command  byte
	RGB      *RGB
}

Command describes command RPI should execute on slabs.

type Commander

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

Commander helps in constructing commands for MQTT client.

func NewCommander

func NewCommander(cli publisher) *Commander

NewCommander creates commander, that sends commands through given MQTT client.

func (*Commander) DisableAllLights

func (cm *Commander) DisableAllLights() error

DisableAllLights turns off all lights.

func (*Commander) PlatformColor

func (cm *Commander) PlatformColor(platformID byte, rgb RGB) error

PlatformColor lights up platform.

func (*Commander) PlatformFadePixels

func (cm *Commander) PlatformFadePixels(platformID byte, rgb RGB, delay byte) error

PlatformFadePixels turns on every single pixel one by one.

func (*Commander) PlatformRotateColor

func (cm *Commander) PlatformRotateColor(platformID byte, rgb RGB, delay int) error

PlatformRotateColor rotates pixel around the platform.

func (*Commander) PlatformSensorReading

func (cm *Commander) PlatformSensorReading(platformID byte) error

PlatformSensorReading enables reading callback events.

type Config

type Config struct {
	MQTT struct {
		Broker string `envconfig:"default=tcp://test.mosquitto.org:1883"`

		KeepAlive struct {
			Seconds time.Duration `envconfig:"default=2s"`
		}

		Timeout struct {
			Seconds time.Duration `envconfig:"default=2s"`
		}

		Disconnect struct {
			Milliseconds time.Duration `envconfig:"default=250ms"`
		}
	}
}

Config for MQTT supporting envconfig for environmental variable parsing. If initialized correctly (by envconfig), contains sane defaults.

type MQTT

type MQTT struct {
	evbus.Bus
	// contains filtered or unexported fields
}

MQTT is an abstraction over MQTT client with API specific for Bullseye slab control.

func FromConfig

func FromConfig(config *Config) (*MQTT, error)

FromConfig initializes MQTT client based on config, as opposed to New, which initializes based on functional options.

func New

func New(broker string, options ...func(*Config)) (*MQTT, error)

New creates and connects MQTT client (by calling FromConfig).

func (*MQTT) Disconnect

func (m *MQTT) Disconnect(milliseconds time.Duration) error

Disconnect from the server.

func (*MQTT) Publish

func (m *MQTT) Publish(cmd Command) error

Publish message to the broker.

func (*MQTT) Subscribe

func (m *MQTT) Subscribe(fn func(*Command)) error

Subscribe on event bus using passed Command.

type RGB

type RGB struct {
	R, G, B byte
}

RGB describes color with 3 bytes. Each color (r, g, b) fits between 0 and 255.

Jump to

Keyboard shortcuts

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