Chris Mullins hace 8 años
padre
commit
86d9f0ab81
Se han modificado 2 ficheros con 13 adiciones y 6 borrados
  1. 11 6
      lib/WebServer/MiLightHttpServer.cpp
  2. 2 0
      lib/WebServer/MiLightHttpServer.h

+ 11 - 6
lib/WebServer/MiLightHttpServer.cpp

@@ -64,12 +64,17 @@ void MiLightHttpServer::handleDownloadUpdate(const UrlTokenBindings* bindings) {
   if (component.equalsIgnoreCase("web")) {
     Serial.println("Attempting to update web UI...");
     
-    const bool result = downloader->downloadFile(
-      MILIGHT_GITHUB_USER,
-      MILIGHT_GITHUB_REPO,
-      MILIGHT_REPO_WEB_PATH,
-      WEB_INDEX_FILENAME
-    );
+    bool result = false;
+    size_t tries = 0;
+    
+    while (!result && tries++ <= MAX_DOWNLOAD_ATTEMPTS) {
+      result = downloader->downloadFile(
+        MILIGHT_GITHUB_USER,
+        MILIGHT_GITHUB_REPO,
+        MILIGHT_REPO_WEB_PATH,
+        WEB_INDEX_FILENAME
+      );
+    }
     
     Serial.println("Download complete!");
     

+ 2 - 0
lib/WebServer/MiLightHttpServer.h

@@ -5,6 +5,8 @@
 #ifndef _MILIGHT_HTTP_SERVER
 #define _MILIGHT_HTTP_SERVER 
 
+#define MAX_DOWNLOAD_ATTEMPTS 3
+
 typedef std::function<void(void)> SettingsSavedHandler;
 
 class MiLightHttpServer {