mqtt

package
v0.0.0-...-bb884da Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 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.

View Source
const QOS byte = 0

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 of DigitalStrom.
	Publish(topic string, message interface{}) error
	// Same as publish but force the retain flag regardless of what is in the config
	PublishAndRetain(topic string, message interface{}) error
	// Subscribe to a topic and calls the given handler when a message is
	// received.
	Subscribe(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
	NormalizeDeviceName bool
	Retain              bool
	QoS                 byte
	DisconnectTimeout   time.Duration
}

ClientOptions contains configurable options for the MQTT client responsible to communicate with DigitalStrom data.

func NewClientOptions

func NewClientOptions() *ClientOptions

NewClientOptions will create a new ClientOptions type with some default values.

  TopicPrefix: "digitalstrom"
	 NormalizeDeviceName: true
	 Retain: true
	 QoS: 0
	 DisconnectTimeout: 1 second

func (*ClientOptions) SetMqttUrl

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

SetMqttUrl will set the address for the DigitalStrom 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.

type SubscriptionHandler

type SubscriptionHandler struct {
	Topic          string
	MessageHandler mqtt.MessageHandler
}

type Subscriptions

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

Jump to

Keyboard shortcuts

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