我正在使用 ESP-IDF 和 PlatformIO 为 ESP32 编写一个文件服务 http 服务器,但我无法将数据上传到 SPIFFS 工作。我正在尝试将 html 和 favicon 发送到 flash,以便可以在 http 上提供。
服务器的代码取自示例https://github.com/espressif/esp-idf/tree/master/examples/protocols/http_server/file_serving。明显的区别是示例项目仅使用 ESP-IDF 工具(没有 platformio),并且在示例中,数据文件与源文件位于同一目录中,在我的项目中,我为 /src 和 /data 分开了目录。SPIFFS 是使用自定义分区表配置的。
我遵循 PlatformIO 文档(https://docs.platformio.org/en/latest/platforms/espressif32.html?utm_source=platformio&utm_medium=piohome)以及 ESP(https://docs.espressif.com )的说明/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#embedding-binary-data)。
我有自定义 partitions.csv 文件(与示例相同)+ 更改 menuconfig 以使用它。
在 platformio.ini 中,我添加了:
board_build.partitions = partitions.csv
board_build.embed_txtfiles =
data/favicon.ico
data/upload_script.html
我还更改了项目 CMakeLists 文件以嵌入如下数据:
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/CMakeLists 保持不变:
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})
但即使有所有这些配置,当我尝试在 file_server.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 =================================================================================
我尝试将外部定义更改为:
extern const unsigned char favicon_ico_start[] asm("_binary_data_favicon_ico_start");
但这并没有改变什么。
此外,在运行“构建文件系统映像”任务时,我收到此错误:
*** [.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.
任何帮助将不胜感激,因为我觉得我做了文档所述的一切。