Problems when using wear-leveling and http client together

Jay_EEE
Posts: 10
Joined: Wed Feb 24, 2021 4:26 am

Problems when using wear-leveling and http client together

Postby Jay_EEE » 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.");

/* ********************************************************************** */

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems when using wear-leveling and http client together

Postby ESP_Sprite » Wed Feb 24, 2021 6:51 am

Those two have very little to do with eachother. What error do you get specifically?

Jay_EEE
Posts: 10
Joined: Wed Feb 24, 2021 4:26 am

Re: Problems when using wear-leveling and http client together

Postby Jay_EEE » Wed Feb 24, 2021 8:02 am

ESP_Sprite wrote:
Wed Feb 24, 2021 6:51 am
Those two have very little to do with eachother. What error do you get specifically?
When the code is executed in the order of


1. http client open
2. fat spiflash mount

the log is

I (3674) MAIN: Charger Firmware Download To HTTPS
I (4900) MAIN: HTTPS OPEN.
I (4900) MAIN: Mounting FAT filesystem
E (4902) MAIN: Failed to mount FATFS (ESP_ERR_NO_MEM)


1. fat spiflash mount
2. http client open

the log is

I (3678) MAIN: Mounting FAT filesystem
I (3685) MAIN: FAT MOUNT.
I (3686) MAIN: Opening file
I (3691) MAIN: Charger Firmware Download To HTTPS
E (3744) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7f00
E (3745) esp-tls: create_ssl_handle failed
E (3745) esp-tls: Failed to open new connection
E (3750) TRANS_SSL: Failed to open a new connection
E (3757) HTTP_CLIENT: Connection failed, sock < 0
E (3761) MAIN: Failed to open HTTP connection: ESP_ERR_HTTP_CONNECT


In my opinion, the http open function is also a file open, so it seems like an error caused by not opening two files at the same time.
The original code is in the body.

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems when using wear-leveling and http client together

Postby ESP_Sprite » Wed Feb 24, 2021 8:13 am

ESP_ERR_NO_MEM strongly indicates that you're using too much memory, and either mounting a filesystem or starting a https connection cannot be done anymore as there's no memory left.

Jay_EEE
Posts: 10
Joined: Wed Feb 24, 2021 4:26 am

Re: Problems when using wear-leveling and http client together

Postby Jay_EEE » Wed Feb 24, 2021 9:25 am

ESP_Sprite wrote:
Wed Feb 24, 2021 8:13 am
ESP_ERR_NO_MEM strongly indicates that you're using too much memory, and either mounting a filesystem or starting a https connection cannot be done anymore as there's no memory left.
Thank you.. I found the problem.. I should have been suspicious when the memory error came out.. Memory management is really difficult.. haha :)

Who is online

Users browsing this forum: No registered users and 89 guests