I'm working on a project where the user will need to be able to switch from running the DHCP server to running as a DHCP client. Basically the user will need to be able to connect a laptop directly with an Ethernet cable (DHCP server mode) to access the web pages running with MQX web server. But there also needs to be a mode where they can plug into a router or modem which would then assign an IP address(DHCP client mode).
I can get both modes to work fine if I do either one right at boot up but when I try to shutdown one mode and switch to the other it tends to become unstable and crash. I have looked through the documentation and tried to search the forums but have not found the correct procedure for shutting down either mode and starting up the other. Does anyone know how to shutdown the DHCP server and switch to DHCP client mode and vice versa?
To startup in DHCP server mode I have been doing:
At this point I can access the web page by connecting my PC to the Ethernet port. MQX will assign my PC and IP as expected. Then I try to switch to DHCP client mode.
shutdown(socket used by DHCP server)
Then startup client mode with:
At this point I can connect to a router and get an IP address. I can usually access the web page. Sometime accessing the web page will cause a crash but disconnecting the Ethernet cable almost always causes a crash.
Any idea what I have done wrong? I'm new to MQX so I probably did something wrong here.