Problems when using wear-leveling and http client together
Posted: Wed Feb 24, 2021 4:32 am
Hi everyone.
I want to save the file I receive from http in real time in flash memory as wear-leveling. However, when connecting with esp_vfs_fat_spiflash_mount and esp_http_client_open, only the one executed first works.
I think this problem is caused by using the same line. Is there any way to solve this problem?
/* ********************************************************************** */
ESP_LOGI(TAG, "Mounting FAT filesystem");
const esp_vfs_fat_mount_config_t mount_config = {
.max_files = 4,
.format_if_mount_failed = true,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
err = esp_vfs_fat_spiflash_mount(base_path, "app_storage", &mount_config, &s_wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
}
ESP_LOGI(TAG,"FAT MOUNT.");
ESP_LOGI(TAG, "Opening file");
FILE *f = fopen("/spiflash/hello.txt", "wb");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
/* ********************************************************************** */
ESP_LOGI(TAG,"Charger Firmware Download To HTTPS");
char buffer[128];
if (buffer == NULL) {
ESP_LOGE(TAG, "Cannot malloc http receive buffer");
return;
}
esp_http_client_config_t config = {
.url = CONFIG_FIRMWARE_UPGRADE_URL,
.cert_pem = (char *)server_cert_pem_start,
.event_handler = _http_event_handler,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if ((err = esp_http_client_open(client, 0)) != ESP_OK) {
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
return;
}
ESP_LOGI(TAG,"HTTPS OPEN.");
/* ********************************************************************** */
I want to save the file I receive from http in real time in flash memory as wear-leveling. However, when connecting with esp_vfs_fat_spiflash_mount and esp_http_client_open, only the one executed first works.
I think this problem is caused by using the same line. Is there any way to solve this problem?
/* ********************************************************************** */
ESP_LOGI(TAG, "Mounting FAT filesystem");
const esp_vfs_fat_mount_config_t mount_config = {
.max_files = 4,
.format_if_mount_failed = true,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
err = esp_vfs_fat_spiflash_mount(base_path, "app_storage", &mount_config, &s_wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
}
ESP_LOGI(TAG,"FAT MOUNT.");
ESP_LOGI(TAG, "Opening file");
FILE *f = fopen("/spiflash/hello.txt", "wb");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
/* ********************************************************************** */
ESP_LOGI(TAG,"Charger Firmware Download To HTTPS");
char buffer[128];
if (buffer == NULL) {
ESP_LOGE(TAG, "Cannot malloc http receive buffer");
return;
}
esp_http_client_config_t config = {
.url = CONFIG_FIRMWARE_UPGRADE_URL,
.cert_pem = (char *)server_cert_pem_start,
.event_handler = _http_event_handler,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if ((err = esp_http_client_open(client, 0)) != ESP_OK) {
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
return;
}
ESP_LOGI(TAG,"HTTPS OPEN.");
/* ********************************************************************** */