Main Site Documentation

G400D DHCP test


#1

Hi Everyone

I am attempting to have a reliable ethernet communication using G400.

Here’s the dummy code I wrote just to test DHCP features.

using System;
using Microsoft.SPOT;
using GHI.Networking;
using System.Threading;
namespace TestDHCP
{
    public class Program
    {
        public static void Main()
        {
            var eth = new EthernetBuiltIn();
            eth.Open();
            eth.NetworkInterface.EnableDhcp();
            while (eth.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP");
                Thread.Sleep(250);
            }
            Debug.Print(eth.IPAddress.ToString());
        }
    }
}

I am really surprised by the behavior of the system. Sometime it works, sometimes not.
When it fails obtaining the DHCP lease, I notice on WireShark only the discover and offer message.
Sometimes the board becomes unresponsive (Device not found or cannot be opened -USB:Gadgeeter). The only way to get the board back is to press the reset button on the HDR board.

How can this be so unreliable? What I am doing wrong?

Does someone can test this code and run it several time and reports its results?


#2

GHI stuff now doesn’t like enabling DHCP when it is already enabled. Try putting an “If” statement before enabling.


#3

I’ll try that…


#4

It does not work. I also try to enable staticIP before enablingdhcp without better results:

using System;
using Microsoft.SPOT;
using GHI.Networking;
using System.Threading;
namespace TestDHCP
{
    public class Program
    {
        public static void Main()
        {
            var eth = new EthernetBuiltIn();
            int it = 0;

            while (true)
            {
                if (it == 0)
                {
                    if (eth.Opened)
                    {
                        Debug.Print("closing interface");
                        eth.Close();
                    }
                    eth.Open();
                }
                if (!eth.IsDhcpEnabled)
                    eth.NetworkInterface.EnableDhcp();
                else eth.RenewDhcpLease();
                int i = 0;
                while (eth.IPAddress == "0.0.0.0" && i < 10)
                {
                    Debug.Print("Waiting for DHCP");
                    Thread.Sleep(1000);
                    i++;
                }
                Debug.Print("IP DHCP" + eth.IPAddress.ToString());
                eth.EnableStaticIP("192.168.1.65", "255.255.255.0", "192.168.1.2");
                Debug.Print("IP Static" + eth.IPAddress.ToString());
                Thread.Sleep(500);
                it++;
                if (it == 5)
                {
                    it = 0;
                }
            }
        }
    }
}

I should mention that sometime it works sometimes not, when it works the code succeed to obtain an ip for an infinite number of iteration, when it fails it fails forever until restarting the board (using VS) several times. I will try to make the same experiments without attaching the VS debugger.


#5

It seems that the problem comes from attaching the debugger. If I just use FEZ config the dhcp client works properly. Any help from GHI would be appreciated…


#6

Don’t call RenewDhcpLease(), G400 doesn’t like it as well.

Is it BuiltIn ethernet, or Enc28 one?


#7

It’s builtin one. From what you say G400 does not like anything related with networking…
I thought all was solved in 4.3… this seems not to be the case… it’s a pain to have networking stuff that work and a huge waste of time.

This seems to be reproducible. The dhcp client fails often when the debugger is attached while it works when I just monitor Output information using FEZ Config.


#8

Aaaaaaaaaahhh, BuiltIn…


#9

??? aaaaaaaaaaaaaaaAAAAAAAAaaaaaaahhhHHHHHHHHHH

You scare me!


#10

BuiltIn is tricky, I somewhat regret moving to it. It is drawing lots of power, so one has to be careful designing supply circuits. It interferes with firmware at startup, so debugger cannot attach. It doesn’t like certain types of resets, so, for example, my program starts like this:

 //With BuiltIn ethernet, I see some terrible general slow down if PCB has just been plugged in.
            //Things get normal on additional reset; this is what I do here.
            var quickResetRegister = new Register(0xFFFFFE04);
            var quickResetValue = (quickResetRegister.Value >> 8) & 7;
            if (quickResetValue == 1) PowerState.RebootDevice(false);

#11

@ leforban - All of our tests have worked fine for DHCP + G400 + Built in Ethernet, but we will take a second look.


#12

Ok John for the moment I have weird problems with the board, sometimes I can’t deploy, sometimes dhcp fail, I even tried to set static ip without any success for ping…

What about the bugs described by Simon? If Eth built in is not reliable what can we do?


#13

@ leforban - If you are having issues, you can always look into the ENC28 while we investigate.


#14

I don’t have ENC28, and run out of time. I am supposed to launch PCB fab by the end of this week. Unfortunately something that should take few minutes takes a week…

I start regretting to port my app from EMX to an other GHI product. I am not sure troubles come from GHI devices but there’s so much changes in the last SDK taht moving from 4.2 to 4.3 while changing devices was not a good idea


#15

@ leforban - try to setup IP before open the nic. Like:


bool _useDHCP = true;
   if (_useDHCP)
            {
                if (!_nic.IsDhcpEnabled)
                {
                    _nic.EnableDhcp();
                    _nic.EnableDynamicDns();
                }
            }
            else
            {
                _nic.EnableStaticIP(_deviceIP, _deviceSubNetMask, _deviceGateWayIP);
                _nic.EnableStaticDns(_dnsServerIPs);
            }

            NetworkChange.NetworkAddressChanged += NetworkChangeNetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChangeNetworkAvailabilityChanged;

            if (!_nic.Opened)
                _nic.Open();



#16

@ robvan this seems not solve the problem. :frowning:


#17

@ leforban - This solved a lot of issues i had with ENC28 and RS9110 on both G120 and G400. I will check tonight with G400D and buildin ethernet


#18

@ leforban - Just checked G400D with built in ethernet and can confirm that it works like a charm.

Did you set a unique mac address for your board. If not your router might get confused if you had another nic controller connected before with same mac.


#19

Hum did you try to restart the program using Visual Studio several times? Sometimes it works well but suddenly I had some problem every 5 to 10 times. When the problem occurs it can last for 4-5 restart and disappears…

I usually receive properly the DISCOVER and OFFER but the G400 seems not to REQUEST the IP given by the server…


#20

@ leforban - I am afraid you are right. I restarted the application 12 times and 4 times it did not receive an IP address. When it did not receive an IP address it also did not detect cable disconnect. :frowning: