     Serial.println("Free heap memory: " + String(ESP.getFreeHeap()) + " Bytes.");
     Serial.println("Chip speed:       " + String(ESP.getFlashChipSpeed()) + " Hz.");
 
+    HandleUpdate();
+
+    char deviceId[21];
+    strcpy(deviceId, "ESP");
+    strcat(deviceId, MAC_char);
+
+    simplesample_http_run(A0, connectionString, deviceId);
+    
+    updateUrl = simplesample_http_getUrl();
+    if (updateUrl != 0)
+    {
+        SaveUpdateFlag(true);
+        ESP.restart();
+    }
+}
+
+void HandleUpdate()
+{
     if (updateUrl != 0)
     {
         t_httpUpdate_return ret = ESPhttpUpdate.update(updateUrl);

            Serial.println("HTTP_UPDATE_OK");
            break;
        }
    }

    char deviceId[21];
    strcpy(deviceId,"ESP");
    strcat(deviceId, MAC_char);
    
    simplesample_http_run(A0, connectionString, deviceId);
    updateUrl = simplesample_http_getUrl();
    if (updateUrl != 0)
    {
        SaveUpdateFlag(true);
        ESP.restart();
    }
}


        digitalWrite(LED_SIGNAL, HIGH);
        SaveUpdateFlag(false);
        UpdateIt();
    }
    else
    {
        digitalWrite(LED_SIGNAL, LOW);
    }
