MOD5282 DHCP ...
MOD5282 DHCP ...
Hello,
I am working with the MOD5282 on a new project (we used to use Rabbit cores and hated them ). This project requires the unit to be capable of switching between static and dynamic IP addresssing. The initial provisioning of the unit will accomplished via the serial port, then future provisioning will most likely be accomplished via the web browser. I have most everything working on the unit, the serial port, TCP sockets (for remote automation control), the web browser. However, I am having an issue getting the MOD5282 to start up and obtain it's ethernet parameters via DHCP.
My network does have a router that is properly handing out DHCP. This has been confirmed via various PC's and other embedded devices. I have included the code block below that is run directly after "InitializeStack();" call in main. Everytime this block attempts to obtain the DHCP parameters it returns unsuccessful in that the DHCP server could not be found.
Any help would be greatly appreciated.
Thanks,
Mark
void StartEthernet()
{
//Get first interface identifier
int FirstInterface = GetFirstInterface();
//Get interface data
InterfaceBlock *ib = GetInterFaceBlock(FirstInterface);
//Check IP address for 0.0.0.0, and use DHCP if necessary
if (ib->netIP == 0)
{
iprintf("No static IP address set, attempting DHCP ...\r\n");
//The following lines of code are essentially what the GetDHCPAddress() function
//does to make the DHCP process easier.
pDHCPOfferName = "CTI RFPMU";
DhcpObj = new DhcpObject( FirstInterface );
DhcpObj->StartDHCP(); //Start DHCP
//Pend on semaphore to verify an address was obtained, waiting 30 seconds
if ( OSSemPend( &( DhcpObj->NotifySem ), 30 * TICKS_PER_SECOND ) == OS_TIMEOUT )
{
iprintf("\r\n*** WARNING ***\r\n");
iprintf("IP Address was set to 0.0.0.0, and a DHCP server could not be found.\r\n");
iprintf("Device does not have a valid IP address.\r\n");
}
else
{
iprintf("My DHCP assigned ethernet values are:\r\n");
iprintf("IP: "); ShowIP(ib->netIP); iprintf("\r\n");
iprintf("NetMask: "); ShowIP(ib->netIpMask); iprintf("\r\n");
iprintf("Gateway: "); ShowIP(ib->netIpGate); iprintf("\r\n");
iprintf("DNS: "); ShowIP(ib->netDNS); iprintf("\r\n");
iprintf("Interface Name: %s\r\n", ib->InterfaceName);
iprintf("\r\n");
bolDhcpAssigned = TRUE;
}
}
//Check DHCP flag
else if (bUseDhcp)
{
iprintf("\r\nDHCP flag set, attempting DHCP ...\r\n");
//The following lines of code are essentially what the GetDHCPAddress() function
//does to make the DHCP process easier.
pDHCPOfferName = "CTI RFPMU";
DhcpObj = new DhcpObject( FirstInterface );
DhcpObj->StartDHCP(); //Start DHCP
//Pend on semaphore to verify an address was obtained, waiting 30 seconds
if ( OSSemPend( &( DhcpObj->NotifySem ), 30 * TICKS_PER_SECOND ) == OS_TIMEOUT )
{
iprintf("\r\n*** WARNING ***\r\n");
iprintf("IP Address was set to 0.0.0.0, and a DHCP server could not be found.\r\n");
iprintf("Device does not have a valid IP address.\r\n");
}
else
{
iprintf("My DHCP assigned ethernet values are:\r\n");
iprintf("IP: "); ShowIP(ib->netIP); iprintf("\r\n");
iprintf("NetMask: "); ShowIP(ib->netIpMask); iprintf("\r\n");
iprintf("Gateway: "); ShowIP(ib->netIpGate); iprintf("\r\n");
iprintf("DNS: "); ShowIP(ib->netDNS); iprintf("\r\n");
iprintf("Interface Name: %s\r\n", ib->InterfaceName);
iprintf("\r\n");
bolDhcpAssigned = TRUE;
}
}
else
{
iprintf("My static assigned ethernet values are: ");
ShowIP(EthernetIP);
iprintf("\r\n");
bolDhcpAssigned = false;
}
}
I am working with the MOD5282 on a new project (we used to use Rabbit cores and hated them ). This project requires the unit to be capable of switching between static and dynamic IP addresssing. The initial provisioning of the unit will accomplished via the serial port, then future provisioning will most likely be accomplished via the web browser. I have most everything working on the unit, the serial port, TCP sockets (for remote automation control), the web browser. However, I am having an issue getting the MOD5282 to start up and obtain it's ethernet parameters via DHCP.
My network does have a router that is properly handing out DHCP. This has been confirmed via various PC's and other embedded devices. I have included the code block below that is run directly after "InitializeStack();" call in main. Everytime this block attempts to obtain the DHCP parameters it returns unsuccessful in that the DHCP server could not be found.
Any help would be greatly appreciated.
Thanks,
Mark
void StartEthernet()
{
//Get first interface identifier
int FirstInterface = GetFirstInterface();
//Get interface data
InterfaceBlock *ib = GetInterFaceBlock(FirstInterface);
//Check IP address for 0.0.0.0, and use DHCP if necessary
if (ib->netIP == 0)
{
iprintf("No static IP address set, attempting DHCP ...\r\n");
//The following lines of code are essentially what the GetDHCPAddress() function
//does to make the DHCP process easier.
pDHCPOfferName = "CTI RFPMU";
DhcpObj = new DhcpObject( FirstInterface );
DhcpObj->StartDHCP(); //Start DHCP
//Pend on semaphore to verify an address was obtained, waiting 30 seconds
if ( OSSemPend( &( DhcpObj->NotifySem ), 30 * TICKS_PER_SECOND ) == OS_TIMEOUT )
{
iprintf("\r\n*** WARNING ***\r\n");
iprintf("IP Address was set to 0.0.0.0, and a DHCP server could not be found.\r\n");
iprintf("Device does not have a valid IP address.\r\n");
}
else
{
iprintf("My DHCP assigned ethernet values are:\r\n");
iprintf("IP: "); ShowIP(ib->netIP); iprintf("\r\n");
iprintf("NetMask: "); ShowIP(ib->netIpMask); iprintf("\r\n");
iprintf("Gateway: "); ShowIP(ib->netIpGate); iprintf("\r\n");
iprintf("DNS: "); ShowIP(ib->netDNS); iprintf("\r\n");
iprintf("Interface Name: %s\r\n", ib->InterfaceName);
iprintf("\r\n");
bolDhcpAssigned = TRUE;
}
}
//Check DHCP flag
else if (bUseDhcp)
{
iprintf("\r\nDHCP flag set, attempting DHCP ...\r\n");
//The following lines of code are essentially what the GetDHCPAddress() function
//does to make the DHCP process easier.
pDHCPOfferName = "CTI RFPMU";
DhcpObj = new DhcpObject( FirstInterface );
DhcpObj->StartDHCP(); //Start DHCP
//Pend on semaphore to verify an address was obtained, waiting 30 seconds
if ( OSSemPend( &( DhcpObj->NotifySem ), 30 * TICKS_PER_SECOND ) == OS_TIMEOUT )
{
iprintf("\r\n*** WARNING ***\r\n");
iprintf("IP Address was set to 0.0.0.0, and a DHCP server could not be found.\r\n");
iprintf("Device does not have a valid IP address.\r\n");
}
else
{
iprintf("My DHCP assigned ethernet values are:\r\n");
iprintf("IP: "); ShowIP(ib->netIP); iprintf("\r\n");
iprintf("NetMask: "); ShowIP(ib->netIpMask); iprintf("\r\n");
iprintf("Gateway: "); ShowIP(ib->netIpGate); iprintf("\r\n");
iprintf("DNS: "); ShowIP(ib->netDNS); iprintf("\r\n");
iprintf("Interface Name: %s\r\n", ib->InterfaceName);
iprintf("\r\n");
bolDhcpAssigned = TRUE;
}
}
else
{
iprintf("My static assigned ethernet values are: ");
ShowIP(EthernetIP);
iprintf("\r\n");
bolDhcpAssigned = false;
}
}
Re: MOD5282 DHCP ...
Does the device DHCP when you load the factory application.... or any of the example applications?
Re: MOD5282 DHCP ...
Although it's been a while... I seem to remember having difficulties with DHCP when using pDHCPOfferName.
bb
bb
-
- Posts: 513
- Joined: Sat Apr 26, 2008 7:14 am
Re: MOD5282 DHCP ...
Use IPsetup to configure the module's IP to be 0.0.0.0. If the module's IP is not 0.0.0.0, it assumes you've set it for a static IP and will not attempt DHCP.
Then add this code to the top of UserMain:
if ( EthernetIP == 0 )
{
iprintf( "Trying DHCP\r\n" );
GetDHCPAddress();
iprintf( "DHCP assigned the IP address of :" );
ShowIP( EthernetIP );
iprintf( "\r\n" );
}
Then add this code to the top of UserMain:
if ( EthernetIP == 0 )
{
iprintf( "Trying DHCP\r\n" );
GetDHCPAddress();
iprintf( "DHCP assigned the IP address of :" );
ShowIP( EthernetIP );
iprintf( "\r\n" );
}
- Chris Ruff
- Posts: 222
- Joined: Thu Apr 24, 2008 4:09 pm
- Location: topsail island, nc
- Contact:
Re: MOD5282 DHCP ...
Why are there more than one instance of DHCP object?
I have code that retries DHCP on a periodic basis when a DHCP server is not available. I instantiate a DHCP object and Start() and Stop() it as required. The offer name bit is mostly useless as you have to have a DHCP server that talks with the DNS server to hand your host name over (and most don't).
One solution I have used:
Create a task with a state machine that pays attention to the EthernetIP value. If it is 0.0.0.0 the state machine should Start DHCP and wait on the semaphore. If that fails, either fall back to an earlier configured static IP or generate a link-local IP address (169.254.x.x) and retry DHCP over and over periodically until you obtain a lease. Keep falling back to the other IP addresses until you get the IP from DHCP.
Chris
I have code that retries DHCP on a periodic basis when a DHCP server is not available. I instantiate a DHCP object and Start() and Stop() it as required. The offer name bit is mostly useless as you have to have a DHCP server that talks with the DNS server to hand your host name over (and most don't).
One solution I have used:
Create a task with a state machine that pays attention to the EthernetIP value. If it is 0.0.0.0 the state machine should Start DHCP and wait on the semaphore. If that fails, either fall back to an earlier configured static IP or generate a link-local IP address (169.254.x.x) and retry DHCP over and over periodically until you obtain a lease. Keep falling back to the other IP addresses until you get the IP from DHCP.
Chris
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand
- NetBurnerGroup
- Posts: 11
- Joined: Thu Apr 24, 2008 4:08 pm
Re: MOD5282 DHCP ...
A couple of points and things to try:
- Run the factory app as suggested earlier, just to verify the dhcp server is working properly.
- pDhcpOfferName is just an option that is included in the dhcp request packet, so it should not have any effect on functon.
- If you use GetDhcpAddress() only call it once. It will start a process that will continually try to get a dhcp address, renew, etc. If you use this function, you cannot use any of the lower level dhcp calls, such as the one to stop the dhcp process.
- If you are creating a user interface that enables a user to enable/disable dhcp and choose between dhcp and static addressing, then you need to create your own dhcp object, as described in the NNDK Programmers Guide ChangeIP example. It sounds like this is where you got your code from. Only create one object, as mentioned by Chris. This scheme works very well, and is used by all our serial to ethernet devices.
- The best way I have found to troubleshoot this type of thing is with wireshark. You can set the filter to ip.addr==x.x.x.x, where the x's are your device's ip address. You can then see the dhcp exchange and quickly determine if the dhcp server is seeing the dhcp request packets. Wireshark will show the packet type as dhcp, so its easy to spot.
- Running the ChangeIP example has a lot of diagnostics and menus to put the netburner in various dhcp modes. Great for experimenting and testing with you specific network configuration.
Thanks for using netburner over rabbit! Hope this helps.
- Run the factory app as suggested earlier, just to verify the dhcp server is working properly.
- pDhcpOfferName is just an option that is included in the dhcp request packet, so it should not have any effect on functon.
- If you use GetDhcpAddress() only call it once. It will start a process that will continually try to get a dhcp address, renew, etc. If you use this function, you cannot use any of the lower level dhcp calls, such as the one to stop the dhcp process.
- If you are creating a user interface that enables a user to enable/disable dhcp and choose between dhcp and static addressing, then you need to create your own dhcp object, as described in the NNDK Programmers Guide ChangeIP example. It sounds like this is where you got your code from. Only create one object, as mentioned by Chris. This scheme works very well, and is used by all our serial to ethernet devices.
- The best way I have found to troubleshoot this type of thing is with wireshark. You can set the filter to ip.addr==x.x.x.x, where the x's are your device's ip address. You can then see the dhcp exchange and quickly determine if the dhcp server is seeing the dhcp request packets. Wireshark will show the packet type as dhcp, so its easy to spot.
- Running the ChangeIP example has a lot of diagnostics and menus to put the netburner in various dhcp modes. Great for experimenting and testing with you specific network configuration.
Thanks for using netburner over rabbit! Hope this helps.
Re: MOD5282 DHCP ...
Thanks to everyone for comments and help. Just to comment on some of the inputs:
1. Regarding reply from lgitlitz - The MOD5282 device did DHCP with the factory demo application, but has never done so since I set a static IP address.
2. Regarding replies from bbracken and Ridgeglider - I will attempt to force the static IP address to 0.0.0.0 to see if it will successfully negotiate DHCP again (update this thread again).
3. Regarding reply from Chris Ruff - Unless I screwed the code up in "void StartEthernet()", the if/else if statements only creates the DHCP object once, although the create object line appears twice. The reason for this code is that I had wanted to trap on the case of no IP address being set and a boolean flag stored in user flash (set via stdio and/or the web page). I will try your input to keep falling back to other IP addresses until I get the IP from DHCP.
4. Regarding reply from NetBurnerGroup - I re-ran the factory demo application, used MTTY to set the IP address to 0.0.0.0 (along with the netmask, DNS, and gateway), rebooted the MOD5282 and saw that it was trying the get a DHCP address but never acquired. I then went over to the NetBurner IPSetup utility to get control back on the MOD52582; the utility did find the device but stated that it was DHCP'd at 0.0.0.0. I reset back to 192.168.1.10. I then open, compiled and downloaded the ChangeIP example and instructed it to start the DHCP client service. The result came back that the IP address was set to 0.0.0.0 and that the DHCP server could not be found.
I will download WireShark and see if I get get some detailed information on what is going across the wire.
1. Regarding reply from lgitlitz - The MOD5282 device did DHCP with the factory demo application, but has never done so since I set a static IP address.
2. Regarding replies from bbracken and Ridgeglider - I will attempt to force the static IP address to 0.0.0.0 to see if it will successfully negotiate DHCP again (update this thread again).
3. Regarding reply from Chris Ruff - Unless I screwed the code up in "void StartEthernet()", the if/else if statements only creates the DHCP object once, although the create object line appears twice. The reason for this code is that I had wanted to trap on the case of no IP address being set and a boolean flag stored in user flash (set via stdio and/or the web page). I will try your input to keep falling back to other IP addresses until I get the IP from DHCP.
4. Regarding reply from NetBurnerGroup - I re-ran the factory demo application, used MTTY to set the IP address to 0.0.0.0 (along with the netmask, DNS, and gateway), rebooted the MOD5282 and saw that it was trying the get a DHCP address but never acquired. I then went over to the NetBurner IPSetup utility to get control back on the MOD52582; the utility did find the device but stated that it was DHCP'd at 0.0.0.0. I reset back to 192.168.1.10. I then open, compiled and downloaded the ChangeIP example and instructed it to start the DHCP client service. The result came back that the IP address was set to 0.0.0.0 and that the DHCP server could not be found.
I will download WireShark and see if I get get some detailed information on what is going across the wire.
Re: MOD5282 DHCP ...
I have attached a WireShark capture session to this post, the capture was performed using the ChangeIP example to "6. Start DHCP Client Service ..." .
- Attachments
-
- MOD5282 DHCP Capture.zip
- (2.15 KiB) Downloaded 529 times
Re: MOD5282 DHCP ...
Ok, I just performed a reboot of our router (Actiontec MI424WR) and used the ConfigIP demo application to switch the MOD5282 in DHCP mode (menu item #6). The unit DID switch over to DHCP mode and acquired an address from the router as expected. I switched the unit back and forth between DHCL and static addressing using the ConfigIP and IP Setup Tool applications a few more times without any issues.
I am not sure what caused my initial issues with DHCP, but I suspect that somehow the router would no longer listen to the MOD5282 DHCP requests. I will continue to test this issue and report back.
I am not sure what caused my initial issues with DHCP, but I suspect that somehow the router would no longer listen to the MOD5282 DHCP requests. I will continue to test this issue and report back.
Re: MOD5282 DHCP ...
I didn't look at your capture, but did you get any reply from the dhcp server when it was not working? For example, did it send a message saying it could not provide the address?