2023-05-31 12:29 AM
Hi all
Currently, I am working on a project in which I have to design an application in such a way that it should support DHCP and static IP mode based on user choice. And this would be in FREERTOS. Users can back and forth between static and DHCP modes. Should it be possible?
If possible please suggest me a way.
@Piranha could you please help me?
2023-06-01 11:52 PM
This is not an STM32-specific issue; you need to refer to documentation to whatever TCP/IP stack you intend to use. Basically, you would need to stop/restart the link layer, whener you want to change the IP number; and you would need to run a DHCP client (which supposedly starts the link layer for you when it acquires an IP lease).
Don't expect this to be something simply clickable in CubeMX. You need to read the documentation and act accordingly.
JW
2023-06-02 12:10 AM
Following the things I did and it works for me.
ip4_addr_t ipaddr;
ip4_addr_t netmask;
ip4_addr_t gw;
// convert IP,subnet mast and gateway
IP4_ADDR(&ipaddr, ipData->ip[0], ipData->ip[1], ipData->ip[2], ipData->ip[3]);
IP4_ADDR(&netmask, ipData->netMask[0], ipData->netMask[1] , ipData->netMask[2], ipData->netMask[3]);
IP4_ADDR(&gw,ipData->getway[0], ipData->getway[1], ipData->getway[2], ipData->getway[3]);
netif_set_addr(&gnetif, &ipaddr, &netmask, &gw);
I took inspiration from this ttps://community.st.com/s/question/0D53W00000zHH9PSAW/changing-ip-address-mac-address-during-runtimee
2023-06-02 12:31 AM
As I've said, you'd need to restart the link layer, and essentially the whole stack. There's more in it than just setting the IP addresses.
For non-STM32-specific lwip questions such as this, you may try the lwip-users mailing list.
JW