Embedded HTTP Server (Hosting this Website)

Webserver Github | Website Github

Current Status— Stack: 2 / 4 KB | Heap: 217 KB free | DRAM: 73 / 332 KB

An embedded HTTPS webserver with no dependencies (besides the esp-idf networking stack) that this website is currently running on. The framework supports TLS, dynamic templating, GET/POST requests and url/form arguments.

The goal was to build a complete, highly efficient web stack that operates within strict memory constraints that I could host my personal website on. The server has near-instant response time and an extremely low power footprint (~1W).

System Architecture

Motivation

I originally hosted my portfolio website on GCP, but eventually got tired of paying the dollar and change each month in cloud computing costs. I decided I wanted to try hosting my website on my own hardware, both to get some experience setting up a webserver and not having to rely on cloud infrastructure.

My first iteration involved coding a webserver in C to run on an old linux machine I had. I developed a library using raw POSIX sockets that supported dynamic templating, url arguments and multiple request types. I eventually got this working, yet running this simple server on a full PC felt like overkill. I had an old ESP32 sitting around that I had always wanted to put to use, so I decided to give it a try. The server had to be adapted slightly to add Wifi driver support and FreeRTOS tasks, but I eventually got it up and running on the ESP. The ESP32 is responsible for serving the website itself. Because the ESP32 is located behind my home network, an Nginx reverse proxy handles the public-facing network layer and forwards requests to the ESP32.



Current setup under my bed.

Current Hardware

The server is built around an ESP32-WROOM-32 with 520 KB of internal SRAM, including approximately 320 KB of DRAM available for data and heap allocations.

The server runs directly on the ESP32 rather than inside Linux or another operating system. FreeRTOS is used for task scheduling and the ESP-IDF networking stack provides the underlying Wi-Fi functionality. The result is a complete web server running on a microcontroller with only a few hundred kilobytes of RAM.


Next Steps: Custom PCB

Custom PCB: I am currently in the process of designing a custom PCB for the server. The target microcontroller will be an ESP C3 which is very similar spec wise to the one I am using now so not many changes will have to be made software wise. The board is centered around the microcontroller, and includes the bare minimum to get the server working such as power supply and breaks out a USB-C port for power.


View the project github for more information.