Przeglądaj źródła

Add endpoint to proxy latest release info from GitHub API

Chris Mullins 8 lat temu
rodzic
commit
ed87922cd0

+ 1 - 1
lib/GithubClient/GithubClient.h

@@ -6,7 +6,7 @@
 
 #define GITHUB_CLIENT_BUFFER_SIZE 32
 
-#define GITHUB_RAW_FINGERPRINT "21 99 13 84 63 72 17 13 B9 ED 0E 8F 00 A5 9B 73 0D D0 56 58"
+#define GITHUB_RAW_FINGERPRINT "CC AA 48 48 66 46 0E 91 53 2C 9C 7C 23 2A B1 74 4D 29 9D 33"
 #define GITHUB_RAW_DOMAIN "raw.githubusercontent.com"
 
 #define GITHUB_API_FINGERPRINT "35 85 74 EF 67 35 A7 CE 40 69 50 F3 C0 F6 80 CF 80 3B 2E 19"

+ 21 - 2
lib/WebServer/MiLightHttpServer.cpp

@@ -26,7 +26,21 @@ void MiLightHttpServer::begin() {
     [this](){
       server.sendHeader("Connection", "close");
       server.sendHeader("Access-Control-Allow-Origin", "*");
-      server.send(200, "text/plain", (Update.hasError())?"FAIL":"OK");
+      
+      if (Update.hasError()) {
+        server.send_P(
+          500,
+          "text/plain",
+          PSTR("Failed updating firmware. Check serial logs for more information. You may need to re-flash the device.")
+        );
+      } else {
+        server.send_P(
+          200,
+          "text/plain",
+          PSTR("Success. Device will now reboot.")
+        );
+      }
+      
       ESP.restart();
     },
     [this](){
@@ -76,6 +90,11 @@ void MiLightHttpServer::handleGetLatestRelease() {
     Serial.println(F("Failed download attempt."));
   }
   
+  if (!SPIFFS.exists(fsPath)) {
+    server.send_P(500, "text/plain", PSTR("Failed to stream API request from GitHub. Check Serial logs for more information."));
+    return;
+  }
+  
   File file = SPIFFS.open(fsPath, "r");
   server.streamFile(file, "application/json");
   SPIFFS.remove(fsPath);
@@ -223,7 +242,7 @@ ESP8266WebServer::THandlerFunction MiLightHttpServer::handleUpdateFile(const cha
       updateFile = SPIFFS.open(filename, "w");
     } else if(upload.status == UPLOAD_FILE_WRITE){
       if (updateFile.write(upload.buf, upload.currentSize) != upload.currentSize) {
-        Serial.println("Error updating web file");
+        Serial.println(F("Error updating web file"));
       }
     } else if (upload.status == UPLOAD_FILE_END) {
       updateFile.close();