Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

natep

Member Since 14 Aug 2012
Offline Last Active Aug 27 2012 05:32 PM
-----

Topics I've Started

Insights into DHCP issues

15 August 2012 - 06:00 PM

The following summarizes a test that I have done regarding DHCP on the netduino plus. The test was done using .NET Micro Framework 4.2 QFE2 and Netduino v4.2.0 RTM firmware. (Tests were also tried using earlier versions with the same results.)

I have been working on getting a Netduino Plus working for the first time. One obvious first step is to get the netduino to obtain a IP from a DHCP server on my network. Like many others who have posted in this forum, I instantly had problems. The solutions posted for most situations is to use a static IP. This is unacceptable for many purposes.

I think that I have found one major bug and would like to report it for the community.

I wrote a simple routine that waits for the netduino to get a DHCP address as follows:

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.Text;

namespace TestEthernet
{
    public class Program
    {        
        public static void Main() {            
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];
            NI.EnableDhcp();
            int sec = 0;            
            while (NI.IPAddress == "0.0.0.0")
            {
                string msg = "Waiting for DHCP for " + sec + " sec.  IP="+ NI.IPAddress.ToString();
                Debug.Print(msg);
                Thread.Sleep(5000);
                sec += 5;
            }
            Debug.Print("Got IP" + NI.IPAddress.ToString());                             
        }
    }
}

If you run this code using the Visual Studio debugger or monitor the output using MFDeploy.exe. You will see that the output indefinitely echoes "Waiting for DHCP for XX sec. IP=0.0.0.0". This would lead you to believe that the netduino is having problems with your network and/or DHCP server.

Here is the crux: In reality, the netDuino IS obtaining a DHCP address.

Purely by accident, I happened to notice the MFDeploy console window during testing. Take a look at the attached screenshot from MFDeploy. It shows that the netduino IS obtaining a DHCP IP address from my network after about 30 seconds, but the value at "NI.IPAddress" does not change. So the code above never exits the while loop because it never realizes that the IP address has been obtained. I have not been able to find any other method within the .NET Micro Framework to find the current IP address. It seems to me that there is a major bug here.

The only work around that I found is to put an arbitrary wait (like "System.Threading.Thread.Sleep(60000);") into my code before beginning to use the network. (If you don't wait for the DHCP address to resolve, your application could potentially throw connection exceptions like 10065 "Host unreachable".)

I was completely confused by the fact that many developers in the forums have applications that seem to be using DHCP successfully, while many others can never get it to work. My guess is that developers are falling into two categories:

1) Obliviously lucky developers. They didn't know that they should check whether the IP address is resolved, so their application is running successfully because they never check it.

2) Developers assuming that NI.IPAddress is valid. Like me (having previous experience programming microcontroller network stacks), they check the IP address using NI.IPAddress and therefore assume that DHCP is not working--when in fact, it is working.

People falling into the second category are a real PR problem for the netduino plus. They just assume that there are major network problems with it and change to a different microcontroller. One of my co-workers did this exact thing.

ONE IMPORTANT FINAL NOTE: I had to use MFDeploy to set the IP address to "0.0.0.0" and use "Enable DHCP" before running my code. I have not been able to fully understand (1)how MFDeploy knows that the IP address has changed (as shown by the screenshot), or (2) whether the functions like "NetworkInterface.EnableDHCP" are even working correctly in the code. It seems that the settings saved to the netduino using MFDeploy->Target->Configuration->Network are the only ones that I completely trust. I suspect that there are copied network properties in the firmware and RAM and they are not properly copying to each other--BUT this is purely speculative as I haven't looked at the source.

Hope this helps others with their DHCP problems. Hope the netduino team can get this sorted out in the future.

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.