mqtt

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 NewMQTTClient

func NewMQTTClient(ctx context.Context, prefs prefs) (*Client, error)

NewMQTTClient will establish a new connection to the MQTT service, using the configuration found under the path specified with prefsPath.

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) Subscribe

func (c *Client) Subscribe(subs ...*Subscription) error

Subscribe will parse the list of subscriptions and listen on their topics, passing any received messages to their callback functions. Any error in setting up a subscription will be returned.

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(MQTT.Client, MQTT.Message)
	Topic    string
	QOS      byte
	Retained bool
}

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