7 #include <StreamString.h> 8 #if defined(USE_ESP32) || defined(USE_LIBRETINY) 17 namespace web_server_base {
19 static const char *
const TAG =
"web_server_base";
29 this->
server_->addHandler(handler);
36 Update.printError(ss);
37 ESP_LOGW(TAG,
"OTA Update failed! Error: %s", ss.c_str());
42 uint8_t *data,
size_t len,
bool final) {
46 ESP_LOGI(TAG,
"OTA Update Start: %s", filename.c_str());
47 this->ota_read_length_ = 0;
49 Update.runAsync(
true);
51 success = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
53 #if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_LIBRETINY) 54 if (Update.isRunning()) {
57 success = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
63 }
else if (Update.hasError()) {
68 success = Update.write(data, len) ==
len;
73 this->ota_read_length_ +=
len;
75 const uint32_t now =
millis();
76 if (now - this->last_ota_progress_ > 1000) {
77 if (request->contentLength() != 0) {
78 float percentage = (this->ota_read_length_ * 100.0f) / request->contentLength();
79 ESP_LOGD(TAG,
"OTA in progress: %0.1f%%", percentage);
81 ESP_LOGD(TAG,
"OTA in progress: %u bytes read", this->ota_read_length_);
83 this->last_ota_progress_ = now;
87 if (Update.end(
true)) {
88 ESP_LOGI(TAG,
"OTA update successful!");
98 AsyncWebServerResponse *response;
99 if (!Update.hasError()) {
100 response = request->beginResponse(200,
"text/plain",
"Update Successful!");
103 ss.print(
"Update Failed: ");
104 Update.printError(ss);
105 response = request->beginResponse(200,
"text/plain", ss);
107 response->addHeader(
"Connection",
"close");
108 request->send(response);
std::shared_ptr< AsyncWebServer > server_
void handleUpload(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) override
uint32_t IRAM_ATTR HOT millis()
void add_handler(AsyncWebHandler *handler)
float get_setup_priority() const override
Application App
Global storage of Application pointer - only one Application can exist.
internal::Credentials credentials_
void handleRequest(AsyncWebServerRequest *request) override
std::vector< AsyncWebHandler * > handlers_
Implementation of SPI Controller mode.
friend class OTARequestHandler