mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
fixes
This commit is contained in:
parent
101901fdb8
commit
f8cb44fb3c
@ -1929,6 +1929,15 @@ void WebServer::handleRequest(AsyncWebServerRequest *request) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
if (request->url() == "/events") {
|
||||
// Events are not supported on ESP-IDF yet
|
||||
// Return a proper response to avoid "uri handler execution failed" warnings
|
||||
request->send(501, "text/plain", "Server-Sent Events not supported on ESP-IDF");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_WEBSERVER_CSS_INCLUDE
|
||||
if (request->url() == "/0.css") {
|
||||
this->handle_css_request(request);
|
||||
@ -2085,6 +2094,10 @@ void WebServer::handleRequest(AsyncWebServerRequest *request) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// No matching handler found - send 404
|
||||
ESP_LOGD(TAG, "Request for unknown URL: %s", request->url().c_str());
|
||||
request->send(404, "text/plain", "Not Found");
|
||||
}
|
||||
|
||||
bool WebServer::isRequestHandlerTrivial() const { return false; }
|
||||
|
@ -44,7 +44,17 @@ void OTARequestHandler::report_ota_progress_(AsyncWebServerRequest *request) {
|
||||
|
||||
void OTARequestHandler::schedule_ota_reboot_() {
|
||||
ESP_LOGI(TAG, "OTA update successful!");
|
||||
this->parent_->set_timeout(100, []() { App.safe_reboot(); });
|
||||
this->parent_->set_timeout(100, [this]() {
|
||||
ESP_LOGI(TAG, "Performing OTA reboot now");
|
||||
#ifdef USE_ESP_IDF
|
||||
// Stop the web server before rebooting to avoid "uri handler execution failed" warnings
|
||||
if (this->parent_->get_server()) {
|
||||
ESP_LOGD(TAG, "Stopping web server before reboot");
|
||||
this->parent_->get_server()->end();
|
||||
}
|
||||
#endif
|
||||
App.safe_reboot();
|
||||
});
|
||||
}
|
||||
|
||||
void OTARequestHandler::ota_init_(const char *filename) {
|
||||
@ -217,7 +227,17 @@ void OTARequestHandler::handleRequest(AsyncWebServerRequest *request) {
|
||||
}
|
||||
#endif // USE_ARDUINO
|
||||
#ifdef USE_ESP_IDF
|
||||
// For ESP-IDF, we use direct send() instead of beginResponse()
|
||||
// to ensure the response is sent immediately before the reboot.
|
||||
//
|
||||
// Note about "uri handler execution failed" warnings:
|
||||
// During OTA completion, the ESP-IDF HTTP server may log these warnings
|
||||
// as the system prepares for reboot. They occur because:
|
||||
// 1. The browser may try to fetch resources (e.g., /events) after OTA completes
|
||||
// 2. The server is shutting down and can't process new requests
|
||||
// These warnings are harmless and expected during OTA reboot.
|
||||
if (this->ota_success_) {
|
||||
ESP_LOGD(TAG, "Sending OTA success response before reboot");
|
||||
request->send(200, "text/plain", "Update Successful!");
|
||||
} else {
|
||||
request->send(200, "text/plain", "Update Failed!");
|
||||
|
@ -49,6 +49,9 @@ void AsyncWebServer::begin() {
|
||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||
config.server_port = this->port_;
|
||||
config.uri_match_fn = [](const char * /*unused*/, const char * /*unused*/, size_t /*unused*/) { return true; };
|
||||
// Increase stack size for OTA operations - esp_ota_end() needs more stack
|
||||
// during image validation than the default 4096 bytes
|
||||
config.stack_size = 6144;
|
||||
if (httpd_start(&this->server_, &config) == ESP_OK) {
|
||||
const httpd_uri_t handler_get = {
|
||||
.uri = "",
|
||||
@ -337,7 +340,11 @@ esp_err_t AsyncWebServer::request_handler_(AsyncWebServerRequest *request) const
|
||||
this->on_not_found_(request);
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
// No handler found - send 404 response
|
||||
// This prevents "uri handler execution failed" warnings
|
||||
ESP_LOGD(TAG, "No handler found for URL: %s (method: %d)", request->url().c_str(), request->method());
|
||||
request->send(404, "text/plain", "Not Found");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
AsyncWebServerRequest::~AsyncWebServerRequest() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user