Ethernet on the Spider not using DHCP

Hi,
I am using a spider with version 4.2.4 and the j11d ethernet.
As I understand it, the ethernet module does not need to be coded, it is just there.
I have this chunk of code to set up my network interface:

      if (_networkInterface == null)
                {
                    if (NetworkInterface.GetAllNetworkInterfaces().Length < 1)
                    {
                        Debug.Print("No Active network interfaces. Bombing out.");
                        Thread.CurrentThread.Abort();
                        return null;
                    }
                    _networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
                }
                try
                {
                    if (_networkInterface.IsDhcpEnabled == false)
                    {
                        Debug.Print("Enabling DHCP.");
                        _networkInterface.EnableDhcp();
                        Debug.Print("DCHP - IP Address = " + _networkInterface.IPAddress + " ... Net Mask = " + _networkInterface.SubnetMask + " ... Gateway = " + _networkInterface.GatewayAddress);
                    }
                    else
                    {
                        Debug.Print("Renewing DHCP lease.");
                        _networkInterface.RenewDhcpLease();
                        Debug.Print(
                             "DCHP - IP Address = " + _networkInterface.IPAddress + " ... Net Mask = " +
                             _networkInterface.SubnetMask + " ... Gateway = " + _networkInterface.GatewayAddress);
                    }

                }

Unfortunately, When I run this, all I get is zeros:

[em]Renewing DHCP lease.
DCHP - IP Address = 0.0.0.0 … Net Mask = 0.0.0.0 … Gateway = 0.0.0.0
IP Address: 0.0.0.0[/em]

I have gone into MFDeploy and set a static IP of 192.168.1.202 and a subnet mask of 255.255.255.0. After I run the code above they are again set to 0.0.0.0

When I look at the network (discrete router for testing) , the device has been assigned an IP address but the device still shows all 0.0.0.0.

any ideas?

DHCP runs in a separate thread. EnableDhcp and RenewDhcpLease are no longer blocking calls.

You have to register for a network event to know when the IP address has been assigned.

The IP address is not ready when you are doing your prints.

Check out this example http://www.tinyclr.com/codeshare/entry/588

Clearly I am missing something here.
I now am using this code:

   public partial class Program
    {
        private NetworkInterface _networkInterface;

        void ProgramStarted()
        {
            NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
            _networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
            if (_networkInterface.IsDhcpEnabled == false)
            {
                Debug.Print("Enabling DHCP.");
                _networkInterface.EnableDhcp();            }
            else
            {
                Debug.Print("Renewing DHCP lease.");
                _networkInterface.RenewDhcpLease();
            }
             Debug.Print("Program Started");
       
        }

        void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            display_HD44780.Clear();
            display_HD44780.PrintString(e.IsAvailable.ToString());
        }

        void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("DCHP - IP Address = " + _networkInterface.IPAddress + " ... Net Mask = " + _networkInterface.SubnetMask + " ... Gateway = " + _networkInterface.GatewayAddress);
            display_HD44780.Clear();
            display_HD44780.PrintString(_networkInterface.IPAddress);
         }

    }
          

I have a j11d plugged into socket 7,
when I run it, the NetworkAddresChangedEvent Never fires.
If I unplug the cable the NetworkChange_NetworkAvailabilityChanged does fire.

I am running:

[em]ClrInfo.clrVersion: 4.2.0.0
ClrInfo.clrVendorInfo: Microsoft Copyright © Microsoft Corporation. All rig
ClrInfo.targetFrameworkVersion: 4.2.0.0
SolutionReleaseInfo.solutionVersion: 4.2.4.0
SolutionReleaseInfo.solutionVendorInfo: Copyright © GHI Electronics, LLC
SoftwareVersion.BuildDate: Aug 22 2012
SoftwareVersion.CompilerVersion: 410462
[/em]

what am I missing?

look carefully at the example I suggested. you are missing necessary steps.

check this posting

http://www.tinyclr.com/forum/topic?id=9438&page=1#msg93923

I read that sample,

It says:
[em]
static EthernetBuiltIn Eth1 = new EthernetBuiltIn();

// if you were to use ENC28J60-based Ethernet connection
//static EthernetENC28J60 Eth1 = new EthernetENC28J60(add code here to configure it);
// wifi is same thing
// static WiFiRS9110 wifi = new WiFiRS9110(…);
[/em}

I am using J11d and firmware that is supposed to “automagically” configure it, As such, I do not know which code from the sample I am supposed to use as much of it appears to be for something other than what I am using.

Not sure what you mean?

If you are using a Gadgeteer project, then you do not have to drop the J11D module in
the designer. But you do have to use code to initialize it.

The code I posted is for the J11d. Ignore the code commented out. The commented code show
you what to do with other types of Ethernet devices.

In the example, when you get to line 55 Ethernet is ready to use. Lines 57-69 are
used to start a HPPT server, so you should ignore them.

where do I find the library for this?

    static EthernetBuiltIn Eth1 = new EthernetBuiltIn();

I would try the reference GHI.Premium.Hardware or GHI.Premium.System.

I am not at my development system, so I can not check my project.

