From c17b7ce6fa03b6e338764bddd71997a83dcf87dd Mon Sep 17 00:00:00 2001 From: toxuin Date: Tue, 20 Sep 2022 15:34:45 -0600 Subject: [PATCH] MQTT: fix missing birth message on reconnect --- buses/mqtt/mqtt.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buses/mqtt/mqtt.go b/buses/mqtt/mqtt.go index 0304458..1e5e0d1 100644 --- a/buses/mqtt/mqtt.go +++ b/buses/mqtt/mqtt.go @@ -31,6 +31,7 @@ func (mqtt *Bus) Initialize(config config.MqttConfig) { mqttOpts.OnConnect = func(client MQTT.Client) { fmt.Printf("MQTT: CONNECTED TO %s\n", config.Server) + mqtt.SendMessage(config.TopicRoot+"/alarmserver", `{ "status": "up" }`) } mqttOpts.SetConnectionLostHandler(func(client MQTT.Client, err error) { @@ -50,8 +51,6 @@ func (mqtt *Bus) Initialize(config config.MqttConfig) { if token := mqtt.client.Connect(); token.Wait() && token.Error() != nil { panic(token.Error()) } - - mqtt.SendMessage(config.TopicRoot+"/alarmserver", `{ "status": "up" }`) } func (mqtt *Bus) SendMessage(topic string, payload interface{}) {