From ec6cb716a681a152f78e71a72d5352df8d3950dd Mon Sep 17 00:00:00 2001 From: root <165865819+brianshea2@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:53:45 +0000 Subject: [PATCH] use SubscribeMultiple --- internal/meshtastic/mqtt.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/meshtastic/mqtt.go b/internal/meshtastic/mqtt.go index 2c783f4..62456ee 100644 --- a/internal/meshtastic/mqtt.go +++ b/internal/meshtastic/mqtt.go @@ -9,7 +9,6 @@ import ( "log" "os" "regexp" - "time" "github.com/brianshea2/meshmap.net/internal/meshtastic/generated" mqtt "github.com/eclipse/paho.mqtt.golang" @@ -56,18 +55,19 @@ func (c *MQTTClient) Connect() error { return err } log.Print("[info] connected") + topics := make(map[string]byte) for i, region := range generated.Config_LoRaConfig_RegionCode_name { if i == 0 { continue } - topic := "msh/" + region + "/#" - token = c.Subscribe(topic, 0, nil) - <-token.Done() - if err := token.Error(); err != nil { - return err - } - log.Printf("[info] subscribed to %v", topic) + topics["msh/"+region+"/#"] = 0 } + token = c.SubscribeMultiple(topics, nil) + <-token.Done() + if err := token.Error(); err != nil { + return err + } + log.Print("[info] subscribed") return nil }