Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Generating char arrays from HTML source (Read 354 times)
NF1Z
Junior Member
**
Offline


Posts: 60
Joined: Aug 18th, 2013
Generating char arrays from HTML source
Sep 9th, 2026 at 9:05pm
Print Post  
Hi.  I'm adding a new webpage to an esp32 project.  The html is to be stored in flash as a compressed char array.  I have a python script that does the conversion job but I'm having much trouble getting html source code changes integrated into the project build.  Google AI has had me going round the world all day and getting nowhere.

I've had enough of that.  It occurs to me that not only is this a common task, but also that the only thing an IDE really does is handle source code changes, so there must be a standard approach to this problem.  Is there??

Many thanks!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12240
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Generating char arrays from HTML source
Reply #1 - Sep 9th, 2026 at 10:11pm
Print Post  
I think most people add the html file to the data folder then use upload data feature. then use the file system on the esp32 to read the file.

Esp32 is in out docs. Maybe it will be helpful?

https://www.visualmicro.com/page/Espressif-ESP32-Overview.aspx



  
Back to top
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 60
Joined: Aug 18th, 2013
Re: Generating char arrays from HTML source
Reply #2 - Sep 10th, 2026 at 1:20am
Print Post  
Tim,
Thanks for the reply.

Most of my app puts the HTML in files in the LittleFS, which is quite convenient, until you run out of space.  However, I'm replacing AsyncElegantOTA to try and improve robustness.  One factor is the use of LittleFS, or rather it's tendency to corruption.  For OTA, reliability seems best served by putting the html (minified and compressed) into a char array, requiring no extra data transfers.  However, it then gets complicated to develop with multiple steps to convert an HTML file to a C++ header file. Basically, you edit the html, run it through a python script to minify, compress and output a .h file, then build.

My initial approach was to put a prebuild hook in board.txt to call the python script.  This is still the best so far, but it seems to take two builds for an html edit to become effective.  Google AI gave several different reasons for this, to do with the relative timing of the build process, but nothing worked.  Their latest suggestion is  that it can't be done in Visual Micro and suggested basically running a python script in the background looking for changes to the specific file...

So I am asking the experts:  how can I automate the incorporation of html file edits in to the final build as char arrays?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12240
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Generating char arrays from HTML source
Reply #3 - Sep 10th, 2026 at 2:54am
Print Post  
ah thanks for the info. I think the ai is wrong. visual micro supports the arduino build hooks system, and makes it easier to access, and includes a few extra.

if you enabled the show build properties mentioned near the top of this forum (yellow) then build. you will see all the build properties. they are the available variables plus std. visual studio properties are also available.

https://www.visualmicro.com/page/Arduino-Build-Events-and-Hooks.aspx

you can add then to a board.txt file in your project folder. or to the standard arduino locations. it would see them too but more cumbersome to maintain.

does that help?

questions

how did you specify the hook for the test you made?

which ai system did you use?
  
Back to top
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 60
Joined: Aug 18th, 2013
Re: Generating char arrays from HTML source
Reply #4 - Sep 10th, 2026 at 5:29am
Print Post  
I admit to being pretty ignorant of the recipe system.  From what I can gather, and this is what AI (Google's) was telling me, was that the list of files to be compiled (and this list is just C++ files) is determined before any of the recipes are invoked.  I guess from dependencies, relative timestamps and such.  What this implies to me is that there is no way a recipe can add or change a C++ file in regard to its presence in the list to be compiled.  This would explain the need to build twice:  first time, the recipe python script creates the .h file but if it is not already in the list for a prior change, it will not change the dependencies that have been determined already; the second time, it will be seen as changed before any recipe are run so will be incorporated.

Consider another point of view:  suppose the only change you make is to the html file.  When checking the dependencies, none will be found, since only C++ files are considered.   The build log will show only  "Using previously compiled file", but the hook will be executed and the .h file will be generated.  The linker, uploader,... will also run.  On the next build, .cpp files dependent on the .h file will be compiled.  This is exactly what my build logs showed.

Anyhow, this is my board.txt line:
Code
Select All
recipe.hooks.prebuild.0.pattern=python3 "{build.project_path}\gzip_html.py" "{build.project_path}" 


and it exhibits the double-build features I described.  I've had a look at the link you sent me, and I can't see any means for doing something before dependencies are determined.  Please correct me if I am wrong.  I am still hoping someone has a solution for this:  I would have guessed it's a pretty common thing.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12240
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Generating char arrays from HTML source
Reply #5 - Sep 11th, 2026 at 8:40pm
Print Post  
some toolchains write extra files to the build folder. these are detected. try creating files in build.path

it's always good to bear in mind that the way libs are referenced in arduino projects (without paths), means the build happens in a temp folder after copying all sources over. Therefore it's the temp folder that is important for any file changes.

we will review the docs. The ai should know all these things.
« Last Edit: Sep 13th, 2026 at 9:24pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint