{"id":4233,"date":"2026-02-21T05:56:09","date_gmt":"2026-02-21T05:56:09","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=4233"},"modified":"2026-02-21T05:56:10","modified_gmt":"2026-02-21T05:56:10","slug":"stm32-and-mongoose-web-server-part-3-create-simple-server","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=4233","title":{"rendered":"STM32 and Mongoose Web server Part 3: Create Simple Server"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-1024x683.png\" alt=\"\" class=\"wp-image-4234\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-1024x683.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-300x200.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-768x512.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-1150x767.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-750x500.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-400x267.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1-250x167.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/ChatGPT-Image-Jan-17-2026-at-10_13_02-AM-1.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Implementing the simple webserver.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Implementing the Simple Web Server:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Above the run mongoose function, declare the following event handler:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static void event_handler(struct mg_connection *c, int ev, void *ev_data) {\n  if (ev == MG_EV_HTTP_MSG) {\n    struct mg_http_message *hm = ev_data;  \/\/ Parsed HTTP request\n    mg_http_reply(c, 200, &quot;&quot;, &quot;ok, uptime: %llu\\r\\n&quot;, mg_millis());\n  }\n}<\/pre><\/div>\n\n\n\n<p>This will send the up time of the MCU. This will allow us to confirm if web server is up and running.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, before the infinite loop in run mongoose function, start the http listen as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">mg_http_listen(&amp;mgr, &quot;http:\/\/0.0.0.0:80&quot;, event_handler, NULL);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the run mongoose function is as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static void run_mongoose(void) {\n  struct mg_mgr mgr;        \/\/ Mongoose event manager\n  mg_mgr_init(&amp;mgr);        \/\/ Initialise event manager\n  mg_log_set(MG_LL_DEBUG);  \/\/ Set log level to debug\n\n  mg_http_listen(&amp;mgr, &quot;http:\/\/0.0.0.0:80&quot;, event_handler, NULL);\n\n  for (;;) {                \/\/ Infinite event loop\n    mg_mgr_poll(&amp;mgr, 0);   \/\/ Process network events\n  }\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Save, build and run the project as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"34\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1024x34.jpg\" alt=\"\" class=\"wp-image-4132\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1024x34.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-300x10.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-768x26.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1536x51.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1150x38.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-750x25.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-400x13.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-250x8.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13.jpg 1986w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. Results:<\/h2>\n\n\n\n<p>Open the web server and type the address of the mongoose and you should be able to see the up time as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"324\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-1024x324.jpg\" alt=\"\" class=\"wp-image-4235\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-1024x324.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-300x95.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-768x243.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-1150x364.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-750x238.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-400x127.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21-250x79.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/02\/2026-02-21_08-41-21.jpg 1244w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next part, we shall develop UI and control LED, display ADC values etc. <\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: 7. Implementing the Simple [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-4233","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4233"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4233"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4233\/revisions"}],"predecessor-version":[{"id":4236,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4233\/revisions\/4236"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}