From 6c920f59a20849deb882f60a3eab42b069914a7e Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 27 Mar 2026 14:28:51 +0100 Subject: Move version string to VERSION.txt This new files can easily be included into Meson and Go. Passing it from Meson to Go or vice versa is not that easy. Thus the version string is now maintained in a dedicated file. --- VERSION.txt | 1 + meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 VERSION.txt diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..0d4d124 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +0.1.0-dev diff --git a/meson.build b/meson.build index 0738894..52a7f19 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'sia-server', - version : '0.1.0-dev', + version : files('VERSION.txt'), ) go = find_program('go', required : true) -- cgit v1.3 From 5b64946098839d3df679bdc7ef1c4cc4e692323a Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 27 Mar 2026 14:30:51 +0100 Subject: Add version to start / stop log messages This makes it more transparent which version is executed. --- main.go | 4 ++-- meson.build | 1 + version.go | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 version.go diff --git a/main.go b/main.go index ef59574..037b8de 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,8 @@ func main() { flags := Flags{} flags.FromArgs() - log.Println("+++ Started Sia server +++") - defer log.Println("--- Stopped Sia server ---") + log.Printf("+++ Started Sia server version %s +++", Version()) + defer log.Printf("--- Stopped Sia server version %s ---", Version()) config := GetStartupConfig(flags.ConfigPath) diff --git a/meson.build b/meson.build index 52a7f19..f830b42 100644 --- a/meson.build +++ b/meson.build @@ -18,6 +18,7 @@ changelog = fs.copyfile(meson.current_source_dir() / 'CHANGELOG.md') sia_server_linux_amd64 = custom_target( input : [ meson.current_source_dir() / 'main.go', + meson.current_source_dir() / 'version.go', meson.current_source_dir() / 'cache.go', meson.current_source_dir() / 'mqtt.go', meson.current_source_dir() / 'homematic.go', diff --git a/version.go b/version.go new file mode 100644 index 0000000..91d58bc --- /dev/null +++ b/version.go @@ -0,0 +1,13 @@ +package main + +import ( + _ "embed" + "strings" +) + +//go:embed VERSION.txt +var rawVersion string + +func Version() string { + return strings.TrimSuffix(rawVersion, "\n") +} -- cgit v1.3 From 3158a0a132d6af4de78c9be90e45834350cfd414 Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 27 Mar 2026 14:39:33 +0100 Subject: 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. --- README.md | 11 +++++++++++ mqtt.go | 2 ++ 2 files changed, 13 insertions(+) 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 string of the publishing Sia server without newline + ### `/contact//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 -- cgit v1.3