2025-10-18 11:20 AM
This is what my task looks like:
void StartMongooseTask(void const * argument)
{
/* init code for LWIP */
MX_LWIP_Init();
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();
while (netif_default == NULL || !netif_is_up(netif_default)
|| !ip4_addr_isany_val(*netif_ip4_addr(netif_default))
) {
osDelay(100);
}
extern struct dhcp_state_enum_t;
struct dhcp *dhcp_client = netif_dhcp_data(netif_default);
while (dhcp_client == NULL || dhcp_client->state != 10) {
osDelay(100);
}
ip = *netif_ip4_addr(netif_default);
printf("IP acquired: %u.%u.%u.%u", ip4_addr1(&ip), ip4_addr2(&ip),
ip4_addr3(&ip), ip4_addr4(&ip));
mdns_resp_init();
mdns_resp_add_netif(netif_default, "22223335", 3600);
mdns_resp_add_service(netif_default, "22223335", "_http",
DNSSD_PROTO_TCP, 80, 3600, NULL, NULL);
mdns_resp_announce(netif_default);
// --------------- mongoose ---------------
mg_log_set(MG_LL_DEBUG);
struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://0.0.0.0:80", http_handler, &mgr);
for (;;) {
mg_mgr_poll(&mgr, 10); // 10 ms polling
osDelay(1); // Yield to other FreeRTOS tasks
}
}
I am certain that the LWIP is getting a valid IP and advertising the service as expected, since I can ping to it. However, I cannot seem to access the http server. The mongoose (v7.19.0) functions are not returning errors, and it looks like they are set up correctly. The poll function will call the `http_handler`.
To try to integrate mongoose with LWIP, I set up the following flags:
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
#define MG_ENABLE_LWIP 1
I also tried to set MG_ENABLE_TCPIP to 0, but when I do so, I get compilation errors saying undefined reference to both mg_mgr_poll and mg_open_listener.
My board is the NUCLEO-F767ZI. Can anyone help me try to diagnose the problem and hopefully find a solution? Thank you
2025-10-18 1:49 PM
2025-10-18 2:47 PM
Thank you for the detailed reply, I made sure that both LWIP_SOCKET and LWIP_NETCONN were on, and that HTTPD is off.Setting MG_ENABLE_TCPIP to 0 on the mongoose_config.h file will always cause the compilation problem regarding the undefined references... I wonder if it is because MG_ARCH is set to MG_ARCH_CUBE, but I can't seem to change it to MG_ARCH_FREERTOS without hundreds of compilation errors showing up.
With the MG_ENABLE_TCPIP on, I see that mg_http_listen does not return a NULL, and I do get a message saying that it is listening: "11d7 3 mongoose.c:4072:mg_listen 1 0 http://0.0.0.0:80"
Changing the IP from 0.0.0.0 to the actual one didn't change anything, and similar regarding removing the osDelay in the for loop, but I suppose all of this is because MG_ENABLE_TCPIP should be 0. I'm not sure how to deal with these errors
2025-10-20 12:52 AM
Hi marrr,
An example of using Mongoose with LwIP and FreeRTOS can be found here in the official Mongoose repository. Moreover, there is this tutorial that guides you through integrating Mongoose with LwIP and FreeRTOS, please make sure you follow it carefully, especially the "FreeRTOS and LwIP integration section" (this is the most important step in configuring LwIP with the correct parameters).
In short, you only need to set MG_ARCH to MG_ARCH_FREERTOS and MG_ENABLE_LWIP to 1. Do not enable MG_ENABLE_TCPIP (which in turn enables the Mongoose built-in TCPIP stack, however you need MG_ENABLE_LWIP to use the LwIP stack). You also do not need to change the listening address, it is not necessary to be the same as your actual IP address assigned via DHCP.
Heads up: I am part of the Mongoose development team, I hope this helps you. If you encounter any other issues, feel free to let me know.
2025-10-21 1:35 AM
Hi :)
I have followed the tutorials carefully. As soon as I set MG_ARCH to MG_ARCH_FREERTOS in the mongoose_config.h file, I get hundreds of compilation errors. By default this flag is set to MG_ARCH_CUBE. Do you have any idea of why this might be happening?
2025-10-21 2:24 AM
These compile issues are weird, they shouldn't happen. Could you please attach zip with your project to take a closer look?
2025-10-21 2:32 AM
I attached a zip with the full project, or you can also see it here: https://github.com/immarianaas/stm32-experiments/tree/4-http-server (this branch, 4-http-server, is where I'm trying to integrate mongoose).
Thank you for looking into it!
2025-10-21 3:26 AM
I'm not sure exactly what happened, but with the following configuration in the mongoose_config.h file, it seems to work!
#define MG_ARCH MG_ARCH_FREERTOS
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
#define MG_ENABLE_TCPIP 0
#define MG_ENABLE_LWIP 1
I am sure I had tried this configuration before, but I used to change some of the flags (MG_ENABLE_TCPIP_DRIVER_INIT and MG_ENABLE_LWIP) in mongoose.h instead of mongoose_config.h, so I wonder if that is the reason why it didn't work.
Thank you so much for the support!
2025-10-21 3:34 AM - edited 2025-10-21 3:36 AM
Yes, exactly! I just had a look at your project. I only edited mongoose_config, enabled MG_ARCH_FREERTOS and MG_ENABLE_LWIP and the build works! You can also try to increase the heap size for FreeRTOS to 65536 (the guide shows you how to do it), I notice you left it at the default value, so it might cause some crashes if it's too small.
By the way, since you don't use Mongoose's built-in stack, you don't need to specify in mongoose_config.h the MG_ENABLE_TCPIP and MG_ENABLE_TCPIP_DRIVER_INIT macros, they are 0 by default :)
Also, the mongoose source files are not meant to be edited, the only changes you should make are in mongoose_config.h.
Happy to help!