#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)
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) {
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;
}
.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() );
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,
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);