Large Uploads Get Corrupted
Posted: Thu Apr 04, 2019 1:22 am
I have been working on a project that uploads data to the ESP32 http server. I have found that, above certain sizes, the mechanism does not properly buffer the incoming data - or at least that is what I think is going on.
When the CPU starts I can see the message: "I (306) wifi: Init static rx buffer size: 1600" on the console and I believe this has something to do with that. The size of the upload that gets corrupted happens at about twice that value ~ somewhere around 3200 bytes.
I have isolated the code into a sample file that loads a webserver, presents a page at the default url (just put the ip in the browser's address) and the page demonstrates the error.
The code preloads the data with '1's except at the i%160 point where it puts a '0'. When you get this from the ESP32 by clicking the "Get Data" button it paints this on the canvas in a grid 160 wide down the left hand side. Then when you press the "Put Data" button it uploads it to the ESP32 http server which stores it back to the original character array. However, it does not do so correctly as pressing the "Get Data" button once again will show.
I have gone through the post and get with wireshark and do not believe the webpage nor the browser has anything to do with this. I tested this with Chromium.
I have put the code in DEBUG mode but got no relevant info, again this is to the best of my knowledge. Please help me verify that this is a bug - or point me to the mistake in my code if possible.
Thank you for any and all help
When the CPU starts I can see the message: "I (306) wifi: Init static rx buffer size: 1600" on the console and I believe this has something to do with that. The size of the upload that gets corrupted happens at about twice that value ~ somewhere around 3200 bytes.
I have isolated the code into a sample file that loads a webserver, presents a page at the default url (just put the ip in the browser's address) and the page demonstrates the error.
The code preloads the data with '1's except at the i%160 point where it puts a '0'. When you get this from the ESP32 by clicking the "Get Data" button it paints this on the canvas in a grid 160 wide down the left hand side. Then when you press the "Put Data" button it uploads it to the ESP32 http server which stores it back to the original character array. However, it does not do so correctly as pressing the "Get Data" button once again will show.
I have gone through the post and get with wireshark and do not believe the webpage nor the browser has anything to do with this. I tested this with Chromium.
- #include <sys/param.h>
- #include <esp_event_loop.h>
- #include <esp_log.h>
- #include <esp_http_server.h>
- #include <esp_wifi.h>
- #include "esp_system.h"
- #include "esp_spiffs.h"
- #include "nvs_flash.h"
- #define TAG "Large_Upload_Test"
- // Declare some functions so that we can order the code as we wish
- httpd_handle_t start_webserver(void);
- void stop_webserver(httpd_handle_t server);
- // This parameter determines the size of the test. The data is downloaded to a webpage and uploaded to the ESP32 again.
- // Target for my project was 19200
- #define UPLOAD_DOWNLOAD_SIZE 19200
- // This determines the buffer size for the upload. Large sizes show bad corruption, even at 1600 or less it shows corruption
- #define UPLOAD_CACHE_SIZE 1600
- // This determines the buffer size for the download. It works at pretty much any reasonable size
- #define DOWNLOAD_CACHE_SIZE 1600
- char detectionMask[UPLOAD_DOWNLOAD_SIZE];
- esp_err_t event_handler(void *ctx, system_event_t *event) {
- httpd_handle_t *server = (httpd_handle_t *)ctx;
- switch (event->event_id) {
- case SYSTEM_EVENT_STA_START:
- ESP_LOGD(TAG, "SYSTEM_EVENT_STA_START");
- ESP_ERROR_CHECK(esp_wifi_connect());
- break;
- case SYSTEM_EVENT_STA_GOT_IP:
- ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOT_IP");
- ESP_LOGD(TAG, "Got IP: '%s'",
- ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
- /* Start the web server */
- if (*server == NULL) {
- *server = start_webserver();
- }
- break;
- case SYSTEM_EVENT_STA_DISCONNECTED:
- ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
- ESP_ERROR_CHECK(esp_wifi_connect());
- /* Stop the web server */
- if (*server) {
- stop_webserver(*server);
- *server = NULL;
- }
- break;
- default:
- break;
- }
- return ESP_OK;
- }
- void initialise_wifi(void *arg) {
- ESP_ERROR_CHECK(nvs_flash_init());
- tcpip_adapter_init();
- ESP_ERROR_CHECK(esp_event_loop_init(event_handler, arg));
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK(esp_wifi_init(&cfg));
- ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
- wifi_config_t wifi_config = {
- .sta = {
- .ssid = CONFIG_WIFI_SSID,
- .password = CONFIG_WIFI_PASSWORD,
- },
- };
- ESP_LOGD(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
- ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
- ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
- ESP_ERROR_CHECK(esp_wifi_start());
- }
- void app_main() {
- for (int i=0; i < sizeof(detectionMask); i++) {
- if (i%160==0) detectionMask[i] = 0;
- else detectionMask[i] = 1;
- }
- static httpd_handle_t server = NULL;
- initialise_wifi(&server);
- }
- esp_err_t set_mask_handler(httpd_req_t *req) {
- char contentBuffer[UPLOAD_CACHE_SIZE];
- size_t recv_size = sizeof(contentBuffer);
- size_t contentLen = req->content_len;
- // some sort of data error happens every 3200 bytes - turn on debug
- esp_log_level_set("*", ESP_LOG_DEBUG);
- ESP_LOGI(TAG, "Incoming transmission %d bytes", contentLen);
- size_t bytes_recvd = 0;
- while (bytes_recvd < contentLen) {
- if ((contentLen - bytes_recvd) < recv_size) recv_size = contentLen - bytes_recvd;
- ESP_LOGI(TAG,"Recieving %d bytes in chunk, total bytes received: %d", recv_size, bytes_recvd);
- int ret = httpd_req_recv(req, contentBuffer, recv_size);
- if (ret <= ESP_OK) { /* ESP_OK return value indicates connection closed */
- /* Check if timeout occurred */
- if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
- /* In case of timeout one can choose to retry calling
- * httpd_req_recv(), but to keep it simple, here we
- * respond with an HTTP 408 (Request Timeout) error */
- httpd_resp_send_408(req);
- }
- /* In case of error, returning ESP_FAIL will
- * ensure that the underlying socket is closed */
- ESP_LOGE(TAG,"Something bad happened, bytes left: %d", contentLen - bytes_recvd);
- return ESP_FAIL;
- }
- // This is debug code to show the first few characters of the buffer.
- // In the stock state the buffer size aligns with the encoded data so that each row should
- // show the characters "011111111111" ...while this works for the first few rows the
- // data then skews about 12 places behind in index, and repeats a couple of other times
- char printData[13];
- printData[12] = '\0';
- ESP_LOGI(TAG, "Writing bytes %d through %d", bytes_recvd, bytes_recvd+recv_size-1);
- for (int i=0; i<recv_size; i++) {
- if (i<12) printData[i] = contentBuffer[i];
- detectionMask[bytes_recvd+i] = contentBuffer[i]=='1'?true:false;
- }
- ESP_LOGI(TAG, "12 Bytes: %s",printData);
- // End debug code
- bytes_recvd += recv_size;
- }
- /* Send a simple response */
- const char resp[] = "Data uploaded successfully";
- httpd_resp_send(req, resp, strlen(resp));
- esp_log_level_set("*", ESP_LOG_INFO);
- return ESP_OK;
- }
- httpd_uri_t uri_upload_mask = {
- .uri = "/bitmask",
- .method = HTTP_POST,
- .handler = set_mask_handler
- };
- esp_err_t get_mask_handler(httpd_req_t *req) {
- char contentBuffer[DOWNLOAD_CACHE_SIZE];
- size_t send_size = sizeof(contentBuffer);
- ESP_LOGI(TAG, "Starting transmission of %d bytes", sizeof(detectionMask));
- size_t bytes_sent = 0;
- while (bytes_sent < sizeof(detectionMask)) {
- if (sizeof(detectionMask) - bytes_sent < send_size) send_size = sizeof(detectionMask) - bytes_sent;
- ESP_LOGI(TAG, "Reading bytes %d through %d", bytes_sent, bytes_sent+send_size-1);
- for (int i=0; i<send_size; i++) {
- contentBuffer[i] = detectionMask[bytes_sent+i]?'1':'0';
- }
- ESP_LOGI(TAG,"Sending %d bytes in chunk, total bytes sent: %d", send_size, bytes_sent);
- httpd_resp_send_chunk(req, (const char *)contentBuffer, send_size);
- // the return codes showed error when it actually worked here...
- // if (ret <= ESP_OK) { /* ESP_OK return value indicates connection closed */
- // /* Check if timeout occurred */
- // if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
- // /* In case of timeout one can choose to retry calling
- // * httpd_req_recv(), but to keep it simple, here we
- // * respond with an HTTP 408 (Request Timeout) error */
- // httpd_resp_send_408(req);
- // }
- // /* In case of error, returning ESP_FAIL will
- // * ensure that the underlying socket is closed */
- // ESP_LOGE(TAG,"Something bad happened, bytes left: %d", sizeof(imageDetectionMask) - bytes_sent);
- // return ESP_FAIL;
- // }
- bytes_sent += send_size;
- }
- // Send 0 size to terminate
- httpd_resp_send_chunk(req, (const char *)contentBuffer, 0);
- /* Send a simple response */
- const char resp[] = "Data downloaded successfully";
- httpd_resp_send(req, resp, strlen(resp));
- return ESP_OK;
- }
- httpd_uri_t uri_download_mask = {
- .uri = "/bitmask",
- .method = HTTP_GET,
- .handler = get_mask_handler
- };
- // This is a simple web page processed with gzip, opened in a hex editor and pasted here.
- // I have wiresharked it for accuracy, it is not the browser doing this. Tested in Chromium
- const char default_html_gz[] = {
- 0x1F, 0x8B, 0x08, 0x08, 0x20, 0x4F, 0xA5, 0x5C, 0x00, 0x03, 0x75, 0x70, 0x6C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x00, 0xD5, 0x57, 0xDD, 0x53, 0xDB, 0x46, 0x10, 0x7F, 0xCF, 0x5F, 0x71, 0xBD, 0x4E, 0x63, 0x51, 0x1C, 0x4B, 0xD0, 0x24, 0x93, 0x89, 0x2D, 0x3F, 0x40, 0x68, 0xC8, 0x0C, 0x14, 0x06, 0x9B, 0xB4, 0x9D, 0x34, 0xC3, 0x9C, 0xA5, 0x45, 0xBA, 0x20, 0xDD, 0xA9, 0xD2, 0xC9, 0xC6, 0xD3, 0xE1, 0x7F, 0xEF, 0x9E, 0x4E, 0x36, 0xA7, 0x0F, 0x08, 0xBC, 0xB5, 0xE2, 0x01, 0x69, 0x77, 0xEF, 0xB7, 0xDF, 0x7B, 0xEB, 0xC9, 0x0F, 0x1F, 0xCE, 0x0E, 0xE7, 0x7F, 0x9E, 0x1F, 0x91, 0x58, 0xA5, 0xC9, 0xF4, 0xC5, 0x44, 0xFF, 0x23, 0x09, 0x13, 0x91, 0x4F, 0x41, 0x50, 0x4D, 0x00, 0x16, 0x4E, 0x5F, 0x10, 0x7C, 0x26, 0x29, 0x28, 0x46, 0x82, 0x98, 0xE5, 0x05, 0x28, 0x9F, 0x5E, 0xCE, 0x7F, 0x7D, 0xF5, 0x8E, 0xD6, 0x2C, 0xC5, 0x55, 0x02, 0xD3, 0x13, 0x96, 0x47, 0x40, 0x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set_hdr(req, "Content-Encoding","gzip");
- httpd_resp_send(req, default_html_gz, sizeof(default_html_gz));
- return ESP_OK;
- }
- httpd_uri_t uri_default = {
- .uri = "/",
- .method = HTTP_GET,
- .handler = defaultHtml
- };
- httpd_handle_t start_webserver(void) {
- httpd_handle_t server = NULL;
- httpd_config_t config = HTTPD_DEFAULT_CONFIG();
- //config.stack_size = 32768;
- // Start the httpd server
- ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
- if (httpd_start(&server, &config) == ESP_OK) {
- // Set URI handlers
- ESP_LOGI(TAG, "Registering URI handlers");
- httpd_register_uri_handler(server, &uri_default);
- httpd_register_uri_handler(server, &uri_upload_mask);
- httpd_register_uri_handler(server, &uri_download_mask);
- return server;
- }
- ESP_LOGE(TAG, "Error starting server!");
- return NULL;
- }
- void stop_webserver(httpd_handle_t server) {
- // Stop the httpd server
- httpd_stop(server);
- }
Thank you for any and all help