What i've tried it's to read the whole .bin file as a binary and store it on a char * buffer but... it doesn't work.
Code: Select all
void try_update() {
esp_ota_handle_t update_handle = 0;
const esp_partition_t *update_partition = esp_ota_get_next_update_partition(NULL);
esp_err_t err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
ESP_LOGI(TAG, "esp_begin result = %d", err);
binary_data_t *data = readFile(MOUNT_POINT"/update.bin");
err = esp_ota_write(update_handle, data->data, data->size);
ESP_LOGI(TAG, "Ota result = %d", err);
err = esp_ota_end(update_handle);
if (err != ESP_OK) {
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
ESP_LOGE(TAG, "Image validation failed, image is corrupted");
}
ESP_LOGE(TAG, "esp_ota_end failed (%s)!", esp_err_to_name(err));
}
err = esp_ota_set_boot_partition(update_partition);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
}
ESP_LOGI(TAG, "Prepare to restart system!");
esp_restart();
}