FEZ Raptor Mainboard and Ethernet ENC28 Module: Static IP issue

I connected the dual power board to port8 and connected the Ethernet ENC28 Module to Port3 of the Raptor. I have both USB and power plug(12v 3amps) plugged into the dual power board. Ethernet cable is connected to my wireless extender port1.

I tried pinging 192.168.1.129 but the Destination host is unreachable and I do not see 192.168.1.129 under the “Wired” list in my wireless extender Status page.

My C# Code:

using System;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Pins;
using GHI.Networking;

namespace HelloWorld
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.
        static EthernetENC28J60 Eth1;
        static bool hasAddress = false;
        static bool available = false;

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

            Eth1 = new GHI.Networking.EthernetENC28J60(
                SPI.SPI_module.SPI2, 
                Cpu.Pin.GPIO_Pin0, //chip select
                Cpu.Pin.GPIO_Pin1, //external interrupt
                Cpu.Pin.GPIO_Pin2 //reset
            ); //change to target design

            Eth1.Open();
            //Eth1.EnableDhcp();
            Eth1.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
            Eth1.EnableStaticDns(new string[] {"192.168.1.1"});

            while (!hasAddress || !available)
            {
                Debug.Print("Initializing Network...");
                System.Threading.Thread.Sleep(100);
            }

            while (hasAddress)
            {
                System.Threading.Thread.Sleep(3000);
                Debug.Print(Eth1.IPAddress.ToString());
            }
        }
        
        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network available: " + e.IsAvailable.ToString());
            available = e.IsAvailable;
        }

        static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("The network address has changed.");
            //System.Threading.Thread.Sleep(500);
            Debug.Print(Eth1.IPAddress.ToString());
            hasAddress = Eth1.IPAddress != "0.0.0.0";
        }
    }
}

Debug Output:

[quote]Using mainboard GHI Electronics FEZ Raptor version 1.0
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Network available: True
The network address has changed.
192.168.1.129[/quote]

For a start, move this stuff out of ProgramStarted(). There’s no guarantee that you’re in a stable state with this code blocking the completion of ProgramStarted().

            while (!hasAddress || !available)
             {
                 Debug.Print("Initializing Network...");
                 System.Threading.Thread.Sleep(100);
             }

             while (hasAddress)
             {
                 System.Threading.Thread.Sleep(3000);
                 Debug.Print(Eth1.IPAddress.ToString());
             }

http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx

1 Like

Thanks for the article. That would explain why the Debug Output was warning me about Blocking. I should have listened to the warning. I am still not able to view my Raptor in the Wired Status of my Wifi extender.

Updated code:


using System;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Pins;
using GHI.Networking;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp3
{
    public partial class Program
    {
        static EthernetENC28J60 Eth1;
        GT.Timer networkTimer = new GT.Timer(3000);

        static bool hasAddress = false;
        static bool available = false;

        // This method is run when the mainboard is powered up or reset.  
        void ProgramStarted()
        {
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

            networkTimer.Tick += new GT.Timer.TickEventHandler(networkTimer_Tick);

            Eth1 = new GHI.Networking.EthernetENC28J60(
                SPI.SPI_module.SPI2,
                Cpu.Pin.GPIO_Pin0, //chip select
                Cpu.Pin.GPIO_Pin1, //external interrupt
                Cpu.Pin.GPIO_Pin2 //reset
            ); //change to target design

            //Eth1.Open();
            //Eth1.EnableDhcp();

            networkTimer.Start();
        }

        void networkTimer_Tick(GT.Timer timer)
        {
            if (!hasAddress || !available)
            {
                Eth1.Open();
                //Eth1.EnableDhcp();
                Eth1.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
                Eth1.EnableStaticDns(new string[] { "192.168.1.1" });

                while (!hasAddress || !available)
                {
                    Debug.Print("Initializing Network...");
                    System.Threading.Thread.Sleep(100);
                }
            }

            while (hasAddress)
            {
                System.Threading.Thread.Sleep(100);
                Debug.Print(Eth1.IPAddress.ToString());
            }
        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network available: " + e.IsAvailable.ToString());
            available = e.IsAvailable;
        }

        static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("The network address has changed.");
            //System.Threading.Thread.Sleep(500);
            Debug.Print(Eth1.IPAddress.ToString());
            hasAddress = Eth1.IPAddress != "0.0.0.0";
        }
    }
}


Debug Output:

