IDF实现OTA下载新固件速度慢,如何变快?

fland@126.com
Posts: 8
Joined: Thu Oct 28, 2021 2:46 am

IDF实现OTA下载新固件速度慢,如何变快?

Postby fland@126.com » Wed Dec 01, 2021 1:03 am

OTA的固件1.5MB不到, 运行OTA下载, 代码设计按照1%的递增显示进度,串口调试助手收到信息是每两秒才下载14KB。 平均每秒才7K。按照地址在网页浏览器下载, 每秒达到800多KB.

为什么这么慢呢?

Code: Select all

    esp_err_t ota_finish_err = ESP_OK;
    esp_http_client_config_t config = {
        .url = OTA_FIRMWARE_UPGRADE_URI,
        .cert_pem = NULL,  //(char *)server_cert_pem_start,
    };
    
    esp_https_ota_config_t ota_config = {
        .http_config = &config,
    };
    
    esp_https_ota_handle_t https_ota_handle = NULL;
    esp_err_t err = esp_https_ota_begin(&ota_config, &https_ota_handle);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "ESP HTTPS OTA Begin failed");
        vTaskDelete(NULL);
    }

    esp_app_desc_t app_desc;
    err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_https_ota_read_img_desc failed");
        goto ota_end;
    }
    err = validate_image_header(&app_desc);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "image header verification failed");
        goto ota_end;
    }

    i = 0;
    len = 0;
    percent = 0;
    while (1) {
        //vTaskDelay(1000 / portTICK_PERIOD_MS);
        err = esp_https_ota_perform(https_ota_handle);
        if (err != ESP_ERR_HTTPS_OTA_IN_PROGRESS) {
            break;
        }
        // esp_https_ota_perform returns after every read operation which gives user the ability to
        // monitor the status of OTA upgrade by calling esp_https_ota_get_image_len_read, which gives length of image
        // data read so far.
        len = esp_https_ota_get_image_len_read(https_ota_handle);
        if ((len - i) > 14336) {
            percent++;
            ESP_LOGE(TAG, "Image bytes read: %d, OTA : %d%%", len, percent);
            i = len;
        }
    }


Helpsen
Posts: 3
Joined: Sat Jan 14, 2023 9:21 am

Re: IDF实现OTA下载新固件速度慢,如何变快?

Postby Helpsen » Mon Aug 28, 2023 4:02 am

这个问题解决了吗,我现在也是遇到这种情况

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: IDF实现OTA下载新固件速度慢,如何变快?

Postby ESP_YJM » Tue Aug 29, 2023 7:49 am

增加 TCP 窗口,WIFI RX buffer 等等可以加快下载速度,你可以尝试增大如下配置项

CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP_WIFI_RX_BA_WIN=32
CONFIG_LWIP_TCP_WND_DEFAULT=28800
CONFIG_LWIP_TCP_RECVMBOX_SIZE=64
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64

增大这些配置会大幅增加内存开销,其中 CONFIG_LWIP_TCP_WND_DEFAULT 在内存充足的情况下可以适当增加。
然后 OTA 读取和写的 bufer 大小最好遵循读一个 sector,写一个 sector(4096 字节),所以可以修改 https://github.com/espressif/esp-idf/bl ... mple.c#L92 里 http config 的 buffer_size 为 4096.

总之想要更快的速度的代价就是更多的内存消耗。

Who is online

Users browsing this forum: No registered users and 37 guests