]> granicus.if.org Git - esp-idf/commitdiff
esp_https_ota: add support for configurable ota buffer size
authorMahavir Jain <mahavir@espressif.com>
Wed, 30 Jan 2019 08:54:20 +0000 (14:24 +0530)
committerMahavir Jain <mahavir@espressif.com>
Wed, 30 Jan 2019 12:41:09 +0000 (18:11 +0530)
Closes https://github.com/espressif/esp-idf/issues/2998

components/esp_https_ota/src/esp_https_ota.c
examples/system/ota/simple_ota_example/main/simple_ota_example.c

index 3e18f9d4b1a1a16dca1ef1e70a9bed7603b73f7c..f44812466c051892381ad4741d7689f523338336 100644 (file)
@@ -19,7 +19,7 @@
 #include <esp_ota_ops.h>
 #include <esp_log.h>
 
-#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;
             }
index 7972f8bd57edbf851f747f6ce0b68a3799f5976f..71bcaa043233f6e898a6d5ab55dbc4996a15d1fb 100644 (file)
@@ -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);