Main Site Documentation

Ethernet_J11D not working in GHI Gadgeteer SDK beta


#1

I can run Ethernet code using a NETMF project, as in code from GHI documentation, but when I run a NET Gadgeteer project using Ethernet J11D module, the network up event never fires.

Output of code that follows:

Ethernet cable is connected!
Enable DHCP
Network settings:
IP Address: 192.168.1.200
Subnet Mask: 255.255.255.0
Default Getway: 192.168.1.1
DNS Server: 192.168.1.1
Test Request
Status code: 200 Status description: OK
Content type: text/html Content length: 6237



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;
using GHIElectronics.NETMF.Net;
using System.Net;


namespace EthernetNETMF
{
    public class Program
    {

        static public bool ethernet_event = false;
        static public bool ethernet_last_status = false;
        static public bool network_is_read = false;
        static public ManualResetEvent NetworkAvailablityBlocking = null;

        public static void Main()
        {
            if (!Ethernet.IsEnabled)
            {
                Ethernet.Enable();
            }
            
            NetworkChange.NetworkAvailabilityChanged += 
                new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
            
            NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces();
            
            // Ethernet is always the first interface netif[0]
            NetworkAvailablityBlocking = new ManualResetEvent(false);

            if (!Ethernet.IsCableConnected)
            {
                Debug.Print("Cable is not connected!");
                NetworkAvailablityBlocking.Reset();
                while (!NetworkAvailablityBlocking.WaitOne(5000, false))
                {
                    if (!Ethernet.IsCableConnected)
                    {
                        Debug.Print("Cable is not connected!");
                        Debug.Print("Still waiting.");
                    }
                    else
                        break;
                }
            }

            Debug.Print("Ethernet cable is connected!");
            Debug.Print("Enable DHCP");
            try
            {
                if (!netif[0].IsDhcpEnabled)
                    netif[0].EnableDhcp();  // This function is blocking
                else
                {
                    netif[0].RenewDhcpLease();  // This function is blocking
                }
                network_is_read = true;
                Debug.Print("Network settings:");
                Debug.Print("IP Address: " + netif[0].IPAddress);
                Debug.Print("Subnet Mask: " + netif[0].SubnetMask);
                Debug.Print("Default Getway: " + netif[0].GatewayAddress);
                Debug.Print("DNS Server: " + netif[0].DnsAddresses[0]);
            }
            catch
            {
                Debug.Print("DHCP Faild");
            }

            Debug.Print("Test Request");
            try
            {
                using (HttpWebRequest request = HttpWebRequest.Create("http://cle-services.net") as HttpWebRequest)
                {
                    HttpWebResponse response;
                    try
                    {
                        response = request.GetResponse() as HttpWebResponse;
                        Debug.Print("Status code: " + response.StatusCode + "  Status description: " + response.StatusDescription);
                        Debug.Print("Content type: " + response.ContentType + "  Content length: " + response.ContentLength);
                        response.Close();
                    }
                    catch (Exception ex)
                    {
                        string exception = ex.Message + " Inner:" + ex.InnerException;
                        Debug.Print(exception);
                    }
                }
            }
            catch
            {
                Debug.Print("Faild to Get the host entry of the FQN from DNS server!");
            }

            Thread.Sleep(Timeout.Infinite);

        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            if (e.IsAvailable)
            {
                if (Ethernet.IsCableConnected)
                {
                    if (ethernet_last_status != true)
                    {
                        ethernet_last_status = true;
                        NetworkAvailablityBlocking.Set();
                    }
                }
            }
            else
            {
                if (!WiFi.IsLinkConnected)
                {
                    if (ethernet_last_status != false)
                    {
                        ethernet_last_status = false;
                        network_is_read = false;
                    }
                }
            }
        }
    }
}




#2

I think there is a bug in network availability events that will be fixed soon so please do not use those events.


#3

The most interesting scenarios I’m using require network availability. In a previous thread I was assured that this problem was fixed in new builds, but I just installed the beta and can’t get any network connectivity.


#4

Mike,

We got the problem fixed but we did release GHI NETMF SDK yet, even not Beta! What Beta SDK are you referring to?


#5

The latest beta with Fez Hydra included here: http://tinyclr.com/forum/12/4891/
Sorry to be impatient. I need the network connection.


#6

That was GHI OSH NETMF SDK and gadgeteer SDK. We never release GHI NETMF SDK :slight_smile:


#7

Another reason for not getting network change notices is that the Ethernet module (Ethernet ENC28 Module) for the Hydra is not available yet.


#8

Sorry, I’m still a little confused. The Ethernet_J11D is a .NET Gadgeteer module. I used NETMF code as above only to verify my ethernet connectivity. I need to know when will the J11D module will work?

I’m using the Spider mainboard not hydra.


#9

Please wait untill a new GHI SDK package is out which should be this month.


#10

Ok, I created my own ethernet class from your excellent documentation of the NETMF Ethernet class: http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html
:wink:


#11

Today i tried starting a new project. I dropped the Hydra in and then the J11D Ethernet module into the designer. Yet there is no way to connect them. Even if i select auto connect.
I was under the assumption that a Gadgeteer module in the tools pane would connect to this board.

Did i do something wrong ?


#12

You are correct but look at socket types. Your question is answered right on the hydra product page.

Note there is no enc28 module in the designer yet.


#13

I would have bet $20 bucks that when i was looking at the socket type of the J11D it was an "A"
Looking at it now i clearly see i was wrong, sorry.