6 #include <StreamString.h> 16 namespace web_server_base {
18 static const char *
const TAG =
"web_server_base";
28 this->
server_->addHandler(handler);
33 Update.printError(ss);
34 ESP_LOGW(TAG,
"OTA Update failed! Error: %s", ss.c_str());
38 uint8_t *data,
size_t len,
bool final) {
41 ESP_LOGI(TAG,
"OTA Update Start: %s", filename.c_str());
42 this->ota_read_length_ = 0;
44 Update.runAsync(
true);
46 success = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
49 if (Update.isRunning())
51 success = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
57 }
else if (Update.hasError()) {
62 success = Update.write(data, len) ==
len;
67 this->ota_read_length_ +=
len;
69 const uint32_t now =
millis();
70 if (now - this->last_ota_progress_ > 1000) {
71 if (request->contentLength() != 0) {
72 float percentage = (this->ota_read_length_ * 100.0f) / request->contentLength();
73 ESP_LOGD(TAG,
"OTA in progress: %0.1f%%", percentage);
75 ESP_LOGD(TAG,
"OTA in progress: %u bytes read", this->ota_read_length_);
77 this->last_ota_progress_ = now;
81 if (Update.end(
true)) {
82 ESP_LOGI(TAG,
"OTA update successful!");
90 AsyncWebServerResponse *response;
91 if (!Update.hasError()) {
92 response = request->beginResponse(200,
"text/plain",
"Update Successful!");
95 ss.print(
"Update Failed: ");
96 Update.printError(ss);
97 response = request->beginResponse(200,
"text/plain", ss);
99 response->addHeader(
"Connection",
"close");
100 request->send(response);
114 #endif // USE_ARDUINO 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_
friend class OTARequestHandler