diff options
| author | xengineering <me@xengineering.eu> | 2026-03-26 20:57:22 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-03-26 20:57:22 +0100 |
| commit | 443ba52ab3f49a28e8874ebcb5476e36c3defb4c (patch) | |
| tree | 3ac9b723f89889d6904e23bf0d54541539c0d671 | |
| parent | a965777d436f3bd68686e3b33066459c7ed5a01c (diff) | |
| download | sia-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.
| -rw-r--r-- | cache.go | 1 | ||||
| -rw-r--r-- | mqtt.go | 4 |
2 files changed, 4 insertions, 1 deletions
@@ -43,6 +43,7 @@ func (c *Cache) Update(states States) { c.Tx <- MQTTMessage{ Topic: topic, Payload: payload, + Retain: true, } } c.States[id] = state @@ -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) } } |
