commit af957d17b817dd909e7861c60e81cf8257c29bd3
parent e8ef50a84aad53523b47944c3aacf3412b0dfa25
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Tue, 14 Jan 2025 19:13:56 +0000
Non-fatal MQTT errors let the reader continue
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mqttagent.go b/mqttagent.go
@@ -182,6 +182,7 @@ func mqttRead(client *mqtt.Client, toLua chan<- MqttMessage, id int) {
switch {
case err == nil:
toLua <- MqttMessage{Timestamp: t, ClientId: id, Topic: dup(topic), Message: dup(message)}
+
case errors.As(err, &big):
data, err := big.ReadAll()
if err != nil {
@@ -189,9 +190,16 @@ func mqttRead(client *mqtt.Client, toLua chan<- MqttMessage, id int) {
} else {
toLua <- MqttMessage{Timestamp: t, ClientId: id, Topic: dup(topic), Message: data}
}
+
+ case errors.Is(err, mqtt.ErrClosed):
+ return
+
+ case mqtt.IsConnectionRefused(err):
+ time.Sleep(15 * time.Minute)
+
default:
log.Println(err)
- return
+ time.Sleep(2 * time.Second)
}
}
}