Skip to content

Commit

Permalink
Merge pull request #13 from jamesfowkes/master
Browse files Browse the repository at this point in the history
Add ability to set custom HTML
  • Loading branch information
scottchiefbaker authored Sep 28, 2020
2 parents 8bd9a8c + dfbaf8e commit c98c830
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/WebOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ long WebOTA::max_sketch_size() {
}

// R Macro string literal https://en.cppreference.com/w/cpp/language/string_literal
const char ota_html[] PROGMEM = "<h1>WebOTA Version: " WEBOTA_VERSION "</h1>"
R"!^!(
const char ota_version_html[] PROGMEM = "<h1>WebOTA Version: " WEBOTA_VERSION "</h1>";

const char ota_upload_form[] PROGMEM = R"!^!(
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
<input type="file" name="update" id="file">
Expand Down Expand Up @@ -150,7 +151,15 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) {

// Upload firmware page
server->on(path, HTTP_GET, [server,this]() {
server->send_P(200, "text/html", ota_html);
String html = "";
if (this->custom_html != NULL) {
html += this->custom_html;
} else {
html += ota_version_html;
}

html += ota_upload_form;
server->send_P(200, "text/html", html.c_str());
});

// Handling uploading firmware file
Expand Down Expand Up @@ -211,6 +220,9 @@ void WebOTA::delay(unsigned int ms) {
}
}

void WebOTA::set_custom_html(char const * const html) {
this->custom_html = html;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

Expand Down
5 changes: 4 additions & 1 deletion src/WebOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ class WebOTA {
#endif

int handle();

void set_custom_html(char const * const html);

private:
bool init_has_run;

char const * custom_html = NULL;
String get_ota_html();
long max_sketch_size();
};
Expand Down

0 comments on commit c98c830

Please sign in to comment.