Skip to content

Commit

Permalink
MQTT: fix missing birth message on reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
toxuin committed Sep 20, 2022
1 parent a486ef5 commit c17b7ce
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions buses/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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{}) {
Expand Down

0 comments on commit c17b7ce

Please sign in to comment.