Cerbuino and ENC28

@ Gus: I do

I am curious the DHCP failes on open but not on premium. So whoever does this test has to have both.

I was able to get DHCP to work on a Cerbuino Bee using the latest firmware from yesterday’s SDK. While I did not get an IP after calling EnableDHCP (it kept the default static IP of 192.168.5.100 I believe), it did load a DHCP address after restarting the board. It also did not get an IP if the board was unplugged (it got 0.0.0.0 for IP and Gateway). If I then reset the board using the button, it did get an address.

@ Jay and baz: can you reproduce that behavior?

My test code:


using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;

public class Program
{
    public static void Main()
    {
        System.Threading.Thread.Sleep(1000);

        Debug.Print("Starting");

        System.Threading.Thread.Sleep(1000);

        var eth = NetworkInterface.GetAllNetworkInterfaces()[0];

        if (!eth.IsDhcpEnabled)
            eth.EnableDhcp();

        Debug.Print(eth.IPAddress);
        Debug.Print(eth.DnsAddresses.Length > 0 ? eth.DnsAddresses[0] : "No DNS");
        Debug.Print(eth.GatewayAddress);
        Debug.Print(eth.SubnetMask);
        Debug.Print(eth.IsDhcpEnabled.ToString());
    }
}

Your code didn’t change a thing… sorry…

the only time I can get the DHCP to work is when I assign a static IP to the board, reboot and remove the static IP Code and turn on DHCP… at first boot the same IP gets assigned and few seconds later the Cable Event fire as if the cable was unplugged and plugged back again… which assigns the board a new IP but the interface isn’t updated with the new IP until next reboot… only IPAddress.GetDefaultLocalAddress() is updated with the new IPAddress.

the best way to test the DHCP issue is resolved is by changing the Mac Address with a new every time the boards boots to make sure the router is assigning you a new IP…

and btw: i have a while loop checking if the IP is not 0.0.0.0 and it loops forever without any changes… and yes I do have a sleep of 1000 inside the loop to make sure nothing is blocked.

here is the code to help you with the random mac generation and assignment :


var eth = NetworkInterface.GetAllNetworkInterfaces()[0];
 var myMac= new byte[6];
            Random r = new Random();
            r.NextBytes(myMac);

_networkInterface.PhysicalAddress = myMac;


I’m aware that the code I gave didn’t allow DHCP to work the first time, it only works in the conditions you described which is what I wanted to verify. We are looking into why it does not work consistently and will let you know when we have something.

just updated SDK, same problem

my code is similar to Jay

Dim eth1 = interfaces(0)

            ' -- assegno un mac random
            Dim r As New Random
            Dim mac(48 - 1) As Byte
            r.NextBytes(mac)
            eth1.PhysicalAddress = mac


            If Not eth1.IsDhcpEnabled Then eth1.EnableDhcp()
            Do
                Thread.Sleep(500)
            Loop Until eth1.IPAddress <> "0.0.0.0"

but if you change the Mac Address you will never get an IP through DHCP, no matter how many times you reboot…

Edit: I take the above back… now if I change the Mac address, it doesn’t assign an IPAddress, but once i reboot the device DHCP works and assign an IP…