diff options
| -rw-r--r-- | mqtt.go | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -15,7 +15,6 @@ const ( RETAINED = true MQTT_CONNECT_TIMEOUT = 1 * time.Second MQTT_DISCONNECT_TIMEOUT_US = 500 - MQTT_RECONNECT_PERIOD = 2 * time.Second ) type MQTTMessage struct { @@ -30,6 +29,9 @@ func MQTTRun(tx chan MQTTMessage) { opts.SetCleanSession(true) opts.SetOnConnectHandler(MQTTOnConnectHandler) opts.SetConnectionLostHandler(MQTTConnectionLostHandler) + opts.SetAutoReconnect(true) + opts.SetConnectRetry(true) + opts.SetConnectTimeout(MQTT_CONNECT_TIMEOUT) client := mqtt.NewClient(opts) @@ -37,8 +39,7 @@ func MQTTRun(tx chan MQTTMessage) { success := token.WaitTimeout(MQTT_CONNECT_TIMEOUT) if !success { - log.Printf("Timed out after %v.", MQTT_CONNECT_TIMEOUT) - return + log.Fatal("Initial connection to MQTT broker failed.") } defer client.Disconnect(MQTT_DISCONNECT_TIMEOUT_US) |
