From def93b8afbd0145df3f88b9727e3233785d8ddb4 Mon Sep 17 00:00:00 2001 From: Peter Banik Date: Wed, 5 Apr 2023 17:01:21 +0200 Subject: [PATCH] Fixed mqtt connection --- pwsmqttdispatcher/config.yaml | 2 +- pwsmqttdispatcher/src/main.go | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pwsmqttdispatcher/config.yaml b/pwsmqttdispatcher/config.yaml index f27f110..5d49e8c 100644 --- a/pwsmqttdispatcher/config.yaml +++ b/pwsmqttdispatcher/config.yaml @@ -1,6 +1,6 @@ # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config name: PWS to MQTT dispatcher addon -version: "0.1.15" +version: "0.1.16" slug: pwsmqttdispatcher description: Push weather station (PWS) data to MQTT url: "https://github.com/peterzen/haas-pws-mqtt-addon/tree/main/pwsmqttdispatcher" diff --git a/pwsmqttdispatcher/src/main.go b/pwsmqttdispatcher/src/main.go index 2ccb647..42b4b1c 100644 --- a/pwsmqttdispatcher/src/main.go +++ b/pwsmqttdispatcher/src/main.go @@ -141,7 +141,13 @@ func parseHtml(doc *goquery.Document) []byte { return jsonData } -func newMqttClient() mqtt.Client { +func main() { + + debugEnabled = false + + if os.Getenv("DEBUG_ENABLED") == "true" { + debugEnabled = true + } pwsIp = os.Getenv("PWS_IP") if pwsIp == "" { @@ -194,18 +200,6 @@ func newMqttClient() mqtt.Client { defer client.Disconnect(250) log.Printf("Connected to MQTT broker %s\n", opts.Servers[0]) - return client -} - -func main() { - - debugEnabled = false - - if os.Getenv("DEBUG_ENABLED") == "true" { - debugEnabled = true - } - - client := newMqttClient() mqttTopic := os.Getenv(("MQTT_TOPIC")) if mqttTopic == "" { @@ -221,7 +215,7 @@ func main() { if weatherData != nil { token := client.Publish(mqttTopic, 0, false, weatherData) if debugEnabled { - log.Printf("Published data to MQTT topic\n") + log.Printf("Published data to #%s\n", mqttTopic) } token.Wait() if debugEnabled {