Compare commits

..

No commits in common. "7a8a2ce030e89f5efddaa319a06a3fd7b35a12d5" and "f33853a4ddf969595826d9f47a93e63875dc0930" have entirely different histories.

2 changed files with 18 additions and 21 deletions

View file

@ -227,17 +227,7 @@ func main() {
}
// connect to MQTT
client := &meshtastic.MQTTClient{
Topics: []string{
"msh/+/2/map/",
"msh/+/2/e/+/+",
"msh/+/+/2/map/",
"msh/+/+/2/e/+/+",
"msh/+/+/+/2/map/",
"msh/+/+/+/2/e/+/+",
"msh/+/+/+/+/2/map/",
"msh/+/+/+/+/2/e/+/+",
},
TopicRegex: regexp.MustCompile(`^msh(?:/[^/]+)+/2/(?:e/[^/]+/![0-9a-f]+|map/)$`),
TopicRegex: regexp.MustCompile(`/2/e/[^/]+/![0-9a-f]+$|/2/map/$`),
Accept: func(from uint32) bool {
_, found := blocked[from]
return !found

View file

@ -9,6 +9,7 @@ import (
"log"
"os"
"regexp"
"time"
"github.com/brianshea2/meshmap.net/internal/meshtastic/generated"
mqtt "github.com/eclipse/paho.mqtt.golang"
@ -31,11 +32,11 @@ func NewBlockCipher(key []byte) cipher.Block {
}
type MQTTClient struct {
Topics []string
TopicRegex *regexp.Regexp
Accept func(from uint32) bool
BlockCipher cipher.Block
MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte)
topics []string
mqtt.Client
}
@ -56,21 +57,27 @@ func (c *MQTTClient) Connect() error {
return err
}
log.Print("[info] connected")
topics := make(map[string]byte)
for _, topic := range c.Topics {
topics[topic] = 0
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)
c.topics = append(c.topics, topic)
}
token = c.SubscribeMultiple(topics, nil)
<-token.Done()
if err := token.Error(); err != nil {
return err
}
log.Print("[info] subscribed")
return nil
}
func (c *MQTTClient) Disconnect() {
if c.IsConnected() {
if c.Unsubscribe(c.topics...).WaitTimeout(time.Second) {
log.Print("[info] unsubscribed")
}
c.Client.Disconnect(1000)
}
}