AnsweredAssumed Answered

Switch between DHCP server and client

Question asked by seandema on Nov 21, 2013
Latest reply on Dec 6, 2013 by seandema

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:

RTCS_create()

ipcfg_init_device()

_io_tfs_install()

HTTPSRV_init()

ipcfg_bind_staticip()

DHCPSRV_init()

DHCPSRV_ippool_add()

 

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 with:

_task_abort(dhcp server)

shutdown(socket used by DHCP server)

ipcfg_unbind()

ipcfg_release_device()

 

Then startup client mode with:

ipcfg_init_device()

ipcfg_bind_dhcp_wait()

ipcfg_task_create()

 

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.

 

Thanks!

Outcomes