4 ms·
My day job is web development but I love hacking on microcontrollers in my spare time. One project involved serving a static webpage from an ESP-8266. But how d
by thedanbob 7y ago
My day job is web development but I love hacking on microcontrollers in my spare time. One project involved serving a static webpage from an ESP-8266. But how do you server an HTML file without a filesystem? There's probably a better way, but my solution was to gzip the file and embed it as an array of raw bytes within the program.
- Koshkin 7y agoAs far as program resources go, on DOS, at least, it used to be possible to simply append a file to the executable, and the loader would put everything in RAM. (On the other hand, you do not need a generic web server to serve a single static page; then you don’t need a file system to store one file.)
- emily-c 7y agoThis is still pretty common for things like self extracting archives on Windows. copy /b "%windir%\system32\extrac32.exe"+inputarchive.cab selfextract.exe
- ronsor 7y agoYou can do that with most executable formats: MZ/NE/PE (DOS, Windows), ELF (Linux, BSD). Not sure about mach-o (macOS) though.
- wolf550e 7y agoDo you mean like Apache mod_asis [0] which will serve a pre-formatted HTTP response, including the headers, directly from disk? Then your HTTP server can speak very little HTTP (compare request line to preformatted "GET /file HTTP/", return 404 on mismatch, return preformtted response on match). Maybe also return nice error if request does not have accept-encoding: gzip. 0 - https://httpd.apache.org/docs/2.4/mod/mod_asis.html https://httpd.apache.org/docs/2.4/mod/mod_asis.html
- GTP 7y agoESP8266 has basic filesystem support, have a look at this: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html https://arduino-esp8266.readthedocs.io/en/latest/filesystem..... You define the filesystem's size when you flash the ESP and there's a tool to upload files there. You should also be able to find example projects that serve a webpage read from SPIFFS. Edit: this is a fake AP for esp8266 that I wrote some time ago that has a captive portal that loads pages from SPIFFS if they're there, otherwise sends some default pages directly from code https://github.com/GTP95/CaptivePortalMatematico?files=1 https://github.com/GTP95/CaptivePortalMatematico?files=1
- thedanbob 7y agoCool! I ended up switching to a raspberry pi for that particular project but I'll keep that in mind.
- deckard1 7y agohttps://github.com/me-no-dev/ESPAsyncWebServer#respond-with-content-coming-from-a-file https://github.com/me-no-dev/ESPAsyncWebServer#respond-with-... That whole ESPAsyncWebServer github project has a lot of great examples on ways to use the esp8266. Also, if you want to connect to your esp8266 externally, you can setup nginx (maybe on a raspberry pi?) as a reverse proxy with TLS enabled: https://jjssoftware.github.io/secure-your-esp8266/ https://jjssoftware.github.io/secure-your-esp8266/. Probably a bit pointless if you only have one esp8266 to connect to, since the RPi could probably do it all. But if you have multiple IoT devices to connect to, might be worth it.