diff --git a/src/WebOTA.cpp b/src/WebOTA.cpp index 4a8ee2c..9b54b07 100644 --- a/src/WebOTA.cpp +++ b/src/WebOTA.cpp @@ -1,7 +1,8 @@ // Arduino build process info: https://github.com/arduino/Arduino/wiki/Build-Process -const char *WEBOTA_VERSION = "0.1.5"; -bool INIT_RUN = false; +#define WEBOTA_VERSION "0.1.5" + +bool INIT_RUN = false; #include "WebOTA.h" #include @@ -74,6 +75,66 @@ long WebOTA::max_sketch_size() { return ret; } +// R Macro string literal https://en.cppreference.com/w/cpp/language/string_literal +const char ota_html[] PROGMEM = "

WebOTA Version: " WEBOTA_VERSION "

" +R"!^!( + +
+ + +
+ +
+ +
+ +)!^!"; + + #ifdef ESP8266 int WebOTA::add_http_routes(ESP8266WebServer *server, const char *path) { #endif @@ -87,8 +148,7 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) { // Upload firmware page server->on(path, HTTP_GET, [server,this]() { - String ota_html = this->get_ota_html(); - server->send(200, "text/html", ota_html.c_str()); + server->send_P(200, "text/html", ota_html); }); // Handling uploading firmware file @@ -135,71 +195,6 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) { server->begin(); } -// Get the HTML for the sketch upload page -String WebOTA::get_ota_html() { - String ota_html = ""; - - ota_html += "

WebOTA Version: " + (String)WEBOTA_VERSION + "

\n"; - ota_html += "\n"; - ota_html += "
\n"; - ota_html += " \n"; - ota_html += " \n"; - ota_html += "
\n"; - ota_html += "\n"; - ota_html += "
Max sketch size: " + (String)this->max_sketch_size() + "
\n"; - ota_html += "
\n"; - ota_html += "
\n"; - ota_html += "
\n"; - ota_html += "\n"; - ota_html += "\n"; - - return ota_html; -} - // If the MCU is in a delay() it cannot respond to HTTP OTA requests // We do a "fake" looping delay and listen for incoming HTTP requests while waiting void WebOTA::delay(int ms) {