0

I'm using the ESP32 aWOT library to setup a webserver and I'd like to embed a bunch of binary files into the firmware .bin image (for OTA update purposes). Using PlatformIO we can use the: board_build.embed_txtfiles = src/file.ext command to embed the files to the .bin file. However I didn't figured out how to retrieve the files (either using a file system like SPIFFS or using C/assembly language). The Espressif documentation mentions the extern const uint8_t file_ext_start[] asm("_binary_src_file_ext_start"); command to access the file content, but I didn't understand how to use it.

Supose a file.html is embedded into the .bin and then I wish to route it like 192.168.0.XX/file.html - the aWOT library provides the app.get("/page", &handler); in which the *handler handles the response, but how to reference the embedded html file inside the handler function?

1
  • just think about those blobs as char file_ext_start[] = "blah blah blah"; and treat them accordingly (as usual strings defined in a C code) . embed_txtfiles directive would add extra zero byte to the end of dumped file content for the file to become zero-terminated string in the code. And in case of embed_files zero terminated byte is NOT added because you know before hand that file contains arbitrary data and can contain zero byte in the middle of the data so strcpy, strlen etc are not applicable to such data. Commented Sep 26, 2021 at 4:59

1 Answer 1

0

With the following contents in your platformio.ini file:

[env:...]

board_build.embed_txtfiles =
    data/file1.ext
    src/file2.ext

You can (and must) define the following variables in your C/C++ code to access the data. The asm(...) part is from ESP-IDF's documentation and it gets the address of the data. Each one will be null-terminated because you used embed_txtfiles rather than embed_files.

extern const uint8_t file_data_file1_start[] asm("_binary_data_file1_ext_start");
extern const uint8_t file_src_file2_start[] asm("_binary_src_file2_ext_start");

The names file_data_file1_start and file_src_file2_start can be any names, ESP-IDF's documentation just sets forth the convention that they're similar to the file paths.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.