maintenance mode (code sanitization)

This commit is contained in:
cyberman54 2021-03-06 19:24:42 +01:00
parent 6775faa87d
commit e54c386e9e

View File

@ -128,45 +128,60 @@ void start_boot_menu(void) {
server.send(200, "text/html", serverIndex); server.send(200, "text/html", serverIndex);
}); });
server.onNotFound([&server, &loginMenu]() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", loginMenu);
});
// handling uploading firmware file // handling uploading firmware file
server.on( server.on(
"/update", HTTP_POST, "/update", HTTP_POST,
[&server]() { [&server]() {
server.sendHeader("Connection", "close"); server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
RTC_runmode = Update.hasError() ? RUNMODE_NORMAL : RUNMODE_POWERCYCLE;
WiFi.disconnect(true); WiFi.disconnect(true);
if (!Update.hasError())
RTC_runmode = RUNMODE_POWERCYCLE;
esp_restart(); esp_restart();
}, },
[&server, &timer]() { [&server, &timer]() {
bool success = false;
HTTPUpload &upload = server.upload(); HTTPUpload &upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
ESP_LOGI(TAG, "Update: %s\n", upload.filename.c_str()); switch (upload.status) {
#if (HAS_LED != NOT_A_PIN)
#ifndef LED_ACTIVE_LOW case UPLOAD_FILE_START:
if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH, HAS_LED, HIGH)) { // start file transfer
#else ESP_LOGI(TAG, "Uploading %s", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH, HAS_LED, LOW)) { success = Update.begin();
#endif break;
#else
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { case UPLOAD_FILE_WRITE:
#endif
ESP_LOGE(TAG, "Error: %s", Update.errorString());
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
// flashing firmware to ESP // flashing firmware to ESP
if (Update.write(upload.buf, upload.currentSize) != success = (Update.write(upload.buf, upload.currentSize) ==
upload.currentSize) { upload.currentSize);
ESP_LOGE(TAG, "Error: %s", Update.errorString()); break;
}
} else if (upload.status == UPLOAD_FILE_END) { case UPLOAD_FILE_END:
if (Update.end( success = Update.end(true); // true to set the size to the current
true)) { // true to set the size to the current progress if (success)
ESP_LOGI(TAG, "Update finished, %u bytes written", ESP_LOGI(TAG, "Upload finished, %u bytes written",
upload.totalSize); upload.totalSize);
} else { else
ESP_LOGE(TAG, "Update failed, status=%d", upload.status); ESP_LOGE(TAG, "Upload failed, status=%d", upload.status);
} break;
case UPLOAD_FILE_ABORTED:
default:
break;
} // switch
if (!success) {
ESP_LOGE(TAG, "Error: %s", Update.errorString());
WiFi.disconnect(true);
esp_restart();
} }
}); });