
In this third part of the guide, we implement a minimal HTTP server using Mongoose on STM32 to validate end-to-end web functionality. The server will respond with the system uptime, confirming that the TCP/IP stack, Ethernet interface, and HTTP layer are operating correctly.
In this guide, we shall cover the following:
- Implementing the simple webserver.
- Results.
7. Implementing the Simple Web Server:
Above the run mongoose function, declare the following event handler:
static void event_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data; // Parsed HTTP request
mg_http_reply(c, 200, "", "ok, uptime: %llu\r\n", mg_millis());
}
}This will send the up time of the MCU. This will allow us to confirm if web server is up and running.
Next, before the infinite loop in run mongoose function, start the http listen as follows:
mg_http_listen(&mgr, "http://0.0.0.0:80", event_handler, NULL);
Hence, the run mongoose function is as follows:
static void run_mongoose(void) {
struct mg_mgr mgr; // Mongoose event manager
mg_mgr_init(&mgr); // Initialise event manager
mg_log_set(MG_LL_DEBUG); // Set log level to debug
mg_http_listen(&mgr, "http://0.0.0.0:80", event_handler, NULL);
for (;;) { // Infinite event loop
mg_mgr_poll(&mgr, 0); // Process network events
}
}Save, build and run the project as follows:

8. Results:
Open the web server and type the address of the mongoose and you should be able to see the up time as follows:

Next part, we shall develop UI and control LED, display ADC values etc.
Stay tuned.
Happy coding 😉
Add Comment