Later on that page they say again " The names are generated from the full name of the file, as given in COMPONENT_EMBED_FILES ." So where did they get “COMPONENT_EMBED_TXTFILES” at ?
Anyone did resolve this issue?
What is the supported way to embed binary not text files?
Is the key COMPONENT_EMBED_FILES supported by platformio? (I can see only the key COMPONENT_EMBED_TXTFILES mentioned in the pio documentation)
Thank you maxgerhardt for your reply.
As a conclusion for my analysis: [COMPONENT_EMBED_TXTFILES] yes does support binary, but as well it adds “\0” at the end of the string once stored on ESP32. That illegal character was breaking the java scripts that I was uploading to ESP32.
The solution was to copy “string length -1” to avoid including the “\0” at the end of the file once it is returned to the user from ESP32.
example:
“extern const uint8_t code_js_start[] asm(”_binary_src_code_js_start");
extern const uint8_t code_js_end[] asm("_binary_src_code_js_end");
netconn_write(conn, code_js_start, code_js_end - code_js_start -1, NETCONN_NOCOPY); "
Hope that could be helpful to the community having same problem.
Thank you all for the information. I intend to use the COMPONENT_EMBED_TXTFILES option in my current ESP32 project however, I believe there is a problem. It appears that during compilation, the ‘\0’ null char is not only added to the embedded file, the source file is also modified. The best way to replicate this error is to embed a Javascript file. On the ESP32 device, the file will work correctly (assuming you specify the length -1) however if the source file is now opened, a NULL Char has been appended to the end and it is broken. Attempting to set the source file as Read Only causes the compiler to have a meltdown! Although this is not a ‘Critical’ problem, it causes no end of drama while developing.
The file of the object which is injected into the binary is generated from the path and filename. Since you wrote src/logo.png it will create the two symbols _binary_src_logo_png_start and _binary_src_logo_png_end. In your code you however reference a different name, thus you get the error.
Either move the src/logo.png one folder higher and use -DCOMPONENT_EMBED_TXTFILES=logo.png or use the correct object name in your asm symbol declaration.
As an alternative, you can try free utility from Segger, named bin2c: What is Bin2c
It creates C source file with null-terminated array of unsigned char containing data of the binary file which is specified on command line as an argument: bin2c binary_file.
The only manual correction I had to do was to change the array name because my binary file contained dots as part of its name, and they got carried over to the array name.
After that, you can include this C file in yours, and voila.
I have an issue with this using platform = espressif32@1.11.0
As a conclusion for my analysis: [ COMPONENT_EMBED_TXTFILES ] yes does support binary, but as well it adds “\0” at the end of the string once stored on ESP32. That illegal character was breaking the java scripts that I was uploading to ESP32. The solution was to copy “string length -1” to avoid including the “\0” at the end of the file once it is returned to the user from ESP32
Every time I now build or upload my program it will add another “\0” at the end of the file…
I have to go through the embedded files manually and delete the extra \0\0\0\0\0\0\ depending on how many builds i do.
that was fixed. Is it still not working in the latest espressif32 release? If it is fixed, you would either need to upgrade your platform version or a backport of the fix is needed.
If you take a look at CMakeLists.txt file for a current project, and that one you will notice they are significantly different. Using Esp32 v3.2.0 & PlatformIO v2.3.2.
If you try to add target_add_binary_data(${COMPONENT_TARGET} “src/myfile.txt” TEXT)
you will get an error.
I.E. A current project looks like this:
> # This file was automatically generated for projects
> # without default 'CMakeLists.txt' file.
>
> FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
>
> idf_component_register(SRCS ${app_sources})
It says, you can use board_build.embed_txtfiles = your file.
When I enter this in using my file it gives an error. Not at work so cannot copy it now. Basically I just want to be sure that the docs are still correct and things have not changed. That example does not do it this way, and I want to be able to.