mqtt

package
v0.0.0-...-bf22cec Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 3 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 a structure for managing the MQTT connection

func (*Client) Disconnect

func (c *Client) Disconnect(quiesce uint)

Disconnect disconnects from the MQTT broker

func (*Client) GetClient

func (c *Client) GetClient() mqtt.Client

GetClient retrieves the underlying MQTT client

func (*Client) Publish

func (c *Client) Publish(p PublishPayload) error

Publish publishes a message to an MQTT topic

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, handler mqtt.MessageHandler) error

Subscribe subscribes to an MQTT topic

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(topics ...string) error

Unsubscribe unsubscribes from MQTT topics

type ClientInterface

type ClientInterface interface {
	// Subscribe subscribes to an MQTT topic with a given message handler.
	Subscribe(topic string, handler mqtt.MessageHandler) error

	// Publish publishes a message to an MQTT topic with the specified payload.
	Publish(p PublishPayload) error

	// Unsubscribe unsubscribes from one or more MQTT topics.
	Unsubscribe(topics ...string) error

	// Disconnect disconnects from the MQTT broker with the specified quiesce timeout.
	Disconnect(quiesce uint)

	// GetClient returns the underlying MQTT client.
	GetClient() mqtt.Client
}

ClientInterface defines an interface for MQTT client functionality.

func NewClient

func NewClient(opt Options) (ClientInterface, error)

NewClient creates a new MQTT client

type Options

type Options struct {
	Broker           string
	ClientId         string
	Username         string
	Password         string
	QoS              byte
	OnConnectionLost func(err error)
}

type PublishPayload

type PublishPayload struct {
	Topic    string
	Value    string
	QOS      byte
	Retained bool
}

Jump to

Keyboard shortcuts

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