From 3fafb3304a0c7e61b06cbb1348993cc3d65bb168 Mon Sep 17 00:00:00 2001
From: sidey79 <7968127+sidey79@users.noreply.github.com>
Date: Tue, 10 Apr 2018 23:07:56 +0200
Subject: [PATCH] HTML Pages and generation for OAT Update adapted to current
version of lib Debug output corrected at some point
---
WiFiManager.cpp | 74 +++++++++++++++++++++++--------------------------
strings_en.h | 9 +++---
2 files changed, 40 insertions(+), 43 deletions(-)
diff --git a/WiFiManager.cpp b/WiFiManager.cpp
index 91134f7..d0a9906 100644
--- a/WiFiManager.cpp
+++ b/WiFiManager.cpp
@@ -2373,76 +2373,65 @@ void WiFiManager::WiFi_autoReconnect(){
#endif
}
-
+// Called when /u is requested
void WiFiManager::handleUpdate() {
- DEBUG_WM(F("Handle update"));
- if (captivePortal()) { // If captive portal return flase to redirect back.
- return;
- }
- String page = FPSTR(HTTP_HEAD);
- page.replace("{v}", "Options");
- page += FPSTR(HTTP_SCRIPT);
- page += FPSTR(HTTP_STYLE);
- page += _customHeadElement;
- page += FPSTR(HTTP_HEAD_END);
- page += "
";
- page += _apName;
- page += "
";
- page += FPSTR(HTTP_ROOT_MAIN);
+ DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update"));
+ if (captivePortal()) return; // If captive portal redirect instead of displaying the page
+ String page = getHTTPHead(FPSTR(S_options)); // @token options
+ String str = FPSTR(HTTP_ROOT_MAIN);
+ str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
+ page += str;
+
page += FPSTR(HTTP_UPDATE);
page += FPSTR(HTTP_END);
- server->send(200, "text/html", page);
+
+ server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
+ server->send(200, FPSTR(HTTP_HEAD_CT), page);
+
}
void WiFiManager::handleUpdating(){
- if (captivePortal()) { // If captive portal return flase to redirect back.
- return;
- }
- // handler for the file upload, get's the sketch bytes, and writes
+ if (captivePortal()) return; // If captive portal redirect instead of displaying the page
+ // handler for the file upload, get's the sketch bytes, and writes
// them through the Update object
HTTPUpload& upload = server->upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.setDebugOutput(true);
WiFiUDP::stopAll();
- DEBUG_WM("Update: %s\r\n", upload.filename.c_str());
+ Serial.printf("Update: %s\r\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { // start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
- Serial.printf(".");
+ Serial.print(".");
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { // true to set the size to the current progress
- Serial.printf("Update Success: %u\r\nRebooting...\r\n", upload.totalSize);
+ Serial.printf("Updated: %u bytes\r\nRebooting...\r\n", upload.totalSize);
} else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
} else if (upload.status == UPLOAD_FILE_ABORTED) {
Update.end();
- DEBUG_WM("Update was aborted");
+ DEBUG_WM(F("<- Update was aborted"));
}
delay(0);
} // handleUpdating
void WiFiManager::handleUpdateDone() {
- DEBUG_WM(F("Handle update done"));
- if (captivePortal()) { // If captive portal return flase to redirect back.
- }
- String page = FPSTR(HTTP_HEAD);
- page.replace("{v}", "Options");
- page += FPSTR(HTTP_SCRIPT);
- page += FPSTR(HTTP_STYLE);
- page += _customHeadElement;
- page += FPSTR(HTTP_HEAD_END);
- page += "";
- page += _apName;
- page += "
";
- page += FPSTR(HTTP_ROOT_MAIN);
+ DEBUG_WM(DEBUG_VERBOSE, F("<- Handle update done"));
+ if (captivePortal()) return; // If captive portal redirect instead of displaying the page
+
+ String page = getHTTPHead(FPSTR(S_options)); // @token options
+ String str = FPSTR(HTTP_ROOT_MAIN);
+ str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
+ page += str;
+
if (Update.hasError()) {
page += FPSTR(HTTP_UPDATE_FAIL);
DEBUG_WM(F("update failed"));
@@ -2450,9 +2439,16 @@ void WiFiManager::handleUpdateDone() {
else {
page += FPSTR(HTTP_UPDATE_OK);
DEBUG_WM(F("update ok"));
+
}
page += FPSTR(HTTP_END);
- server->send(200, "text/html", page);
+
+ server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
+ server->send(200, FPSTR(HTTP_HEAD_CT), page);
+
+
delay(1000); // send page
- ESP.restart();
+ if (!Update.hasError()) {
+ ESP.restart();
+ }
}
diff --git a/strings_en.h b/strings_en.h
index 8dbe91a..05f0f3d 100644
--- a/strings_en.h
+++ b/strings_en.h
@@ -100,6 +100,8 @@ const char HTTP_HELP[] PROGMEM =
"Parameter page | "
"| /info | "
"Information page |
"
+ "| /u | "
+ "OTA Update |
"
"| /close | "
"Close the captiveportal popup,configportal will remain active |
"
"| /exit | "
@@ -215,15 +217,14 @@ const char D_HR[] PROGMEM = "--------------------";
// -----------------------------------------------------------------------------------------------
// DO NOT EDIT BELOW THIS LINE
-const uint8_t _nummenutokens = 10;
-const char * const _menutokens[10] PROGMEM = {
+const uint8_t _nummenutokens = 9;
+const char * const _menutokens[9] PROGMEM = {
"wifi",
"wifinoscan",
"info",
"param",
"close",
"restart",
- "update",
"exit",
"erase",
"sep"
@@ -242,7 +243,7 @@ const char R_close[] PROGMEM = "/close";
const char R_erase[] PROGMEM = "/erase";
const char R_status[] PROGMEM = "/status";
const char R_update[] PROGMEM = "/u";
-const char R_updatedone[] PROGMEM = "/update";
+const char R_updatedone[] PROGMEM = "/update";
//Strings