allow custom root topics

This commit is contained in:
root 2024-12-01 04:34:59 +00:00
parent ec6cb716a6
commit 1b62110914
2 changed files with 13 additions and 5 deletions

View file

@ -227,6 +227,16 @@ 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(`/2/e/[^/]+/![0-9a-f]+$|/2/map/$`),
Accept: func(from uint32) bool {
_, found := blocked[from]

View file

@ -31,6 +31,7 @@ func NewBlockCipher(key []byte) cipher.Block {
}
type MQTTClient struct {
Topics []string
TopicRegex *regexp.Regexp
Accept func(from uint32) bool
BlockCipher cipher.Block
@ -56,11 +57,8 @@ func (c *MQTTClient) Connect() error {
}
log.Print("[info] connected")
topics := make(map[string]byte)
for i, region := range generated.Config_LoRaConfig_RegionCode_name {
if i == 0 {
continue
}
topics["msh/"+region+"/#"] = 0
for _, topic := range c.Topics {
topics[topic] = 0
}
token = c.SubscribeMultiple(topics, nil)
<-token.Done()