diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 3e18f9d4b..f44812466 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -19,7 +19,7 @@ #include #include -#define OTA_BUF_SIZE 256 +#define DEFAULT_OTA_BUF_SIZE 256 static const char *TAG = "esp_https_ota"; static void http_cleanup(esp_http_client_handle_t client) @@ -85,16 +85,18 @@ esp_err_t esp_https_ota(const esp_http_client_config_t *config) ESP_LOGI(TAG, "Please Wait. This may take time"); esp_err_t ota_write_err = ESP_OK; - char *upgrade_data_buf = (char *)malloc(OTA_BUF_SIZE); + const int alloc_size = (config->buffer_size > 0) ? config->buffer_size : DEFAULT_OTA_BUF_SIZE; + char *upgrade_data_buf = (char *)malloc(alloc_size); if (!upgrade_data_buf) { ESP_LOGE(TAG, "Couldn't allocate memory to upgrade data buffer"); return ESP_ERR_NO_MEM; } + int binary_file_len = 0; while (1) { - int data_read = esp_http_client_read(client, upgrade_data_buf, OTA_BUF_SIZE); + int data_read = esp_http_client_read(client, upgrade_data_buf, alloc_size); if (data_read == 0) { - ESP_LOGI(TAG, "Connection closed,all data received"); + ESP_LOGI(TAG, "Connection closed, all data received"); break; } if (data_read < 0) { @@ -102,7 +104,7 @@ esp_err_t esp_https_ota(const esp_http_client_config_t *config) break; } if (data_read > 0) { - ota_write_err = esp_ota_write( update_handle, (const void *)upgrade_data_buf, data_read); + ota_write_err = esp_ota_write(update_handle, (const void *) upgrade_data_buf, data_read); if (ota_write_err != ESP_OK) { break; } diff --git a/examples/system/ota/simple_ota_example/main/simple_ota_example.c b/examples/system/ota/simple_ota_example/main/simple_ota_example.c index 7972f8bd5..71bcaa043 100644 --- a/examples/system/ota/simple_ota_example/main/simple_ota_example.c +++ b/examples/system/ota/simple_ota_example/main/simple_ota_example.c @@ -96,7 +96,7 @@ static void initialise_wifi(void) .password = CONFIG_WIFI_PASSWORD, }, }; - ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid); + ESP_LOGI(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() ); @@ -104,14 +104,14 @@ static void initialise_wifi(void) void simple_ota_example_task(void * pvParameter) { - ESP_LOGI(TAG, "Starting OTA example..."); + ESP_LOGI(TAG, "Starting OTA example"); /* Wait for the callback to set the CONNECTED_BIT in the event group. */ xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY); - ESP_LOGI(TAG, "Connect to Wifi ! Start to Connect to Server...."); + ESP_LOGI(TAG, "Connected to WiFi network! Attempting to connect to server..."); esp_http_client_config_t config = { .url = CONFIG_FIRMWARE_UPGRADE_URL, @@ -122,7 +122,7 @@ void simple_ota_example_task(void * pvParameter) if (ret == ESP_OK) { esp_restart(); } else { - ESP_LOGE(TAG, "Firmware Upgrades Failed"); + ESP_LOGE(TAG, "Firmware upgrade failed"); } while (1) { vTaskDelay(1000 / portTICK_PERIOD_MS);