8 #include <StreamString.h> 9 #if defined(USE_ESP32) || defined(USE_LIBRETINY) 18 namespace web_server_base {
20 static 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());
48 this->ota_read_length_ = 0;
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;
74 this->ota_read_length_ +=
len;
76 const uint32_t now =
millis();
77 if (now - this->last_ota_progress_ > 1000) {
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);
82 ESP_LOGD(TAG,
"OTA in progress: %u bytes read", this->ota_read_length_);
84 this->last_ota_progress_ = now;
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);
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