From 05907d4745cc265e095a6bbdea1f3de864586cd7 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sat, 21 Jan 2023 22:20:16 +0000 Subject: [PATCH] logging on disconnect --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 09854b9..ef99375 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,9 @@ func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) { tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages)) } +func onConnectionLostHandler(c MQTT.Client, reason error) { + log.Fatalf(reason.Error()) +} func setupMQTT() *mqtt.ClientOptions { opts := MQTT.NewClientOptions() opts.AddBroker(fmt.Sprintf("tcp://%s:%s", os.Getenv("MQTTBROKER"), os.Getenv("MQTTPORT"))) @@ -112,6 +115,7 @@ func setupMQTT() *mqtt.ClientOptions { opts.SetPassword(os.Getenv("MQTTPASSWORD")) opts.SetClientID("rgbboard") opts.SetAutoReconnect(true) + opts.SetConnectionLostHandler(onConnectionLostHandler) return opts }