commit 3feee60a2aaaeb7253c59ea4abdee9a8e73921d4
parent 8ee8bb3e245874cde667086b1712ec0f9c78bf5d
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Thu, 20 Mar 2025 20:11:17 +0000
MQTTS support
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/main.go b/main.go
@@ -46,6 +46,7 @@ type MqttConfig struct {
Session string
UserName string
Password string
+ TLS bool
Keepalive int
}
@@ -103,6 +104,14 @@ func readConfig(path string) Config {
return config
}
+func dialer(config Config) mqtt.Dialer {
+ if config.Mqtt.TLS {
+ return mqtt.NewTLSDialer("tcp", config.Mqtt.Server, nil)
+ } else {
+ return mqtt.NewDialer("tcp", config.Mqtt.Server)
+ }
+}
+
func main() {
var err error
var m *mqtt.Client
@@ -127,7 +136,7 @@ func main() {
}
m, err = mqtt.VolatileSession(config.Mqtt.Session, &mqtt.Config{
- Dialer: mqtt.NewDialer("tcp", config.Mqtt.Server),
+ Dialer: dialer(config),
PauseTimeout: 4 * time.Second,
UserName: config.Mqtt.UserName,
Password: []byte(config.Mqtt.Password),