mqtt

package
v9.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConnection = errors.New("no MQTT connection")

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 prefs, subscriptions []*Subscription, configs []*Msg) (*Client, error)

func (*Client) Publish

func (c *Client) Publish(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(msgs ...*Msg) error

type Device

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

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.

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