summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2025-09-04 01:40:07 +0300
committerMarin Ivanov <[email protected]>2025-09-04 09:00:55 +0300
commit9897dc711a8e3e1be51a72d5f68f50692b289eeb (patch)
tree065a20d7b0ad972cacd914c85850b9fda61afb7e
parentf37dd8d9f636d312614d9459802aab0847548c3a (diff)
Fixes
bugfix: channel hash over MQTT bugfix: telemetry reply fix: typo
-rw-r--r--mqtt.go22
-rw-r--r--node.go2
-rw-r--r--noderxloop.go3
3 files changed, 14 insertions, 13 deletions
diff --git a/mqtt.go b/mqtt.go
index 2e83e8a..c3caa37 100644
--- a/mqtt.go
+++ b/mqtt.go
@@ -26,12 +26,12 @@ type MqttIf struct {
GatewayID meshtastic.NodeID
Channels *pb.ChannelSet
- logger *log.Logger
- c *autopaho.ConnectionManager
- ctx context.Context
- stop context.CancelFunc
- inputCh chan mqttServiceEnvelope
- chIdMap map[string]uint8
+ logger *log.Logger
+ c *autopaho.ConnectionManager
+ ctx context.Context
+ stop context.CancelFunc
+ inputCh chan mqttServiceEnvelope
+ chIdHash map[string]uint32
}
type mqttServiceEnvelope struct {
@@ -62,7 +62,7 @@ func (m *MqttIf) channelPublishTopic(channelId string) string {
func (m *MqttIf) onConnectionUp(cm *autopaho.ConnectionManager, connAck *paho.Connack) {
topics := []string{fmt.Sprintf("%s/2/e/PKI/#", m.Root)}
- chIdMap := make(map[string]uint8)
+ chIdHash := make(map[string]uint32)
for _, c := range m.Channels.Settings {
topics = append(topics, fmt.Sprintf("%s/2/e/%s/#", m.Root, c.Name))
channelHash, err := radio.ChannelHash(c.Name, c.Psk)
@@ -71,9 +71,9 @@ func (m *MqttIf) onConnectionUp(cm *autopaho.ConnectionManager, connAck *paho.Co
m.c.Disconnect(m.ctx)
return
}
- chIdMap[c.Name] = uint8(channelHash)
+ chIdHash[c.Name] = channelHash
}
- m.chIdMap = chIdMap
+ m.chIdHash = chIdHash
subscriptions := make([]paho.SubscribeOptions, 0, len(topics))
for _, t := range topics {
subscriptions = append(subscriptions, paho.SubscribeOptions{Topic: t, QoS: 1})
@@ -168,7 +168,6 @@ func (m *MqttIf) ReadMeshPacket() (*pb.MeshPacket, uint64, error) {
if p.se == nil || p.se.Packet == nil {
return nil, 0, errors.New("no input")
}
- p.se.Packet.Channel = uint32(m.chIdMap[p.se.ChannelId])
return p.se.Packet, uint64(p.timestamp.UnixMicro()), nil
}
@@ -177,16 +176,17 @@ func (m *MqttIf) WriteMeshPacket(p *pb.MeshPacket) error {
if p.PkiEncrypted {
channelId = "PKI"
p.Priority = pb.MeshPacket_HIGH
+ p.Channel = 0
} else {
channel := m.Channels.Settings[p.Channel]
channelId = channel.Name
+ p.Channel = m.chIdHash[channelId]
}
if p.RxTime == 0 {
p.RxTime = uint32(time.Now().Unix())
}
p.RelayNode = p.RelayNode & 0xFF
p.NextHop = p.NextHop & 0xFF
- p.Channel = 0 // Don't expose your channel number
se := &pb.ServiceEnvelope{
Packet: p,
ChannelId: channelId,
diff --git a/node.go b/node.go
index a2b8edb..0481396 100644
--- a/node.go
+++ b/node.go
@@ -591,7 +591,7 @@ func (n *Node) dispatchMessageToAdmin(msg *pb.FromRadio) error {
}
for conn := range n.adminConn {
if err := conn.Write(msg); err != nil {
- n.logger.Errorf("failed to send to admin: %w", err)
+ n.logger.Errorf("failed to send to admin: %s", err)
}
}
return nil
diff --git a/noderxloop.go b/noderxloop.go
index f4ed602..d7e275e 100644
--- a/noderxloop.go
+++ b/noderxloop.go
@@ -5,6 +5,7 @@ import (
"context"
"encoding/hex"
"fmt"
+ "time"
"github.com/charmbracelet/log"
"github.com/meshnet-gophers/meshtastic-go"
@@ -238,7 +239,7 @@ func (n *Node) rxMessage(ts uint64, p *pb.MeshPacket) error {
if err != nil {
break
}
- reply = metrics
+ reply = &pb.Telemetry{Time: uint32(time.Now().Unix()), Variant: &pb.Telemetry_DeviceMetrics{DeviceMetrics: metrics}}
} else {
deviceMetrics := telemetry.GetDeviceMetrics()
if deviceMetrics == nil {