private static readonly EthernetENC28J60 net = new EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, G120.P1_10, G120.P2_11, G120.P1_9);
private static readonly EthernetENC28J60 net = new EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, G120.P1_17, G120.P2_21, G120.P1_14);
private static readonly EthernetENC28J60 net = new EthernetENC28J60(SPI.SPI_module.SPI1, Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3);
private EthernetBuiltIn net = new EthernetBuiltIn();
Non of them work. I even try with adding ENC28 module to the Program.gadgeteer.
In some cases the NetworkChange_NetworkAvailabilityChanged event is called and e.IsAvailable is true, but I can not get any html not even from local network (works with Spider, Cerberus).
If I copy requested URL to the Chrome the page opens (it only prints current time).
I connected ENC28 to the Socket 6 (The only one with S socket).
What is the correct configuration?
@ Makla - The example on https://www.ghielectronics.com/docs/318/fez-cobra-ii-developers-guide is known to work. Using that as a starting point, can you create a minimal, but complete, program that shows your issue? Can you then try the exact same code on a different board, changing only the pins?
using GHI.Pins;
using GHI.Networking;
using Microsoft.SPOT.Net.NetworkInformation;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
namespace CobraIIECONetTest
{
public partial class Program
{
private static EthernetENC28J60 netif;
// This method is run when the mainboard is powered up or reset.
public void ProgramStarted()
{
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
netif = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.P1_10, G120.P2_11, G120.P1_9);
netif.Open();
netif.EnableDhcp();
netif.EnableDynamicDns();
}
private static void NetworkChange_NetworkAddressChanged(object sender, Microsoft.SPOT.EventArgs e)
{
Debug.Print("Network address changed");
if (netif.IPAddress != "0.0.0.0")
{
Debug.Print("Network address " + netif.IPAddress);
}
}
private static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
Debug.Print("Network availability: " + e.IsAvailable.ToString());
}
}
}
Output is:
[quote]The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Cobra II Eco version Rev B
Network availability: True
The thread ‘’ (0x5) has exited with code 0 (0x0).
The program ‘[8] Micro Framework application: Managed’ has exited with code 0 (0x0).[/quote]
AddressChanged is never called. My DHCP is working. I tried with mobile, and laptop.
Of course I am running the latest firmware. I also tried to erase everything and load fresh firmware and TinyBooter.
The cable is working.
The orange led on ENC28 is blinking. 1 to 5 times per second.
@ Makla - You are assuming that the NetworkChange_NetworkAddressChanged event occurs before NetworkChange_NetworkAvailabilityChanged event. This might not be the case. Do a little research.
I would wait to insure that an IP address is available before doing anything.
I also recommend that you do not do any processing in an event handler. Issuing the web request will hold the event handler thread which often results in unexpected things happening.
The exception you are seeing may be caused by the IP address not being available yet.
I know. I send http request in NetworkChange_NetworkAvailabilityChanged event only when I use static IP/DNS. (Second case.)
When I use dynamic IP/DNS I don’t have any code. Only some Debug.Print.
Same code works on Spider, CobraII WIFI and Cerberus.
Strange is when I request page from localhost I get socket error code: 10053 - Software caused connection abort,
but when I request StackOverflow I get error code: 10060 - Connection timed out.
I also try to connect LAN cable to different router.
@ Makla - Can you run the below code and see what happens? Make sure the ENC28 is in socket 6 and you have nothing else connected to the board. Update the loader and firmware before running it as well.
The code in the document that I linked you was actually for the Cobra II Net which I mistakenly thought you were using. The pins in the below code are correct for the Cobra II Eco on socket 6.
using GHI.Networking;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;
using System.Net;
using System.Threading;
namespace Networking
{
public class Program
{
public static void Main()
{
NetworkChange.NetworkAvailabilityChanged += (a, b) => Debug.Print("SPOT NAVAC " + b.IsAvailable.ToString());
NetworkChange.NetworkAddressChanged += (a, b) => Debug.Print("SPOT NADRC");
using (var netif = new EthernetENC28J60(SPI.SPI_module.SPI2, (Cpu.Pin)(32 + 17), (Cpu.Pin)(64 + 21), (Cpu.Pin)(32 + 14), 8000))
{
netif.Open();
netif.EnableDhcp();
netif.EnableDynamicDns();
while (netif.IPAddress == "0.0.0.0")
{
Debug.Print("Waiting DHCP");
Thread.Sleep(250);
}
Debug.Print(netif.IPAddress);
byte[] result = new byte[4096 * 4];
int read = 0, total = 0;
using (var req = HttpWebRequest.Create("http://www.ghielectronics.com/downloads/Gadgeteer/.NET%20Gadgeteer%20Ultimate%20Guide%20(discontinued).pdf") as HttpWebRequest)
{
using (var res = req.GetResponse() as HttpWebResponse)
{
using (var stream = res.GetResponseStream())
{
do
{
read = stream.Read(result, 0, result.Length);
total += read;
Thread.Sleep(20);
} while (read != 0);
Debug.Print("Downloaded " + total.ToString("N2") + " bytes.");
}
}
}
}
}
}
}