mqtt

package
v0.0.0-...-dc1fef4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Online  string = "online"
	Offline string = "offline"
)
View Source
const (
	State   string = "state"
	Command string = "command"
	Event   string = "event"
)

Topics.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Connect to the MQTT server.
	Connect() error
	// Disconnect from the MQTT server.
	Disconnect() error

	// Publishes a message under the prefix topic
	PublishWithPrefix(topic string, message interface{}) error
	Publish(topic string, message interface{}) error
	// Subscribe to a topic and calls the given handler when a message is
	// received.
	SubscribeWithPrefix(topic string, messageHandler mqtt.MessageHandler) error

	// Return the full topic for a given subpath.
	GetFullTopic(topic string) string
	// Returns the topic used to publish the server status.
	ServerStatusTopic() string

	RawClient() mqtt.Client
}

func NewClient

func NewClient(options *ClientOptions) Client

type ClientOptions

type ClientOptions struct {
	MqttUrl           string
	Username          string
	Password          string
	TopicPrefix       string
	Retain            bool
	QoS               byte
	DisconnectTimeout time.Duration
}

ClientOptions contains configurable options for the MQTT client

func NewClientOptions

func NewClientOptions() *ClientOptions

func (*ClientOptions) SetMqttUrl

func (o *ClientOptions) SetMqttUrl(server string) *ClientOptions

SetMqttUrl will set the address for the server to connect.

func (*ClientOptions) SetPassword

func (o *ClientOptions) SetPassword(p string) *ClientOptions

SetPassword will set the password to be used by this client when connecting to the MQTT server.

func (*ClientOptions) SetRetain

func (o *ClientOptions) SetRetain(retain bool) *ClientOptions

SetRetain will define the value for the retain flag for all published messages.

func (*ClientOptions) SetTopicPrefix

func (o *ClientOptions) SetTopicPrefix(prefix string) *ClientOptions

SetTopicPrefix will set the prefix that will be prepended to all the published messages.

func (*ClientOptions) SetUsername

func (o *ClientOptions) SetUsername(u string) *ClientOptions

SetUsername will set the username to be used by this client when connecting to the MQTT server.

Jump to

Keyboard shortcuts

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