File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,12 @@ func (mqc *MQTTConnection) Connect(options ConnectionOptions) error {
2929 compressed := snappy .Encode (nil , []byte (options .OnDisconnect .Body ))
3030 mqttOpts .SetWill (options .OnDisconnect .Topic , string (compressed ), 1 , false )
3131 }
32+ if options .EventsHandler != nil && options .AutoReconnect == true {
33+ mqttOpts .OnConnect = func (c * mqtt.Client ) {
34+ mqc .conn = c
35+ mqc .options .EventsHandler (mqc , ConnectedEvent )
36+ }
37+ }
3238 mqc .backoff = NewBackoff ()
3339 mqc .conn = mqtt .NewClient (mqttOpts )
3440 for {
@@ -41,7 +47,7 @@ func (mqc *MQTTConnection) Connect(options ConnectionOptions) error {
4147 }
4248 }
4349 mqc .options = options
44- if mqc .options .EventsHandler != nil {
50+ if mqc .options .EventsHandler != nil && mqc . options . AutoReconnect != true {
4551 mqc .options .EventsHandler (mqc , ConnectedEvent )
4652 }
4753 return nil
@@ -77,7 +83,7 @@ func (mqc *MQTTConnection) Subscribe(topic string, handler SubscriptionHandler)
7783 return token .Error ()
7884}
7985
80- func (mqc * MQTTConnection ) disconnected (cilent * mqtt.Client , err error ) {
86+ func (mqc * MQTTConnection ) disconnected (client * mqtt.Client , err error ) {
8187 log .Errorf ("MQTT connection failed: %s." , err )
8288 for {
8389 if token := mqc .conn .Connect (); token .Wait () && token .Error () != nil {
Original file line number Diff line number Diff line change @@ -147,9 +147,10 @@ func (r *cogRelay) handleBusEvents(conn bus.Connection, event bus.Event) {
147147 }
148148 if r .catalog .Len () > 0 {
149149 r .catalog .Reconnected ()
150+ } else {
151+ log .Info ("Loading bundle catalog." )
152+ r .requestBundles ()
150153 }
151- log .Info ("Loading bundle catalog." )
152- r .requestBundles ()
153154 }
154155}
155156
You can’t perform that action at this time.
0 commit comments