summaryrefslogtreecommitdiff
path: root/mqtt.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2026-03-26 20:57:22 +0100
committerxengineering <me@xengineering.eu>2026-03-26 20:57:22 +0100
commit443ba52ab3f49a28e8874ebcb5476e36c3defb4c (patch)
tree3ac9b723f89889d6904e23bf0d54541539c0d671 /mqtt.go
parenta965777d436f3bd68686e3b33066459c7ed5a01c (diff)
downloadsia-server-443ba52ab3f49a28e8874ebcb5476e36c3defb4c.tar
sia-server-443ba52ab3f49a28e8874ebcb5476e36c3defb4c.tar.zst
sia-server-443ba52ab3f49a28e8874ebcb5476e36c3defb4c.zip
Add `Retain` attribute to MQTTMessage
This allows the sending part of the code to decide about the retain flag. The MQTT go routine will set it accordingly.
Diffstat (limited to 'mqtt.go')
-rw-r--r--mqtt.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/mqtt.go b/mqtt.go
index fd1cba1..acd0108 100644
--- a/mqtt.go
+++ b/mqtt.go
@@ -27,6 +27,7 @@ var (
type MQTTMessage struct {
Topic string
Payload []byte
+ Retain bool
}
type Route struct {
@@ -60,6 +61,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) {
message := MQTTMessage{
Topic: strings.TrimPrefix(msg.Topic(), config.TopicPrefix + "/"),
Payload: msg.Payload(),
+ Retain: msg.Retained(),
}
route.Destination <- message
})
@@ -88,7 +90,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) {
for message := range tx {
topic := fmt.Sprintf("%s/%s", config.TopicPrefix, message.Topic)
- client.Publish(topic, QoS1, RETAINED, message.Payload)
+ client.Publish(topic, QoS1, message.Retain, message.Payload)
}
}