Is a file system required to make an http web service?

Hi there! I have a question pertaining to the http web server example freeRTOS provides.
I would give a link, but new users cannot do this. It’s the one underneath TCP and FAT examples.
I noticed it uses an SD card to store the http files and lots of other examples online do this as well. My question is basically why? Is it not possible or undesirable to use the internal memory of the microcontroller? And furthermore, if it is possible to put html files directly into the program memory, then how the heck does that work? Would I need to format a portion of the program memory to act as a file system? How would I store and access the html files?

Thanks in advance! I have so many questions and no other professionals to consult.

I think the biggest part is that a HTTP request includes a “resource” to request from the server, and a file system is the simplest way to express an assortment of resources to provide (if the content is mostly static).

Do you know if a file system is required? Or is it just really difficult not to have a file system, but still possible?

It is definitely not impossible. Other network middleware packages such as Kadak’s KwikNet have used things like virtual file systems that contain the HTML templates to be filled with the dynamic info at run time. As Richard pointed out, a file system is a somewhat natural way to represent Web page contents, so when present, it is generally the first choice.

Thank you so much for the information! One last question… If I wanted to put a file system on my microcontroller, what’s a good way to do it? Do I format part of the program memory to be a small file system? I’ve never done anything like that before. What are the basics to get started with that?

Have you tried FREERTOS+FAT? I haven’t used it yet, but it is supposedly fairly stable.

In the past I had used several middleware file system packets, both free/OS and commercial. The one recommendation I have whichever one you choose is to test it well under fringe conditions, ie fill it up to the rim and see what happens.

You can have const strings that hold the HTML built into your application code, if the pages are fixed, then have file requests find the correct string.

1 Like

I thought FreeRTOS+FAT needed an SD card??? Can you choose where the file system goes? Would be great if I could just partition part of program memory.

Hi Giselle,

according to this here documentation, FreeRTOS+FAT can also be backed by a NAND flash chip or purely in RAM, but I’m sure someone with more first hand experience will chime in and clarify.

You can have const strings that hold the HTML built into your application code, if the pages are fixed, then have file requests find the correct string.

(by @rtel )

I found this strategy very interesting, but I’ve got a question about memory consumption: Do constant strings embedded (compiled) in the program need to be loaded to RAM in order to be sent via HTTP to the client? I wonder if it’s possible to send big HTML pages from a highly constrained memory device.

Thanks in advance.

When you store the HTML pages in flash, they don’t consume any ARM:

static const char web_page[] = "blablabla";

You can pass this pointer directly to eg. FreeRTOS_send() so it will be delivered to the client.

I remember one exceptional platform on which this was complicated: ATmega by Atmel. But that is most probably noy the platform you are using.

1 Like

@RAc wrote:

Have you tried FREERTOS+FAT? I haven’t used it yet, but it is supposedly fairly stable.

Yes FREERTOS+FAT is indeed very stable. It supports FAT12, FAT16, and FAT32.

@RAc also wrote:

according to this here documentation, FreeRTOS+FAT can also be backed by a NAND flash chip or purely in RAM, but I’m sure someone with more first hand experience will chime in and clarify.

You can store a FAT filesystem on a NAND drive, unless you’re doing frequent changes.
It does have a RAM-disk driver, which can use any size of RAM.

Thanks, Hein. Indeed we’re using a ESP32 SoC with 512KB RAM (most part of it already in use by the program) and we intend to serve a web application, around 2 MB big, from flash memory.

Happy New Year!