Slow file download speed via HTTPS GET

dr.modi
Posts: 6
Joined: Tue Jan 31, 2023 12:14 pm

Slow file download speed via HTTPS GET

Postby dr.modi » Fri Mar 31, 2023 10:02 am

Hello everyone. I use a board based on ESP-WROOM-32 in conjunction with the W5500. I want to download some files for storage on the SD card, but I am faced with the fact that the speed is very low. I managed to download 3 MB in 22 minutes. I don't quite understand why this happens, because a PC connected to the same network downloads this file in ~10 seconds.
Here is a bit of my code. Download request GET function:

Code: Select all

void http_get_file() {
    esp_http_client_config_t config_get = {
        .url = "https://download.samplelib.com/wav/sample-15s.wav",
        .method = HTTP_METHOD_GET,
        .cert_pem = (const char *)certs_pem_start,
        .event_handler = client_event_get_handler};

    esp_http_client_handle_t client = esp_http_client_init(&config_get);
    esp_http_client_perform(client);
    esp_http_client_cleanup(client);
}
Event GET handler:

Code: Select all

esp_err_t client_event_get_handler(esp_http_client_event_handle_t evt) {
    ESP_LOGI(TAG, "Opening file %s", file_wav);
    FILE *sd_f = fopen(file_wav, "a");
    if (sd_f == NULL) {
        ESP_LOGE(TAG, "Failed to open file for writing");
        return ESP_FAIL;
    }
    switch (evt->event_id) {
        case HTTP_EVENT_ON_DATA:
            fwrite(evt->data, 1, evt->data_len, sd_f);
            break;
        default:
            break;
    }
    fclose (sd_f);
    return ESP_OK;
}
In the end I get the correct file that plays, but it's too slow. I tested the maximum speed using the iperf example and got the result in 8.2 Mbits/sec. What important configurations need to be made to increase the speed? Or maybe it's worth changing the approach?

Who is online

Users browsing this forum: Baidu [Spider] and 110 guests