8#include <StreamString.h>
9#if defined(USE_ESP32) || defined(USE_LIBRETINY)
18namespace web_server_base {
20static const char *
const TAG =
"web_server_base";
30 this->
server_->addHandler(handler);
37 Update.printError(ss);
38 ESP_LOGW(TAG,
"OTA Update failed! Error: %s", ss.c_str());
43 uint8_t *data,
size_t len,
bool final) {
47 ESP_LOGI(TAG,
"OTA Update Start: %s", filename.c_str());
50 Update.runAsync(
true);
52 success = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
54#if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_LIBRETINY)
55 if (Update.isRunning()) {
58 success = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
64 }
else if (Update.hasError()) {
69 success = Update.write(data,
len) ==
len;
76 const uint32_t now =
millis();
78 if (request->contentLength() != 0) {
79 float percentage = (this->
ota_read_length_ * 100.0f) / request->contentLength();
80 ESP_LOGD(TAG,
"OTA in progress: %0.1f%%", percentage);
88 if (Update.end(
true)) {
89 ESP_LOGI(TAG,
"OTA update successful!");
99 AsyncWebServerResponse *response;
100 if (!Update.hasError()) {
101 response = request->beginResponse(200,
"text/plain",
"Update Successful!");
104 ss.print(
"Update Failed: ");
105 Update.printError(ss);
106 response = request->beginResponse(200,
"text/plain", ss);
108 response->addHeader(
"Connection",
"close");
109 request->send(response);
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
uint32_t ota_read_length_
void handleUpload(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) override
uint32_t last_ota_progress_
void handleRequest(AsyncWebServerRequest *request) override
float get_setup_priority() const override
void add_handler(AsyncWebHandler *handler)
friend class OTARequestHandler
std::vector< AsyncWebHandler * > handlers_
std::shared_ptr< AsyncWebServer > server_
internal::Credentials credentials_
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.