How to store a File in Code memory

Hi,
I want to store a file which is of type ".html" to display the contents in web page.

So how do I say to compiler including an external file in to the code memory for displaying it, how ever currently I am using file system to store a file by doing FTP.

When I was using Dynamic c, it had a method to include external files in to the Source code.

1 Like

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for advice on (nor for problems with) your project.

Which arduino do you have?

Something like

const char myHTML [] PROGMEM {"
#include "myHTML.html"
"}
 
1 Like

Nice, it works like this:

const char buttonCss[] = {
#include "button.css"
};

But in the CSS file I have to use the raw literal, which uglyfies the file a bit:

R"(
/* dedicated button.css file, yeah! */
body {
    text-align: center;
}
)"

So, there would be 2 questions:

  1. How do I include the file so that it can be a "real" css file, without the C++'s raw string literal wrapping?
  2. How do I include it with PSTR() / F() macro (PROGMEM is only for global/static vars, cannot be used inside code blocks).

That won't work. You can't put a "#include" preprocessor statement inside a string.

I think the best solution is to change the "myHTML.html" file to "myHTML.cpp" and edit it to have:
const char myHTML [] PROGMEM {R"uniquetag(
at the top and
)uniquetag"};
at the bottom. That makes it a 'Raw' string and it can contain any sequence of characters except ")uniquetag".

In your sketch, declare it with:
extern char myHTML[];
If you use an Arduino that supports PROGMEM, be sure to treat it as a PROGMEM address.

Actually, it kinda works. Check out my comment above.

@bharadwajtke I have once again moved your topic back to the appropriate forum category. Please don't move it again.

In the future, please take some time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose. If you have read that topic, you would have known that the "Website and Forum" category you used is used for discussion of:

Improvements for the website, documentation, forum software, etc.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.