mqtt

package
v10.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoConnection       = errors.New("no MQTT connection")
	ErrInvalidTopicPrefix = errors.New("invalid topic prefix")
	ErrInvalidServer      = errors.New("invalid server")
	ErrNoPrefs            = errors.New("no preferences provided")
)

Functions

This section is empty.

Types

type Client

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

Client is the connection to the MQTT broker.

func NewClient

func NewClient(ctx context.Context, prefs MQTTPrefs, subscriptions []*Subscription, configs []*Msg) (*Client, error)

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, msgs ...*Msg) error

Publish will send the list of messages it is passed to the broker that the client is connected to. Any errors in publihsing will be returned.

func (*Client) Unpublish

func (c *Client) Unpublish(ctx context.Context, msgs ...*Msg) error

type Device

type Device interface {
	Name() string
	Configuration() []*Msg
	States() []*Msg
	Subscriptions() []*Subscription
}

type MQTTPrefs

type MQTTPrefs interface {
	TopicPrefix() string
	Server() string
	User() string
	Password() string
}

type Msg

type Msg struct {
	Topic    string
	Message  json.RawMessage
	QOS      byte
	Retained bool
}

Msg represents a message that can be sent or received on the MQTT bus.

func NewMsg

func NewMsg(topic string, msg json.RawMessage) *Msg

NewMsg is a convenience function to create a new Msg with a given topic and message body. The returned Msg can be further customised directly for specifying retention and QoS parameters, which are not set through this function and assumed to be left as their default values.

func (*Msg) Retain

func (m *Msg) Retain() *Msg

Retain sets the Retained status of a Msg to true, ensuring that it will be retained on the MQTT bus when sent.

type Subscription

type Subscription struct {
	Callback func(p *paho.Publish)
	Topic    string
}

Subscription represents a listener on a specific Topic, that will pass any messages sent to that topic to the Callback function.

Jump to

Keyboard shortcuts

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