Documentation
¶
Index ¶
- Constants
- type Client
- type ClientOptions
- func (o *ClientOptions) SetMqttUrl(server string) *ClientOptions
- func (o *ClientOptions) SetPassword(p string) *ClientOptions
- func (o *ClientOptions) SetRetain(retain bool) *ClientOptions
- func (o *ClientOptions) SetTopicPrefix(prefix string) *ClientOptions
- func (o *ClientOptions) SetUsername(u string) *ClientOptions
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.
Click to show internal directories.
Click to hide internal directories.