How to assign text stored in a local file to a string at compile time

I found another way to include a literal file (html, css, or other) and assign it to a constant string without resorting to make files:

Add one line of code on top of your html (css, js, etc) file, and another at the bottom, and save it with an extra .h extension. Then include that file in de Arduino IDE. This could easily be done by a (manually executed) script, every time those files are changed.

const char *indexHtml = R"====( // added by script
<html> <!-- original .html file -->
.
.
.
</html> <!-- end .html -->
)===="; // added by script

The variable name can be derived from the original filename. The result is saved with an extra .h extension. In the .ino (or .cpp) you can then include this file:

#include index.html.h

This will compile in the Arduino IDE.

Tags:

C

Web Server