From ec0fd4f916ca3fe25a760775ec01bd81a245604e Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 7 Feb 2022 15:54:36 +0100 Subject: [PATCH] Set connection lost handler to exit subscription mode Signed-off-by: Knut Ahlers --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 228b932..1359f42 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,9 @@ func main() { mqtt.NewClientOptions(). AddBroker(cfg.MQTTBroker). SetClientID(cfg.MQTTClientID). + SetConnectionLostHandler(func(_ mqtt.Client, err error) { + log.WithError(err).Fatal("Connection to broker lost") + }). SetKeepAlive(cfg.MQTTTimeout). SetPassword(cfg.MQTTPass). SetUsername(cfg.MQTTUser),