mqtt

package
v0.0.0-...-9d63270 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Online  string = "online"
	Offline string = "offline"
)

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
	PublishAndLogError(topic string, message interface{})

	// 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 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.

Jump to

Keyboard shortcuts

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