mirror of
https://github.com/esphome/esphome.git
synced 2025-10-03 18:42:23 +01:00
web server esp idf suppport (#3500)
* initial web_server_idf implementation * initial web_server_idf implementation * fix lint errors * fix lint errors * add captive_portal support * fix lint errors * fix lint errors * add url decode * Increase the max supported size of headers section in HTTP request * add ota support * add mulipart form data support (ota required) * make linter happy * make linter happy * make linter happy * fix review marks * add DefaultHeaders support * add DefaultHeaders support * unify file names * using std::isnan * parse multipart requests only when ota enabled * parse multipart requests only when ota enabled * parse multipart requests only when ota enabled * parse multipart requests only when ota enabled * parse multipart requests only when ota enabled * drop multipart request support * drop multipart request support * drop multipart request support * OTA is disabled by default * fail when OTA enabled on IDF framework * changing file permissions to remove execute bit * return back PGM_P and strncpy_P macro * temp web_server fix to be compat with 2022.12 * fix config handling w/o web_server * fix compilation with "local" * fully remove all idf ota * merge with esphome 2023.6 * add core/hal to web_server_base * Update esphome/components/web_server_base/__init__.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Update __init__.py * Update __init__.py --------- Co-authored-by: Keith Burzinski <kbx81x@gmail.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "web_server_base.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include <StreamString.h>
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
#include <StreamString.h>
|
||||
#ifdef USE_ESP32
|
||||
#include <Update.h>
|
||||
#endif
|
||||
#ifdef USE_ESP8266
|
||||
#include <Updater.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace web_server_base {
|
||||
@@ -24,18 +25,22 @@ void WebServerBase::add_handler(AsyncWebHandler *handler) {
|
||||
handler = new internal::AuthMiddlewareHandler(handler, &credentials_);
|
||||
}
|
||||
this->handlers_.push_back(handler);
|
||||
if (this->server_ != nullptr)
|
||||
if (this->server_ != nullptr) {
|
||||
this->server_->addHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
void report_ota_error() {
|
||||
#ifdef USE_ARDUINO
|
||||
StreamString ss;
|
||||
Update.printError(ss);
|
||||
ESP_LOGW(TAG, "OTA Update failed! Error: %s", ss.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const String &filename, size_t index,
|
||||
uint8_t *data, size_t len, bool final) {
|
||||
#ifdef USE_ARDUINO
|
||||
bool success;
|
||||
if (index == 0) {
|
||||
ESP_LOGI(TAG, "OTA Update Start: %s", filename.c_str());
|
||||
@@ -45,9 +50,10 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
||||
// NOLINTNEXTLINE(readability-static-accessed-through-instance)
|
||||
success = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
|
||||
#endif
|
||||
#ifdef USE_ESP32
|
||||
if (Update.isRunning())
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
if (Update.isRunning()) {
|
||||
Update.abort();
|
||||
}
|
||||
success = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
|
||||
#endif
|
||||
if (!success) {
|
||||
@@ -85,8 +91,10 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
||||
report_ota_error();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void OTARequestHandler::handleRequest(AsyncWebServerRequest *request) {
|
||||
#ifdef USE_ARDUINO
|
||||
AsyncWebServerResponse *response;
|
||||
if (!Update.hasError()) {
|
||||
response = request->beginResponse(200, "text/plain", "Update Successful!");
|
||||
@@ -98,10 +106,13 @@ void OTARequestHandler::handleRequest(AsyncWebServerRequest *request) {
|
||||
}
|
||||
response->addHeader("Connection", "close");
|
||||
request->send(response);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebServerBase::add_ota_handler() {
|
||||
#ifdef USE_ARDUINO
|
||||
this->add_handler(new OTARequestHandler(this)); // NOLINT
|
||||
#endif
|
||||
}
|
||||
float WebServerBase::get_setup_priority() const {
|
||||
// Before WiFi (captive portal)
|
||||
@@ -110,5 +121,3 @@ float WebServerBase::get_setup_priority() const {
|
||||
|
||||
} // namespace web_server_base
|
||||
} // namespace esphome
|
||||
|
||||
#endif // USE_ARDUINO
|
||||
|
Reference in New Issue
Block a user