Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MqttConnection ¶ added in v1.1.0
type MqttConnection struct {
// contains filtered or unexported fields
}
Struct holding the MQTT client and user settings
func NewMqttConnection ¶ added in v1.1.0
func NewMqttConnection(topicRoot string, qualityOfService int, options *mqtt.ClientOptions) (c MqttConnection)
Creating a new MQTT connection Parameter: * topicRoot: common prefix of a MQTT topic for this connection * qualityOfService: the MQTT quality of service for all operations * options: Return: * c: MqttConnection struct, containing a connected MQTT client and the specified parameters
func (MqttConnection) Disconnect ¶ added in v1.1.0
func (c MqttConnection) Disconnect(quiesce uint)
Disconnect from MQTT broker The does not invalidate the connection struct, Reconnect re-enables all functionality Parameter: * quiesce: amount of milliseconds to wait before closing
func (MqttConnection) Publish ¶ added in v1.1.0
func (c MqttConnection) Publish(obis, value, unit string, retained, updateOnlyIfChanged bool) (updated bool)
Publishes a message to the MQTT broker Parameter:
- obis: the obis code, which will be used as topic suffix
- value: the MQTT message containing the value
- unit: if a unit is specified it will be appended to the MQTT message. To drop the unit use an empty string ""
- retained: set to true if the message should be retained by the MQTT server
- updateOnlyIfChanged: set to true to publish the message only if the value differs from the previous This avoids short interval subscriber updates without any value change
Return: * updated: true if a message was published (depending on updateOnlyIfChanged!)
func (MqttConnection) Reconnect ¶ added in v1.1.0
func (c MqttConnection) Reconnect()
(Re)Connects the MQTT client
func (MqttConnection) Subscribe ¶ added in v1.1.0
func (c MqttConnection) Subscribe(obis string, callback mqtt.MessageHandler) (success bool)
Registers as subscriber to the specified topic Parameter: * obis: the topic extension to subscribe (topicRoot + extension) * callback: the callback function to call once a new message arrives (specify your own) Return: success: true is subscribing the topic was successful