summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache.go1
-rw-r--r--mqtt.go4
2 files changed, 4 insertions, 1 deletions
diff --git a/cache.go b/cache.go
index 4e0eddc..18ce0c9 100644
--- a/cache.go
+++ b/cache.go
@@ -43,6 +43,7 @@ func (c *Cache) Update(states States) {
c.Tx <- MQTTMessage{
Topic: topic,
Payload: payload,
+ Retain: true,
}
}
c.States[id] = state
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)
}
}