mqttim

MQTT ↔ Instant Messaging Bridge
git clone https://git.instinctive.eu/mqttim.git
Log | Files | Refs | README | LICENSE

commit 3e402125306c461987b2c07051a5323d62b92f8c
parent eaa4e79e526229b84ff7accdfc8f076a1601006a
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Wed, 22 Jan 2025 18:54:56 +0000

Non-fatal MQTT errors let the reader continue
Diffstat:
Mmain.go | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -146,7 +146,7 @@ func dup(src []byte) []byte { return res } -func mqtt2irc(m *mqtt.Client, l *mqttLogger, f mqttTopicFilter, c chan Msg, config *Config) error { +func mqtt2irc(m *mqtt.Client, l *mqttLogger, f mqttTopicFilter, c chan Msg, config *Config) { var big *mqtt.BigMessage for { @@ -158,15 +158,27 @@ func mqtt2irc(m *mqtt.Client, l *mqttLogger, f mqttTopicFilter, c chan Msg, conf if !isFiltered(&f, topic) { c <- msg } + case errors.As(err, &big): msg := Msg{Topic: dup(topic), Message: []byte("<Big Message>")} logReceived(l, msg.Message, msg.Topic) if !isFiltered(&f, topic) { c <- msg } + + case errors.Is(err, mqtt.ErrClosed): + log.Println("mqtt2irc finishing:", err) + return + + case mqtt.IsConnectionRefused(err): + c <- Msg{Topic: []byte("$mqttim/err2"), + Message: []byte(err.Error())} + time.Sleep(5 * time.Minute) + default: - log.Print(err) - return err + c <- Msg{Topic: []byte("$mqttim/err"), + Message: []byte(err.Error())} + time.Sleep(2 * time.Second) } } }