PlatformIO Community

File-serving server, can't upload filesystem image

Hello! I am writing a simple file-serving http server using this example “esp-idf/examples/protocols/http_server/file_serving/main at f65c8249af109de349650b9cf79ae283992617”, but I encountered a problem. I can’t build my program, nor build filesystem image, due to errors with /data directory, when I am trying to embed files to SPIFFS partition.
This is how my project structure looks like:
image
Rest of the project (I think) is configured in accordance to ESP-IDF documentation. Here are the most important parts:
partitions.csv ( partition configured in menu config as custom as well)

# Name,   Type, SubType, Offset,  Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
storage,  data, spiffs,  ,        0xF0000,

platformio.ini

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = espidf
monitor_speed = 115200
board_build.partitions = partitions.csv
board_build.embed_txtfiles =
  data/favicon.ico
  data/upload_script.html

project CMakeList

cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(HTTP-server)
target_add_binary_data(HTTP-server.elf "data/favicon.ico" TEXT)
target_add_binary_data(HTTP-server.elf "data/upload_script.html" TEXT)

/src/CMakeList

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)

idf_component_register(SRCS ${app_sources})

During compilation I get errors on those lines in file_system.c:

    extern const unsigned char favicon_ico_start[] asm("_binary_favicon_ico_start");
    extern const unsigned char favicon_ico_end[] asm("_binary_favicon_ico_end");
    extern const unsigned char upload_script_start[] asm("_binary_upload_script_html_start");
    extern const unsigned char upload_script_end[] asm("_binary_upload_script_html_end");
Linking .pio/build/nodemcu-32s/firmware.elf
/home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.http_resp_dir_html+0x14): undefined reference to `_binary_upload_script_html_end'
/home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.http_resp_dir_html+0x18): undefined reference to `_binary_upload_script_html_start'
/home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.favicon_get_handler+0x0): undefined reference to `_binary_favicon_ico_end'
/home/artur/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/nodemcu-32s/src/file_server.o:(.literal.favicon_get_handler+0x4): undefined reference to `_binary_favicon_ico_start'
collect2: error: ld returned 1 exit status
*** [.pio/build/nodemcu-32s/firmware.elf] Error 1
================================================================================= [FAILED] Took 65.20 seconds ================================================================================= 

(on the other note, why is platformio always compiling all the files? it makes it so slow! why can’t it only compile those that were changed?)

And during “Build Filesystem Image” task I get this error:

*** [.pio/build/nodemcu-32s/spiffs.bin] Implicit dependency `data/favicon' not found, needed by target `.pio/build/nodemcu-32s/spiffs.bin'.
================================================================================= [FAILED] Took 5.70 seconds =================================================================================
The terminal process "platformio 'run', '--target', 'buildfs', '--environment', 'nodemcu-32s'" terminated with exit code: 1.

I would be very thankful for any advice.

Careful.

Will try to create a SPIFFS image of the data stored in the data/ folder. The project is then searched for a partition table and uploaded to wit hthe “Upload Filesystem Image”.

Will try and include the given files directly into the binary. No SPIFFS partition or anything is created.

Since the example you linked to is using

You must be usingg the embedded data path, not SPIFFS. That is not used at all here.

No, as you can see in the reference project

the instructions to add data goes into the src/CMakeLists.txt.

I recommend you to move the files from data/ directly to src/, just like the original example does (and also to prevent PlatformIO from creating a SPIFFS partition), adapt the CMakeLists.txt and src/CMakeLists.txt according to my comments and references above, and modify the path to the files in platformio.ini as well.

Thank you, it worked! But this only showed that I don’t understand the difference between HAVING data on SPIFFS partition and EMBEDDING it into an app. Could you maybe point me out into any good resources explaining when which one should be used, or if you have time try to explain basics of it yourself? You see, my simple brain though that HTML files should be usually part of data/ and send using SPIFFS. If that where the case, then all those changes to platform.io and CMake files would be unnecessary? Can you serve files from SPIFFS on httpd server the same way you do with embedded files? Thank you in advance.