mqttagent

MQTT Lua Agent
git clone https://git.instinctive.eu/mqttagent.git
Log | Files | Refs | README | LICENSE

commit 96375b84c00398f617d259bb5013909468565770
parent 114d7eb8dc936de6c74f0a443400ff21d9a6eefc
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Tue, 11 Feb 2025 19:43:33 +0000

MQTT configuration uses strings rather than byte slices
Diffstat:
Mmqttagent.go | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/mqttagent.go b/mqttagent.go @@ -290,10 +290,10 @@ type mqttConfig struct { AtLeastOnceMax int ExactlyOnceMax int UserName string - Password []byte + Password string Will struct { Topic string - Message []byte + Message string Retain bool AtLeastOnce bool ExactlyOnce bool @@ -302,6 +302,14 @@ type mqttConfig struct { CleanSession bool } +func mqttConfigBytes(src string) []byte { + if src == "" { + return nil + } else { + return []byte(src) + } +} + func newClient(config *mqttConfig, id string) (*mqtt.Client, error) { pto, err := time.ParseDuration(config.PauseTimeout) if err != nil { @@ -314,7 +322,7 @@ func newClient(config *mqttConfig, id string) (*mqtt.Client, error) { AtLeastOnceMax: config.AtLeastOnceMax, ExactlyOnceMax: config.ExactlyOnceMax, UserName: config.UserName, - Password: config.Password, + Password: mqttConfigBytes(config.Password), Will: struct { Topic string Message []byte @@ -323,7 +331,7 @@ func newClient(config *mqttConfig, id string) (*mqtt.Client, error) { ExactlyOnce bool }{ Topic: config.Will.Topic, - Message: config.Will.Message, + Message: mqttConfigBytes(config.Will.Message), Retain: config.Will.Retain, AtLeastOnce: config.Will.AtLeastOnce, ExactlyOnce: config.Will.ExactlyOnce,