[quote]Using mainboard GHI Electronics FEZ Raptor version 1.0
Program Started
Network available: True
The network address has changed.
192.168.1.129
The thread ‘’ (0x3) has exited with code 0 (0x0).
[/quote]

I also tried directly connecting the Raptor to port1 of my router, completely bypassing my wifi extender. However, I still do not see the Raptor on my routers Status wired list.

I am out of ideas of how to continue to troubleshoot this issue :confused:

@ dottedquad - Are you sure your router shows static IP allocations in the status list? If I am not mistaken, when configuring a static IP, no traffic goes out on the network so the router has no way of seeing you until you make a request.

1 Like

Hi John. I have always delt with DHCP configurations. This is my first time using a static configuration. I was always under the impression while the device is configuring its network settings it would communicate with the router and that would make sense for DHCP.

Is there an example showing how to make a request or multiple ping requests when using the Ethernet ENC28 Module?

@ dottedquad -

Try to call

Eth1.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
                Eth1.EnableStaticDns(new string[] { "192.168.1.1" });

before calling Open();

1 Like

Hi Dat. I changed the code around and I am still getting the same result.

I commented out StaticIP and StaticDns and EnabledDhcp();

            if (!hasAddress || !available)
            {
                Eth1.EnableDhcp();
                //Eth1.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
                //Eth1.EnableStaticDns(new string[] { "192.168.1.1" });

                Eth1.Open();

                while (!hasAddress || !available)
                {
                    Debug.Print("Initializing Network...");
                    System.Threading.Thread.Sleep(100);
                }
            }

Debug.Print outputs

[quote]Using mainboard GHI Electronics FEZ Raptor version 1.0
Program Started
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
Network available: True
Initializing Network…
Initializing Network…
Initializing Network…
Initializing Network…
The thread ‘’ (0x3) has exited with code 0 (0x0).
Initializing Network…[/quote]

@ dottedquad - Can you try a different socket on the mainboard? Do you have a second mainboard or ENC28 module you can try? Do you have a different router?

1 Like

@ dottedquad -

Try to re-flash the config.hex file.

Also, for DHCP, try to set different MAC Address by FEZ config tool.

1 Like

@ John I moved the ENC28 to socket 1 and changed the ENC28 config code to:

 Eth1 = new GHI.Networking.EthernetENC28J60(
                SPI.SPI_module.SPI1,
                Cpu.Pin.GPIO_Pin0, //chip select
                Cpu.Pin.GPIO_Pin1, //external interrupt
                Cpu.Pin.GPIO_Pin2 //reset
            );

I have tried three different routers and one wifi extender. I am still receiving the same results with both DHCP and Static. I don’t have another ENC28 module as I only purchased a Dual Power modules, FEZ Raptor and one ENC28 last week.

@ Dat Here is a few screenshots of using the FEZ config tool

I tried your original code on my setup and found the same problem. I then added the ENC28 through Gadgeteer and using the following code works fine for me.

namespace HelloWorld
{
    public partial class Program
    {
        //static EthernetENC28J60 ethernetENC28;
        GT.Timer networkTimer = new GT.Timer(3000);

        static bool hasAddress = false;
        static bool available = false;

        // This method is run when the mainboard is powered up or reset.  
        void ProgramStarted()
        {
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

            networkTimer.Tick += new GT.Timer.TickEventHandler(networkTimer_Tick);

            //ethernetENC28 = new GHI.Networking.EthernetENC28J60(
            //    SPI.SPI_module.SPI2,
            //    Cpu.Pin.GPIO_Pin0, //chip select
            //    Cpu.Pin.GPIO_Pin1, //external interrupt
            //    Cpu.Pin.GPIO_Pin2 //reset
            //); //change to target design

            //ethernetENC28.Open();
            //ethernetENC28.EnableDhcp();

            networkTimer.Start();
        }

        void networkTimer_Tick(GT.Timer timer)
        {
            if (!hasAddress || !available)
            {
                ethernetENC28.NetworkInterface.Open();
                //Eth1.EnableDhcp();
                ethernetENC28.NetworkSettings.EnableStaticIP("192.168.0.129", "255.255.255.0", "192.168.0.1");
                ethernetENC28.NetworkSettings.EnableStaticDns(new string[] { "192.168.0.1" });

                while (!hasAddress || !available)
                {
                    Debug.Print("Initializing Network...");
                    System.Threading.Thread.Sleep(100);
                }
            }

            while (hasAddress)
            {
                System.Threading.Thread.Sleep(100);
                Debug.Print(ethernetENC28.NetworkInterface.IPAddress.ToString());
            }
        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network available: " + e.IsAvailable.ToString());
            available = e.IsAvailable;
        }

         void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("The network address has changed.");
            //System.Threading.Thread.Sleep(500);
            Debug.Print(ethernetENC28.NetworkInterface.IPAddress.ToString());
            hasAddress = ethernetENC28.NetworkInterface.IPAddress != "0.0.0.0";
        }
    }
}

The difference seems to be in the lines

ethernetENC28.NetworkInterface.Open();
                //Eth1.EnableDhcp();
                ethernetENC28.NetworkSettings.EnableStaticIP("192.168.0.129", "255.255.255.0", "192.168.0.1");
                ethernetENC28.NetworkSettings.EnableStaticDns(new string[] { "192.168.0.1" });

As the Open & NetworkSettings extension methods are not found in EthernetENC28J60.

1 Like

Hi Sprigo. I am really new to this and I greatly appreciate you and everyone that has taken the time to help me with this issue.

I am not exactly sure what you mean by “added ENC28 through Gadgeteer” Are you referring to adding the GTM.GHIElectronics.EthernetENC28 to the References?

my using statements at the top of program.cs are as follows:

using System;
using System.Net;
using System.Threading;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Pins;
using GHI.Networking;


using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

I just figured out what you meant :slight_smile:

Oops I feel a bit embarrassed :-[ . I didn’t look inside “Toolbox” It was minimized. I should really pin the Toolbox open. As far as the code… I am trying out your change and will report back with an update.

Thank You! I owe you a beer or coffee :slight_smile: setting up Static IP works a treat; however, ethernetENC28.UseDHCP(); configures my ip as 0.0.0.0.

Working static IP code:

using System;
using System.Net;
using System.Threading;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Pins;
using GHI.Networking;


using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp3
{
    public partial class Program
    {
        //static EthernetENC28J60 Eth1;
        GT.Timer networkTimer = new GT.Timer(3000);

        static bool hasAddress = false;
        static bool available = false;

        // This method is run when the mainboard is powered up or reset.  
        void ProgramStarted()
        {
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

            networkTimer.Tick += new GT.Timer.TickEventHandler(networkTimer_Tick);

            //Eth1 = new GHI.Networking.EthernetENC28J60(
            //    SPI.SPI_module.SPI2,
            //    Cpu.Pin.GPIO_Pin0, //chip select
            //    Cpu.Pin.GPIO_Pin1, //external interrupt
            //    Cpu.Pin.GPIO_Pin2 //reset
            //); //change to target design

            //Eth1.Open();
            //Eth1.EnableDhcp();

            networkTimer.Start();
        }

        void networkTimer_Tick(GT.Timer timer)
        {
            if (!hasAddress || !available)
            {
                //Eth1.EnableDhcp();
                //Eth1.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
                //Eth1.EnableStaticDns(new string[] { "192.168.1.1" });

                //Eth1.Open();
                ethernetENC28.NetworkInterface.Open();
                //ethernetENC28.UseDHCP();
                ethernetENC28.NetworkSettings.EnableStaticIP("192.168.1.129", "255.255.255.0", "192.168.1.1");
                ethernetENC28.NetworkSettings.EnableStaticDns(new string[] { "192.168.1.1" });
                
                while (!hasAddress || !available)
                {
                    Debug.Print("Initializing Network...");
                    System.Threading.Thread.Sleep(100);
                }
            }

            while (hasAddress)
            {
                System.Threading.Thread.Sleep(100);
                Debug.Print(ethernetENC28.NetworkInterface.IPAddress.ToString());
            }
        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network available: " + e.IsAvailable.ToString());
            available = e.IsAvailable;
        }

        void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("The network address has changed.");
            //System.Threading.Thread.Sleep(500);
            Debug.Print(ethernetENC28.NetworkInterface.IPAddress.ToString());
            hasAddress = ethernetENC28.NetworkInterface.IPAddress != "0.0.0.0";
        }
    }
}

@ dottedquad the ‘Toolbox’ is your friend :slight_smile: Adding your modules here means that you don’t need to worry about the initialization.

I missed the call too


in the original code but as you are using static you don't need it.

Glad to hear that you are up and running. 



:dance:
1 Like