Close

ESP8266 SD card webserver with server side scripting

A project log for Budget wi-fi nest box camera

Finding the cheapest way of getting a camera in a bird nest box, and then making it simple to use and install.

fractalFractal 12/21/2017 at 12:180 Comments

This log is to detail the requirements and challenges required of the wireless module. Fundamentally it is a webserver serving files from a microsd card and/or it's own flash memory. It also is sharing the SD card with another device, that the ESP8266 can power up and down.

There are several simple webserver examples out there: e.g. https://randomnerdtutorials.com/esp8266-web-server/

Or the much better: https://github.com/marcoskirsch/nodemcu-httpserver .

Nevertheless, there are several things the webserver needs to be able to do reliably, that the simple examples don't necessarily cover. (though Marcos Kirsch's one is pretty complete on the webserver front and does several of these things perfectly)

Some of the solutions here can be hacks, it's OK if say, the module resets after every picture, it's never going to be a fast experience. Some things set requirements for later on - for instance everything apart from images is staying on the ESP8266's flash.

The overall methodology I originally planned was to have lua commands embedded in html files, for some kind of .htmlua file. In that manner one file would be responsible for everything. However, this makes sending files quite complicated in that you have to scan for and buffer for commands every time the file is requested... it could get quite tricky.

Instead the preferred technique as used in the nodemcu-httpserver project is to have .lua files which individually do the whole connection (and send some dynamic HTML), and some static html pages. Any hyperlink can also have a GET request easily, that info can go into the scripts, but the bulk of the work will be with a set of static .html files and using .lua files as dynamic pages. They'll get a bit unwieldy, but should be readable. Headers and stuff repeated often can be hidden in a .lua file, and called as needed.

One obvious hard part is keeping the connection alive if the camera's taking many seconds to turn on. I don't want to go into dynamic web page content - the ESP8266 doesn't like having many simultaneous connections...instead it may simply have to either be slow, or show the previous image. Making a webpage auto-refresh is easy though.

For now, the best bet appears to be https://github.com/marcoskirsch/nodemcu-httpserver. If I do manage to fix any generic problems with it, it's open source so I could submit a pull request. 

Discussions