Page 1 of 1

Does file_serving example support SD Card?

Posted: Tue Feb 22, 2022 12:24 am
by Vinnie
Does file_serving example support SD Card?

Source code:

Code: Select all

https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_server/file_serving
First of all first forgive my fractured English, it's not my native language.
I'm a newbie in programming and I'm having a hard time trying this example to work with my SD Card, I tried another similar program in Arduino IDE without problems but in ESP-IDE I can't make it work as the default path for file serving to the SD Card, And it's all correctly configured with idf.py menuconfig

When I try to mount the file server to /sdcard i get the following error:

Code: Select all

"file server presently supports only '/spiffs' as base path"
The SD Card it's correctly mounted but I can't use it to upload files or for file listing, because the default path for file serving its/spiffs

Code: Select all

ets Jun  8 2016 00:22:57
I (552) example: Initializing SD card
I (552) example: Using SPI peripheral
I (562) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
Name: SS08G
Type: SDHC/SDXC
Speed: 20 MHz
Size: 7580MB
I (5212) example: Initializing SPIFFS
I (5332) example: Partition size: total: 896321, used: 3012
I (5332) file_server: Starting HTTP Server on port: '80'
I (5342) gpio: GPIO[13]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (5352) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (5352) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (5362) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
Greeting,
Vicente.

Re: Does file_serving example support SD Card?

Posted: Mon Mar 28, 2022 3:06 am
by davidjaqua
I also could not get this to work by following the directions in the readme / menuconfig.

I did get file_serving to use the sdcard by doing the following.

1. enable sdcard in menuconfig

2. in main.c, line 87 change the esp_vfs_spiffs_conf_t struct to use /sdcard

esp_vfs_spiffs_conf_t conf = {
.base_path = "/sdcard",
.partition_label = NULL,
.max_files = 5, // This decides the maximum number of files that can be created on the storage
.format_if_mount_failed = true
};

3. in main.c, line 237 ESP_ERROR_CHECK(start_file_server("/sdcard"));

4. in file_server.c line 450, comment out the check for the base_path - lines 451-455

Then it should work.

If I have it right, vfs stands in front of spiffs, which is in a file system on an nvs partition, or fat32, which is a file system on sdcard. I have no idea why they have that check for spiffs in there.

And, your English is fine. It is better that many native writers here in Vermont, USA.

Re: Does file_serving example support SD Card?

Posted: Tue Mar 29, 2022 11:23 am
by ESP_Mahavir
Hello,

Please note that "file_serving" example from ESP-IDF was recently refactored and it already includes some of the suggestions discussed here. Please find relevant commit at: https://github.com/espressif/esp-idf/co ... e581ef446b

Could you please try latest example from master branch and share your feedback?

Thanks.

Re: Does file_serving example support SD Card?

Posted: Sun Apr 17, 2022 5:14 pm
by changchenyin
davidjaqua wrote:
Mon Mar 28, 2022 3:06 am
I also could not get this to work by following the directions in the readme / menuconfig.

I did get file_serving to use the sdcard by doing the following.

1. enable sdcard in menuconfig

2. in main.c, line 87 change the esp_vfs_spiffs_conf_t struct to use /sdcard

esp_vfs_spiffs_conf_t conf = {
.base_path = "/sdcard",
.partition_label = NULL,
.max_files = 5, // This decides the maximum number of files that can be created on the storage
.format_if_mount_failed = true
};

3. in main.c, line 237 ESP_ERROR_CHECK(start_file_server("/sdcard"));

4. in file_server.c line 450, comment out the check for the base_path - lines 451-455

Then it should work.

If I have it right, vfs stands in front of spiffs, which is in a file system on an nvs partition, or fat32, which is a file system on sdcard. I have no idea why they have that check for spiffs in there.

And, your English is fine. It is better that many native writers here in Vermont, USA.
Hi, I use ESP-IDF(V4.4 stable) and change code follow your way. But actully I find it just change string "/spiffs" to '/sdcard' , you can see the log still printing :"I (5640) example: Partition size: total: 896321, used: 0".So it still use flash as storge, and I try some way prove my opinion is right.(e.g. Upload the file then reset code and unplugged the sdcard,you can see the file can be checked forever.)