For a long time I have been looking for a proper way to store websites on a ESP8266 / ESP32, and doing it in a easy way.
Goals for this project
- Simple to use
- Fast when making new code changes
- Reliable
- AND Works with external files
I wanted to be able to develop my website as i usually would, splitting the HTML, CSS and JS in different files. Also keeping the time needed to test the new website changes, at the minimum.
How it worksThe inspiration for this project comes from Stefan Kremser(Spacehuhn)'s Esp8266 deauther project after digging into this code, to figure out his way of serving a website on the esp8266.
Long story short, he used a shell script which checked each file in a /html directory then:
1. Used a online minifier, which matched the file extension.
2. Converted the minified text to hex.
3. Appended the hex version to a text file as an unit8_t array, ready to copy into your code.
Since that it's stated that his method works in Linux/Mac, and I couldn't get it to work in Windows. I made my own version with the same method using Python.
So the advantage of his method is that, you don't have to implement your CSS and javascript to be HTML inline. Also the output of the Python script, gives you a line of code for each file, which means you only have to update a single line in your code for the ESP.
Example:
An example can be found in the Github project: ESP-HTML-Compressor/Example
Known issuesImplementing small webfiles works without problems, but implementing Bootstrap and Jquery, seems to give problems.
Having files with punctuation in the filename(Not for the extension) also gives problems. Replacing them with underscores is a solution though.
Feel free to suggest changes on the Github project to fix those issues.
Other methods:I tried a few different methods so fare, none that quite satisfied my needs. I will list them here, just in case someone any how find them useful for their needs. Also included why they didn't work for me.
- Text to C/C++ String: Takes up to much storage of the ESP, could have been used for more code. Annoying to do with multiple files.
- Storing webfiles in SPIFFS: Failed serving multiple files crashed my ESP8266, when client requested multiple files at once. Might work for ESP32, due to the two cores, haven't tried.
(Feel free to leave a comment, if you have more possibilities that could be added)
Comments
Please log in or sign up to comment.