LWIP with Ethernet Cable Disconnected
I am using a Nucleo-F429ZI with FreeRtos and LWIP.
I am having an issue with LWIP when I start with a disconnected Ethernet Cable and then when I connect it back when the firmware is running.
I have a thread with the following code.
1 - The gnetif structure is initialized by MX_LWIP_Init(). But the function check
netif_is_up(&gnetif)
returns that the link is up even though the cable is disconnected.
2 - When I plug the cable back, the DHCP function does not acquire an IP Address. It seems stuck somewhere
3 - When the cable is connected and then I disconnect it, the gnetif.ip_addr.addr stays with the initial DHCP address instead of resetting to 0.
Any thoughts on what the issues might be ?
MX_LWIP_Init();
/* USER CODE BEGIN 5 */
firstTime = 1;
/* Infinite loop */
for(;;)
{
while (timer_update == 0);
timer_update = 0;
if (netif_is_up(&gnetif)) {
printf("Main Link is Up\n");
} else {
printf("Main Link is Down\n");
continue;
}
local_IP = gnetif.ip_addr.addr;
if (local_IP == 0) continue;
printf("IP Address: %s\n", ip4addr_ntoa(&gnetif.ip_addr));
if (client == NULL) client = mqtt_client_new();
osDelay(100);
if(client != NULL) {
if (!mqtt_client_is_connected(client)) {
printf("Connecting to Client\n\r");
corin_do_connect(client,local_IP);
} else {
corin_publish(client,"This is a Test");
}
osDelay(100);
}
}
