コード例 #1
0
func reconnectMqttBroker(client *MQTT.MqttClient, opts *MQTT.ClientOptions) {
	if mqttConnected == false {
		//log.Println("Attempting reconnect . . .")
		// Always reconnect with cleansession false
		opts.SetCleanSession(false)
		_, err := client.Start()
		if err != nil {
			time.Sleep(1 * time.Second)
		} else {
			log.Info("Reconnected")
			mqttConnected = true
		}
	}
}