DeterministicESPAsyncWebServer
▲ 9 r/esp32+2 crossposts

DeterministicESPAsyncWebServer

An HTTP/1.1 web server for ESP32 with a fully deterministic memory footprint, RFC 7230 compliant request parsing, and an OSI-layered architecture. Should be on the Arduino registry tonight.

I'm actively working on it; docs, second optimization pass, adding assertions to tests, etc. I'm going to be adding more hw crypto support because I ultimately want to ssh into this.

I built this from the ground up to be different from the existing library. Please share your thoughts, use the library, and report any bugs by opening an issue.

My next project is going to be like a web based terminal using this deterministic async webserver, fully featured and free under agpl, I want it to look like telnet or ssh.

Happy coding!

Github: github

API Documentation: docs

Git: git

```txt
Features
Zero heap allocation *ever*. The event queue, connection pool, HTTP pool, WebSocket pool, and SSE pool are all statically sized in BSS; the entire memory footprint is fixed at link time
RFC 7230 compliant request parser validates method, path, header field-names, and field-values byte-by-byte before storing anything
WebSocket support (RFC 6455) SHA-1 handshake via mbedTLS hardware accelerator, frame parser, ping/pong/close handled automatically
Server-Sent Events persistent connections, per-connection and broadcast push
HTTP Basic Authentication per-route credential checking via mbedTLS base64
Static file serving chunked reads from any Arduino FS (LittleFS, SPIFFS, SD)
Multipart form-data parser in-place, no allocation, up to MAX_MULTIPART_PARTS parts
Compile-time feature flags strip unused subsystems entirely; a REST-only build includes none of the above
Compile-time configuration every buffer, pool, and timeout is a #define; illegal combinations produce #error messages
Diagnostic JSON endpoint optional DETWS_ENABLE_DIAG build-config dump, disabled by default for security
Backpressure-aware TCP shrinks the receive window instead of dropping data when the ring buffer fills
CORS preflight short-circuit OPTIONS answered with 204 automatically when CORS is enabled
restart() hard-resets all connections and reinitializes on the same port without touching the WiFi/TCP stack
321 tests across nine Unity test suites, runnable on native x86/x64 (no hardware required)
```
u/dstroy0 — 13 hours ago

made a tiny memory manager

So I kept running into the same problem, sketch works fine for a while then starts doing weird things, and after way too long debugging I'd figure out the heap had fragmented itself into uselessness. Arduino's malloc exists but you have no visibility into what it's doing without JTAG.

I wrote a library that lets you allocate from a fixed buffer you control instead of the global heap.

The API is pretty minimal: allocate, deallocate, reallocate, and two size queries. That's it. Sizes get rounded up to 4 bytes automatically and passing nullptr to deallocate or blockSize is tolerated.

MemoryManager mm(512);

void *p = mm.allocate(100);   // nullptr on failure
mm.deallocate(p);
void *p2 = mm.reallocate(p, 200);

It's nothing revolutionary, just a circular doubly-linked free list with coalescing, I figured someone else might find it useful. I uploaded the version I've been using locally to my public github.

MemoryManagerLite

One thing I'm not 100% sure about is how the block header size differences between AVR (2-byte pointers) and ARM Cortex-M (4-byte pointers) affect the overhead in practice — if anyone's tested allocator stuff across both architectures I'd be curious what you ran into.

test/ src test cases compile with g++. most of my libraries use an external C++17 test suite for unit testing the C++11 src/ so that you can write your own test cases and run tests without flashing a board.

Thanks for looking! ILet me know what you think.

u/dstroy0 — 20 days ago