summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2026-03-27 14:39:33 +0100
committerxengineering <me@xengineering.eu>2026-03-27 14:43:56 +0100
commit3158a0a132d6af4de78c9be90e45834350cfd414 (patch)
treeb19a858d67cab60bf0f4be400d332e972aa6a426
parent5b64946098839d3df679bdc7ef1c4cc4e692323a (diff)
downloadsia-server-3158a0a132d6af4de78c9be90e45834350cfd414.tar
sia-server-3158a0a132d6af4de78c9be90e45834350cfd414.tar.zst
sia-server-3158a0a132d6af4de78c9be90e45834350cfd414.zip
Add server version publishing
This makes it possible that the client adapts it's behaviour easily to the server version making support of breaking API changes during early development and debugging easier.
-rw-r--r--README.md11
-rw-r--r--mqtt.go2
2 files changed, 13 insertions, 0 deletions
diff --git a/README.md b/README.md
index e0555a0..845a068 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,17 @@ For all terms not explained here see the [MQTT version 3.1.1 documentation][9].
- `good`: Sia server is connected to MQTT broker
- `bad`: Sia server is disconnected from MQTT broker
+### `/server/version`
+
+- description: Sia server version string from VERSION.txt
+- direction: Sia server to client
+- Quality of Service: QoS 1 (at least once)
+- retained: yes
+- receives will message: no
+- topic parameters: none
+- payloads:
+ - `<version>`: version string of the publishing Sia server without newline
+
### `/contact/<id>/state`
- description: Indicates state of Homematic IP SWDO-2 contacts
diff --git a/mqtt.go b/mqtt.go
index acd0108..26b6444 100644
--- a/mqtt.go
+++ b/mqtt.go
@@ -46,6 +46,7 @@ func (m MQTTMessage) String() string {
func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) {
mqttServerHealthTopic = fmt.Sprintf("%s/server/health", config.TopicPrefix)
+ mqttServerVersionTopic := fmt.Sprintf("%s/server/version", config.TopicPrefix)
opts := mqtt.NewClientOptions()
opts.AddBroker(config.Broker)
@@ -54,6 +55,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) {
opts.SetOnConnectHandler(func(c mqtt.Client) {
log.Printf("Connected to MQTT broker.")
c.Publish(mqttServerHealthTopic, QoS1, true, []byte(`good`))
+ c.Publish(mqttServerVersionTopic, QoS1, true, []byte(Version()))
for _, route := range routes {
topic := config.TopicPrefix + "/" + route.Topic