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.");
/* ********************************************************************** */
Problems when using wear-leveling and http client together
-
- Posts: 9739
- Joined: Thu Nov 26, 2015 4:08 am
Re: Problems when using wear-leveling and http client together
Those two have very little to do with eachother. What error do you get specifically?
Re: Problems when using wear-leveling and http client together
When the code is executed in the order ofESP_Sprite wrote: ↑Wed Feb 24, 2021 6:51 amThose two have very little to do with eachother. What error do you get specifically?
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.
-
- Posts: 9739
- Joined: Thu Nov 26, 2015 4:08 am
Re: Problems when using wear-leveling and http client together
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.
Re: Problems when using wear-leveling and http client together
Thank you.. I found the problem.. I should have been suspicious when the memory error came out.. Memory management is really difficult.. hahaESP_Sprite wrote: ↑Wed Feb 24, 2021 8:13 amESP_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.
Who is online
Users browsing this forum: No registered users and 117 guests