mirror of
https://github.com/brianshea2/meshmap.net.git
synced 2025-03-05 21:00:01 -08:00
use SubscribeMultiple
This commit is contained in:
parent
77509cb40e
commit
ec6cb716a6
|
@ -9,7 +9,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/brianshea2/meshmap.net/internal/meshtastic/generated"
|
"github.com/brianshea2/meshmap.net/internal/meshtastic/generated"
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
@ -56,18 +55,19 @@ func (c *MQTTClient) Connect() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Print("[info] connected")
|
log.Print("[info] connected")
|
||||||
|
topics := make(map[string]byte)
|
||||||
for i, region := range generated.Config_LoRaConfig_RegionCode_name {
|
for i, region := range generated.Config_LoRaConfig_RegionCode_name {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
topic := "msh/" + region + "/#"
|
topics["msh/"+region+"/#"] = 0
|
||||||
token = c.Subscribe(topic, 0, nil)
|
|
||||||
<-token.Done()
|
|
||||||
if err := token.Error(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Printf("[info] subscribed to %v", topic)
|
|
||||||
}
|
}
|
||||||
|
token = c.SubscribeMultiple(topics, nil)
|
||||||
|
<-token.Done()
|
||||||
|
if err := token.Error(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Print("[info] subscribed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue