Wired Ethernet - DHCP Issues

I recently purchsed 2 FEZ Spider II Tinker Kits and some bits to use in proof of concept and product demonstration platforms.

Besides product demonstration, I also need to evaluate functionality, ease of adoption, platform maturity, availability of support, and so forth towards accessing the viability of use of GHI Electronics components in an extensive commercial product offering.

Besides not being able to find mature working examples in the available documentation which are specific to the module I am using, I have already found 2 seemingly simple issues which I have not been able to resolve using the resources available. Given that this is the first time I am using GHI Electronics products, and that I have not previously used .NETMF, these difficulties are not totally
unexpected. This is by no means criticism, I’m am a bit disappointed though.

The first issue relating to ‘Reading an Analog Input’ I posted on the forum earlier.

The second issue relates to wired ethernet. I used FEZ Config in order to set and verify the Mac Address. I have given this a few attempts, without success. The code and debug output of my last 2 attempts, one using DHCP, and one using a Static IP, are included below.

Any assistance with this code will be appreciated.

When using DHCP

// Program.generated.cs
namespace GadgeteerEthernet {
    using Gadgeteer;
    using GTM = Gadgeteer.Modules;
    
    
    public partial class Program : Gadgeteer.Program {
        
        /// <summary>The USB Client EDP module using socket 1 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.USBClientEDP usbClientEDP;
        
        /// <summary>The Ethernet J11D module using socket 7 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.EthernetJ11D ethernetJ11D;
        
        /// <summary>This property provides access to the Mainboard API. This is normally not necessary for an end user program.</summary>
        protected new static GHIElectronics.Gadgeteer.FEZSpiderII Mainboard {
            get {
                return ((GHIElectronics.Gadgeteer.FEZSpiderII)(Gadgeteer.Program.Mainboard));
            }
            set {
                Gadgeteer.Program.Mainboard = value;
            }
        }
        
        /// <summary>This method runs automatically when the device is powered, and calls ProgramStarted.</summary>
        public static void Main() {
            // Important to initialize the Mainboard first
            Program.Mainboard = new GHIElectronics.Gadgeteer.FEZSpiderII();
            Program p = new Program();
            p.InitializeModules();
            p.ProgramStarted();
            // Starts Dispatcher
            p.Run();
        }
        
        private void InitializeModules() {
            this.usbClientEDP = new GTM.GHIElectronics.USBClientEDP(1);
            this.ethernetJ11D = new GTM.GHIElectronics.EthernetJ11D(7);
        }
    }
}

// Program.cs
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.Net.NetworkInformation;

namespace GadgeteerEthernet
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset. 
        void ProgramStarted()
        {
            Mainboard.SetDebugLED(false);

            InitEthernet();

            Debug.Print("Program Started");
        }

        private void InitEthernet()
        {
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;

            this.ethernetJ11D.NetworkSettings.EnableDhcp();
            this.ethernetJ11D.NetworkSettings.EnableDynamicDns();
            this.ethernetJ11D.UseDHCP();
        //    this.ethernetJ11D.NetworkSettings.EnableStaticIP("10.0.0.6", "255.255.255.0", "10.0.0.2");
            this.ethernetJ11D.UseThisNetworkInterface();

            while (this.ethernetJ11D.NetworkSettings.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP...");
                Thread.Sleep(1000);
            }
        }

        void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    Debug.Print("------------------------------------------------");
                    Debug.Print("MAC:          " + ni.PhysicalAddress.ToString());
                    Debug.Print("IP Address:   " + ni.IPAddress);
                    Debug.Print("DHCP Enabled: " + ni.IsDhcpEnabled.ToString());
                    Debug.Print("Subnet Mask:  " + ni.SubnetMask);
                    Debug.Print("Gateway:      " + ni.GatewayAddress);
                    Debug.Print("------------------------------------------------");
                }
            }
        }

        void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            if (e.IsAvailable)
                Debug.Print("Network is Up");
            else
                Debug.Print("Network is Down");
        }

    }
}

The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider II version 1.0
Waiting for DHCP…
Waiting for DHCP…
Network is Up
Waiting for DHCP…
Waiting for DHCP…
Waiting for DHCP…
Waiting for DHCP…
Waiting for DHCP…
WARN: Total initialization time exceeds 10 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
Waiting for DHCP…
Waiting for DHCP…
Waiting for DHCP…

When using a Static IP

private void InitEthernet()
{
    NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
    NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;

    //this.ethernetJ11D.NetworkSettings.EnableDhcp();
    //this.ethernetJ11D.NetworkSettings.EnableDynamicDns();
    //this.ethernetJ11D.UseDHCP();
    this.ethernetJ11D.NetworkSettings.EnableStaticIP("10.0.0.6", "255.255.255.0", "10.0.0.2");
    this.ethernetJ11D.UseThisNetworkInterface();

    //while (this.ethernetJ11D.NetworkSettings.IPAddress == "0.0.0.0")
    //{
    //    Debug.Print("Waiting for DHCP...");
    //    Thread.Sleep(1000);
    //}
}

The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider II version 1.0
Program Started
Network is Up

IP Address: 10.0.0.6
DHCP Enabled: False
Subnet Mask: 255.255.255.0
Gateway: 10.0.0.2


IP Address: 0.0.0.0
DHCP Enabled: True
Subnet Mask: 0.0.0.0
Gateway: 0.0.0.0


IP Address: 0.0.0.0
DHCP Enabled: True
Subnet Mask: 0.0.0.0
Gateway: 0.0.0.0

The thread ‘’ (0x3) has exited with code 0 (0x0).
The program ‘[8] Micro Framework application: Managed’ has exited with code 0 (0x0).

@ Oldevel - you are effectively doing a wait in the ProgramStarted method. This is a “NO-NO”. Blocking the ProgramStarted method suspends the framework startup process. Do your ethernet initialization in a separate thread.

andre.m - Thanks for the comments, this got me digging a bit further, I eventually disconnected the J11D device, added a BuiltInEthernet instance, and used the sample code in docs / Networking.

Mike - Thanks for the heads-up, this is for debug only.