Main Site Documentation

Cerbuino and ENC28


#1

Hello,
I need a simple task: start the ENC28 on my Cerbuino, and get an IP from DHCP.
Quite simple, but I cannot complete it :frowning:
I’ve looked for samples and forum but really nothing was clear.

Someone from GHI can provide me some way to get it?

thanks


#2

Try something like this:


private NetworkInterface _ni;

        private void ProgramStarted()
        {
            Debug.Print("Program Started");

            try
            {
                _ni = NetworkInterface.GetAllNetworkInterfaces()[0];

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

                if (_ni.IPAddress != "0.0.0.0")
                    Debug.Print("IP Address:" + _ni.IPAddress);
            }
            catch (Exception exception)
            {
                throw new ArgumentException("Could not resolve host via DNS.", exception);
            }
         }


#3

Thank you. In fact I was trying something similar inspired by http://www.ghielectronics.com/community/codeshare/entry/606:



 Dim interfaces() = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces

            Try

                Dim eth1 = interfaces(0)
                If Not eth1.IsDhcpEnabled Then eth1.EnableDhcp()

                Do

                    eth1 = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

                    Thread.Sleep(1000)

                Loop Until eth1.IPAddress <> "0.0.0.0"

                IsNetworkRunning = True

            Catch ex As Exception
                IsNetworkRunning = False
            End Try

However my eth1.IPAddress is always “0.0.0.0” :frowning:


#4

The code I posted is what I use in a lot of my projects (Cerberus with a ENC28) and it works well, example:

https://thingspeak.com/channels/5854

or

https://thingspeak.com/channels/3512


#5

I really don’t know :frowning:

If I assign a static address with


eth1.EnableStaticIP ("172.30.98.60", "255.255.255.0", "172.30.98.1") 

I can ping the board (after a while, and sometimes after detach and reattach the cable)

With DHCP still always 0.0.0.0
My DHCP server is ok. I’ve also changed switch port and also cable to be sure.
If your code works, it really has no sense.

p.s. Canada? You are really lucky: it’s so beautiful…:slight_smile:


#6

I’ve found that my DHCP server is releasing IP address when I switch to eth1.EnableDhcp. I can found the MAC addresses reported by eth1.EnableDhcp in my release table.

Se the problem is that the board doesn’t “load it”… :frowning:

Question: may I inizialize the ENC28 before to use it? The MAC seems quite strange…


#7

@ baz - you can set the macadress with the Fez Config Tool or simply at program start :


NetworkInterface.GetAllNetworkInterfaces()[0].PhysicalAddress = new byte[] { 0x00, 0x75, 0x65, 0xde, 0xac, 0xaa };


#8

This seems like one of the scenarios that we’ve heard (I have it too) where the DHCP lease offered by the DHCP server isn’t working exactly as expected in the netmf IP stack. I don’t think there’s an easy way to diagnose this without network traces to check the responses - I also don’t have a link to the work item or the thread here that talked about it (will update this post if I can find them). Edit: here’s the thread that has some insights http://www.ghielectronics.com/community/forum/topic?id=12032&page=2 edit2: this is the only work item I could find that had 4.2 DHCP relevance https://netmf.codeplex.com/workitem/1655 so I’ve added the above thread to the comments and voted.


#9

I think that this is the problem :frowning:

I’ve assigned a MAC address to my board but this didn’t change anything. The board doesn’t load the IP assigned by my DHCP server.
I’d I statically assign the address, it works.

I also voted to the thread. However it’s incredible I cannot create an object that is plug-and-play on networks using this kind of devices. MS: what a great framework! :frowning:


#10

@ Baz, the framework took the lwIP implementation http://savannah.nongnu.org/projects/lwip/ in the 4.2 version, and therefore I suspect that the framework is a victim of a potential issue here - and before anyone pipes up, yes I work for Microsoft (not anything to do with netmf) so obviously I am somewhat protective, but it’s important to delve into this reported problem in the correct way.

Can someone share their test code? I have an ENC28 on the way so I can test my Cobra2 with wired and with my (failing) router and help collect more information


#11

@ baz - I experienced same problem on custom board, but with Cerberus firmware.
Problem was with INT pin on the board. Make sure that pin is available and not reserved for other features.


#12

@ slawek I’m sorry for the newbie question, but… what is the INT pin on may Cerbuino?

Thanks


#13

@ baz -

FEZ Cerbuino, Socket 1, Pin 3 goes to the PA14

Also make sure that SPI works correctly.
You can test it with SPI loopback.
Connect a wire between PB5 and PB4 pins.
Create a project “Example 1” from http://www.ghielectronics.com/docs/14/spi.
Add some data in tx_data array as

tx_data[0]=44;tx_data[0]=55;

and etc.
Insert breakpoint at

MySPI.WriteRead(tx_data, rx_data); 

In rx_data array data should be the same as in tx_data


#14

@ Brett: my VB code is:

        Dim interfaces() = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
                

Dim eth1 = interfaces(0)

Dim mac As Byte() = {&H0, &H88, &H50, &HB2, &HDE, &HD3}
eth1.PhysicalAddress = mac

If Not eth1.IsDhcpEnabled Then eth1.EnableDhcp()

Do

                    eth1 = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

                    Thread.Sleep(1000)
Loop Until eth1.IPAddress <> "0.0.0.0"


In fact the second access to GetAllNetworkInterfaces is not required, it was just a test to see if there was some problem updating internal objects references.

thank you for assistance and for your clarification


#15

@ baz

Did u resolve your problem?


#16

No :frowning:
I’ve tried to understand your suggestion, but I simply have the Cerbuino connected to the ENC using the provided cabled gadgeteer cable. So pins and so on are connected using that cables.

However the NIC works well, just the DHCP doesn’t load received address, so I think that connections and other similar things are ok.


#17

on the Cerbuino that pin is part of the socket 1 where the Enc28 is plugged in, and only place where you can plug it in…

not sure what can be done to make it available…

i’m experiencing the same issue with Cerbuino no DHCP…

Cheers,
Jay.


#18

DHCP simply doesnt’ work on current version of MF :frowning:
It works only sometimes, but most of DHCP servers are not “supported”. Really bad.


#19

@ baz - do you have any of our premium devices?


#20

cerbuino bee