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";
}
}
}
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());
}
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
@ 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.
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 - 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?
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.
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";
}
}
}
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;
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.