我正在使用ESP-IDF和PlatformIO为ESP32编写一个文件服务http服务器,但是我就是不能让数据上传到SPIFFS工作。我正在尝试发送html和收藏夹图标到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)的说明。
我有自定义的partisions.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");
但这并没有改变任何事情。
此外,在运行"Build Filesystem Image“任务时,我收到以下错误:
*** [.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.
任何帮助都会非常感谢,因为我觉得我做了文档中规定的所有事情。
发布于 2021-08-25 16:14:25
我怀疑您需要将它们声明为二进制而不是文本。TEXT创建一个以null结尾的字符串,该字符串可能不会生成_binary_..._end
别名。
target_add_binary_data(HTTP-server.elf "data/favicon.ico" BINARY)
target_add_binary_data(HTTP-server.elf "data/upload_script.html" BINARY)
另外,你的尖峰图像生成也有一些问题。您知道CMake宏target_add_binary_data()
和idf_component_register(... EMBED_TXTFILES...)
只将内容嵌入到应用程序二进制文件中,对吧?您不能使用它们将内容添加到预先生成的SPIFFS分区。为此,您需要使用spiffsgen-py脚本。
发布于 2021-08-26 08:32:53
问题是,我对将文件嵌入到应用程序和将文件发送到SPIFFS分区之间的区别感到有点困惑。
解决方案是将.html和.ico文件从/data移动到/src。我认为这背后的原因是这段代码:asm("_binary_favicon_ico_start")
不能引用其他目录中的文件,但我不确定。我还将项目CMakeFile恢复为默认值,并将下面这一行添加到/src/CMakeFile:idf_component_register(SRCS ${app_sources} EMBED_FILES "favicon.ico" "upload_script.html")
我也不需要创建任何文件系统镜像,因为SPIFFS分区只需要was服务器本身。
https://stackoverflow.com/questions/68924676
复制相似问题