ESP8266 File System

While I still try to get my head around the two different DNS servers I thought it was about time to write another tutorial. In this tutorial I'm going to discuss the use of the Serial Peripheral Interface Flash File System (SPIFFS). This handy library lets you store files on the flash memory of the device. So instead of having to construct a HTML string as a response to a request we can serve up a standard web page.

To use SPIFFS you need to include the file "fs.h" at the top of the program and in the setup function you need to start the SPIFFS library using the 'begin' function. This initialises the library and allows you to access any files that are contained within the flash memory. For the purpose of debugging I tend to loop through the file system to list all the files contained on the device. The following lines of code retrieve a reference to the directory structure and then outputs all the files names to the serial port.
Finally we need to put this file system to use. The web server library is able to serve web pages directly from the file system rather than having to construct a new response each time. In this case we instruct the web server to respond to a root request with the index.html page directly from SPIFFS. Using this method you can write a web page in sensible editor, test it in your browser all without ever having to connect to the ESP device.
Here the complete code for a simple web page server, the next issue is how to get the files onto the device in the first place.
ESP8266FS is a tool that can be used to create file system images and upload them to the ESP device. It integrates with the Arduino IDE so it's easy to use. To install the tool you simply create a folder called 'Tools' in your arduino sketchbook directory, and unpack the zipped file into it.

Now when you open the Arduino IDE there should be an additional option in the 'Tools' menu system. ESP8266 Sketch Data Upload. If you create a folder called 'Data' next to your arduino sketch, then the tool will convert any files in that folder, into an image and send them to the file system on the device.

Popular posts from this blog

Wine Bottle Gift Boxes

Final 48 hours for Kickstarter

Laser Cut Cryptex