From f108c118221b85fa517e8ab06c3e6a237c3f8302 Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 17 Jul 2025 18:16:25 -0600 Subject: [PATCH] Fix upload page to split html --- main/ota_server.c | 334 ++++++++++++++++++++++++---------------------- 1 file changed, 171 insertions(+), 163 deletions(-) diff --git a/main/ota_server.c b/main/ota_server.c index 5515d7a..31b7607 100644 --- a/main/ota_server.c +++ b/main/ota_server.c @@ -21,157 +21,6 @@ static const char *TAG = "OTA_SERVER"; -// HTML page for OTA update -static const char *ota_html = -"" -"" -"" -"ESP32 OTA Update" -"" -"" -"" -"" -"
" -"

ESP32 OTA Update

" -"
" -"Current Version: %s
" -"Free Space: %u KB" -"
" -"
" -"

Drag and drop firmware file here or click to select

" -"" -"" -"
" -"
" -"" -"
" -"
0%%
" -"
" -"
" -"
" -"" -"" -""; - // Server handle static httpd_handle_t s_server = NULL; @@ -208,20 +57,179 @@ static esp_err_t index_handler(httpd_req_t *req) } esp_partition_iterator_release(it); - // Allocate buffer for response - size_t response_size = strlen(ota_html) + 64; - char *response = malloc(response_size); - if (!response) { - httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Memory allocation failed"); - return ESP_FAIL; - } - - snprintf(response, response_size, ota_html, s_version, free_space / 1024); - + // Send response in chunks httpd_resp_set_type(req, "text/html"); - httpd_resp_send(req, response, strlen(response)); - free(response); + // Part 1: HTML head and styles + const char *html_part1 = + "" + "" + "" + "ESP32 OTA Update" + "" + "" + "" + "" + "
" + "

ESP32 OTA Update

"; + + httpd_resp_send_chunk(req, html_part1, strlen(html_part1)); + + // Part 2: Info section with dynamic content + char info_buf[256]; + snprintf(info_buf, sizeof(info_buf), + "
" + "Current Version: %s
" + "Free Space: %lu KB" + "
", s_version, (unsigned long)(free_space / 1024)); + + httpd_resp_send_chunk(req, info_buf, strlen(info_buf)); + + // Part 3: Upload area + const char *html_part3 = + "
" + "

Drag and drop firmware file here or click to select

" + "" + "" + "
" + "
" + "" + "
" + "
0%
" + "
" + "
" + "
"; + + httpd_resp_send_chunk(req, html_part3, strlen(html_part3)); + + // Part 4: JavaScript + const char *html_part4 = + "" + "" + ""; + + httpd_resp_send_chunk(req, html_part4, strlen(html_part4)); + + // Send final chunk to complete response + httpd_resp_send_chunk(req, NULL, 0); + return ESP_OK; }