From 0913422296410eebcc95f5bd4a209354cacca3d2 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Sun, 17 Apr 2022 02:44:06 +0100 Subject: [PATCH] Add configurable mqtt port --- config.toml.example | 1 + main.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config.toml.example b/config.toml.example index 5dfb0bb..4b64a5d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,5 +1,6 @@ [mqtt] Host = "192.168.0.123" +Port = 1883 [[targets]] Host = "192.168.0.222" diff --git a/main.go b/main.go index 6273184..a7663f7 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ type targetConfig struct { type config struct { MQTT struct { Host string + Port uint16 } Targets []targetConfig } @@ -206,7 +207,9 @@ func main() { conf, err := parseConfig(*configpath) check(err) - mqttOpts := mqtt.NewClientOptions().AddBroker(fmt.Sprintf("tcp://%s:1883", conf.MQTT.Host)).SetClientID("apc2mqtt") + mqttOpts := mqtt.NewClientOptions().AddBroker( + fmt.Sprintf("tcp://%s:%d", conf.MQTT.Host, conf.MQTT.Port), + ).SetClientID("apc2mqtt") mqttClient := mqtt.NewClient(mqttOpts) if token := mqttClient.Connect(); token.Wait() && token.Error() != nil { panic(token.Error())