cancel
Showing results for 
Search instead for 
Did you mean: 

httpd not working after IP changed at runtime (no rtos)

FDe V
Associate

Hi,

I'm trying to implement a webpage to change network parameters (IP, Gateway, netmask) on nucleo-F429ZI

If i change parameters before httpd_init() is called, all works ok: the board responds to the ping, and the httpd returns the webpages. But if I call httpd_init(), and after I change network parameters, the network interface responds to ping on the new address until I try to request a webpage. When I request a webpage, httpd go to timeout and the board not respondig to ping.

this is the code to change network parameters:

          netif_set_down( &gnetif );

           IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);

           IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);

           IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);

           netif_set_addr(&gnetif,&ipaddr,&netmask,&gw);

           if (netif_is_link_up(&gnetif))

           {

             netif_set_up(&gnetif);

           }

           else

           {

             netif_set_down(&gnetif);

           }

thank you

1 REPLY 1
toroid
Associate III

Hi, I think you might be overdoing it. Ip address change does not need so much configuration when done after the interface has been initialized.

I am using the following function to do it after initialization by cubemx generated code. I have this function inside lwip.c so that gnetif is available there as global. You can put this inside /* USER CODE BEGIN 2 */ on the top, so it's safe to regenerate.

/** Set new ip address to ethernet

 * @param addr is the new ip address as a string, eg 192.168.1.1

 * @param netmask is the new netmask address as a string, eg 255.255.255.0

 */

void setIpAddr(char* addr, char* netmask)

{

   ip4_addr_t newip, newMask;

   if (ip4addr_aton(addr, &newip))

   {

      netif_set_ipaddr(&gnetif, &newip);

   }

   if (ip4addr_aton(netmask, &newMask))

   {

      netif_set_netmask(&gnetif, &newMask);

   }

}

More details in lwip docs:

https://lwip.fandom.com/wiki/Network_interfaces_management