The documentation in the forum support area has not been updated with the Oct 24 RC release.

just to be clear, you are saying to use the ENC28 ethernet with the Spider Mainboard?

That is not what the documentation says to use… the docs say use j11d.

Where did I say that?

You gave me a reference to this post: http://www.tinyclr.com/codeshare/entry/588

Quoting the description of that article:

So what did I mis read?

It says the code requires a PHY, which is part of the Spider. It further says, that the code could be simply changed to user the ENC28. That is shown in the code referencing the ENC28, which has been made into comments.

To help other users, which specific part of the above quote made you think an ENC28 is required?

Try getting this code working. It is for a Spider with J11D using DHCP.

using System;
using Microsoft.SPOT;
using System.Net;
using System.Text;
using System.Threading;
using GHI.Premium.Net;
using Microsoft.SPOT.Hardware;

namespace JD11Example
{
    public class Program
    {
        static EthernetBuiltIn Eth1 = new EthernetBuiltIn();

        static byte[] outBuffer;
        static public ManualResetEvent NetworkAvailablityBlocking = null;
        static public ManualResetEvent IPAddressSetResetEvent = null;
        static string myIP = "192.168.0.226";

        public static void Main()
        {
            Eth1.Open();
            NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);
            //Eth1.NetworkInterface.EnableStaticIP(myIP, "255.255.255.0", "192.168.0.2");
            Eth1.NetworkInterface.EnableDhcp();
            IPAddressSetResetEvent = new ManualResetEvent(false);
            Eth1.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
            Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);

            if (!Eth1.IsCableConnected)
            {
                NetworkAvailablityBlocking = new ManualResetEvent(false);

                do
                {
                    if (!Eth1.IsCableConnected)
                    {
                        Debug.Print("Ethernet cable is not connected yet.");
                    }
                    else
                        break;
                } while (!NetworkAvailablityBlocking.WaitOne(5000, false));
            }

            while (!IPAddressSetResetEvent.WaitOne(500, false))
            {
                Debug.Print("IP address is not set yet.");
            }
            Debug.Print("IP address is set");

            // we are now ready to use Ethernet
            Thread.Sleep(Timeout.Infinite);
        }

        static void Eth1_CableConnectivityChanged(object sender, EthernetBuiltIn.CableConnectivityEventArgs e)
        {
            Debug.Print("Built-in Ethernet Cable is " + (e.IsConnected ? "Connected!" : "Disconneced!"));
            if (e.IsConnected)
                NetworkAvailablityBlocking.Set();
        }

        static void Eth1_NetworkAddressChanged(object sender, EventArgs e)
        {

            Debug.Print("New address for The built-in Ethernet Network Interface ");

            Debug.Print("Is DhCp enabled: " + Eth1.NetworkInterface.IsDhcpEnabled);
            Debug.Print("Is DynamicDnsEnabled enabled: " + Eth1.NetworkInterface.IsDynamicDnsEnabled);
            Debug.Print("NetworkInterfaceType " + Eth1.NetworkInterface.NetworkInterfaceType);
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + Eth1.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + Eth1.NetworkInterface.SubnetMask);
            Debug.Print("Default Getway: " + Eth1.NetworkInterface.GatewayAddress);
            Debug.Print("Number of DNS servers:" + Eth1.NetworkInterface.DnsAddresses.Length);
            for (int i = 0; i < Eth1.NetworkInterface.DnsAddresses.Length; i++)
                Debug.Print("DNS Server " + i.ToString() + ":" + Eth1.NetworkInterface.DnsAddresses[i]);
            Debug.Print("------------------------------------------------------");
            if (Eth1.NetworkInterface.IPAddress == myIP || Eth1.NetworkInterface.IPAddress != "0.0.0.0")
                IPAddressSetResetEvent.Set();
        }
    }
}

“Of course this example requires a built in Ethernet PHY”

I am using a Fez Spider 1.0…I do not know what the Built in “Ethernet PHY” is I do not see an ethernet jack on the card…so I figure I do not have a built in “Ethernet PHY”

without having that, I continue on in the statement and it says “the code can be simply changed to use ENC28”.

I am trying your code, but as I said earlier, I cannot find a dll to reference for EthernetBuiltIn.

I suspect it is in GHI.Premium.Net as I cannot resolve that namespace, but I cannot find it in any of the premium libraries.

so do you know where GHI.Premium.Net is located?

BTW, Thanks for all of the help.

When you use the Spider and J11D you have an Ethernet PHY. I believe the PHY is built into the chip used on the Spider.

The PC I am using now does not have the latest GHI Premium SDK installed.

I will be leaving to home soon, and I will find the reference later tonight.

BTW, you must be using the SDK released on October 24. The version of
the reference would be 4.2.5

OK, the GHI.Premium.Net reference is in the 4.2.5 release of the GHI SDK, which came out around Oct 24/26. If you are using
4.2 but do not see it, then you are not running the lastest SDK. Ethernet support came out with the 4.2.5 release.

Yes, I did not have the most up to date firmware…However I have bricked my spider trying to upgrade…I will get back to this thread when I fix that.

Thanks for all of the help