mongoose
Embedded web server, with TCP/IP network stack, MQTT and Websocket
A tiny two-file C networking library for embedded devices and microcontrollers that provides HTTP, WebSocket, MQTT, TCP, and TLS 1.3 in one portable package, including its own TCP/IP stack for systems with no operating system.
Mongoose is a networking library written in C that lets you add internet connectivity to embedded devices and microcontrollers. It provides the building blocks for HTTP servers and clients, WebSocket connections, MQTT messaging (commonly used in IoT devices), UDP and TCP communication, and built-in TLS 1.3 encryption. The library has been in use since 2004 and is described as running on systems ranging from commercial industrial equipment to hardware on the International Space Station.
One of its main selling points is that it fits inside very small devices with tight memory constraints. Adding Mongoose to a project requires copying just two files: mongoose.c and mongoose.h. It ships with its own built-in TCP/IP stack, which means it can run on microcontrollers that have no operating system at all. For chips from STM32, NXP, Microchip, Texas Instruments, Renesas, and others with built-in Ethernet hardware, Mongoose can handle all networking without any additional libraries. It can also run on top of existing stacks like lwIP or Zephyr when those are already part of the system.
Programming with Mongoose follows an event-driven pattern. You write a callback function that responds to different types of events (an incoming HTTP request, an MQTT message arriving, a connection closing), register it with an event manager, and run a polling loop. The README shows short examples: a web server that serves files from a directory, a REST endpoint that returns the current time, and an MQTT client that subscribes to one topic and echoes messages to another. Each example fits in roughly 20 lines of C.
The library is dual-licensed: GPLv2 for open-source projects and a commercial license for proprietary products. It is cross-platform and also builds on Linux, macOS, and Windows, which makes development and testing on a workstation straightforward before deploying to a target device.
Where it fits
- Add an HTTP REST API to an STM32 or NXP microcontroller running without an operating system by copying just two files into your project
- Build an MQTT IoT client on an embedded device with built-in TLS 1.3 encryption using an event-driven callback model