 
 
 
-void mqttReconnect() {
-  // Loop until we're reconnected
-  while (!mqttClient.connected()) {
-    Serial.print("Attempting MQTT connection...");
-    // Attempt to connect
-    if (mqttClient.connect(clientID.c_str())) {
-      Serial.println("connected");
-      for (int i = 0; i < subscriptions_length; i++ )
-      {
-        mqttClient.subscribe(subscriptions[i].c_str());
-        #if DEBUG
-          Serial.print("Subscribing to: ");
-          Serial.println(subscriptions[i]);
-        #endif
-      }
-    } else {
-      Serial.print("failed, rc=");
-      Serial.print(mqttClient.state());
-      Serial.println(" try again in 5 seconds");
-      // Wait 5 seconds before retrying
-      delay(5000);
+void mqttTryReconnect() {  
+  Serial.print("Attempting MQTT connection...");
+  // Attempt to connect
+  if (mqttClient.connect(clientID.c_str())) {
+    Serial.println("connected");
+    for (int i = 0; i < subscriptions_length; i++ )
+    {
+      mqttClient.subscribe(subscriptions[i].c_str());
+      #if DEBUG
+        Serial.print("Subscribing to: ");
+        Serial.println(subscriptions[i]);
+      #endif
     }
+  } else {
+    Serial.print("failed, rc=");
+    Serial.print(mqttClient.state());
+    Serial.println(" try again in 5 seconds");
+    // Wait 5 seconds before retrying
+    delay(5000);
+    
   }
 }
 



void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();

  setupOTA();
  mqttClient.setServer(mqtt_server, 1883);
  mqttClient.setCallback(callback);
  mqttTryReconnect();
  registration();
}


void loop() {
  while(!mqttClient.connected()) {
    mqttTryReconnect();
    ArduinoOTA.handle();
  }
  mqttClient.loop();
  fadeLoop();
