Main Site Documentation

FEZ Raptor ECN28 Networkng


#1

I have been trying to build a html server using a raptor, but have not had any luck. I have tried translating several sets of example code to VB without luck. This code is the only adapted code examples I have been able to run. First the code throws the NetworkDown event, although the cat5 cable is connected, and shows traffic (the LED blinks).

The debug shows that the IP address remains 0.0.0.0.

The idea of using the Premium.Net package is appealing as it should detect cable problems. DHCP is also important for my application. Any ideas of why this does not work are appreciated.

And I would also appreciate knowing why when I copy code from Visual Studio and paste into the forum composer, I get an extra blank line for every code line.

Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Seeed
Imports Microsoft.SPOT.Hardware
Imports GHI.Hardware.G400
Imports System
Imports System.Net
Imports Microsoft.SPOT
Imports GHI.Premium.Net
Imports System.Text
Imports System.Threading
Imports Microsoft.SPOT.Net.NetworkInformation
Imports System.Net.Sockets

Namespace GadgeteerApp1
    Partial Public Class Program

            'Set iface to the first available network interface
        Private Shared WithEvents iface As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces(0)

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(1000)

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            Dim rtc_raptor As New RTC_Raptor

            iface.EnableDhcp()
            iface.EnableDynamicDns()
            Debug.Print(iface.PhysicalAddress.ToString())

            Debug.Print(iface.GatewayAddress.ToString)

            InternetTimer.Start()

        End Sub

        Private listening As Boolean = False
        Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            If listening = False Then
                If iface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & iface.IsDhcpEnabled.ToString & ", but no connection")
                    Exit Sub
                Else
                    Debug.Print("Has IP address of " & iface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
            Else

            End If
            Dim clientSocket As Socket = server.Accept ' wait for client to accept
            ' Process the client request.
            ProcessClientRequest(clientSocket)
        End Sub

        Private Shared Sub ProcessClientRequest(ByVal m_clientSocket As Socket)
            Const c_microsecondsPerSecond As Int32 = 1000000
            ' 'using' ensures that the client's socket gets closed.
            ' Wait for the client request to start to arrive.
            Using m_clientSocket
                Dim buffer() As Byte = New Byte((1024) - 1) {}
                If m_clientSocket.Poll((5 * c_microsecondsPerSecond), SelectMode.SelectRead) Then
                    ' If 0 bytes in buffer, 
                    ' then the connection has been closed,
                    ' reset, or terminated.
                    If (m_clientSocket.Available = 0) Then
                        Return
                    End If
                    ' Read the first chunk of the request 
                    ' (we don't actually do anything with it).
                    Dim bytesRead As Int32 = m_clientSocket.Receive(buffer, m_clientSocket.Available, SocketFlags.None)
                    ' Return a static HTML document to the client.
                    Dim s As String = ("HTTP/1.1 200 OK" & vbCrLf & "Content-Type: text/html; charset=utf-8" & vbCrLf & vbCrLf & "<html><head><title>.NET Micro Framework We" & _
                "b Server</title></head>" + "<body><bold><a href=\""http://www.ghielectronics.com/\"">Learn more about the .NET Micro Framework with" & _
                " FEZ by clicking here</a></bold></body></html>")
                    Dim buf() As Byte = System.Text.Encoding.UTF8.GetBytes(s)
                    Dim offset As Integer = 0
                    Dim ret As Integer = 0
                    Dim len As Integer = buf.Length

                    While (len > 0)
                        ret = m_clientSocket.Send(buf, offset, len, SocketFlags.None)
                        len = (len - ret)
                        offset = (offset + ret)

                    End While
                    m_clientSocket.Close()
                End If
            End Using
        End Sub

        Private Sub ethernet_ENC28_NetworkDown(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkDown
            Debug.Print("network down fired")
        End Sub


        Private Sub ethernet_ENC28_NetworkUp(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkUp
            Debug.Print("Network up fired")
        End Sub
    End Class
End Namespace

#2

At least on G120 you need to handle the NetworkAddressChanged event, or the IP address property will not be updated. May be this applies for G400 as well.
see:
https://www.ghielectronics.com/tracker/entry/54


#3

@ rockybooth - For this, you will most likely need to construct an ENC28 object for it to register as a network interface, since it is not statically assigned in the firmware, like it is for open source offerings.



Edit: Did not notice the GadgeteerApp1 as the namespace, I assume it is in the designer?

#4

@ James, can you please be more specific? I have tried several guesses at what you mean but I cannot get any to compile.

@ Reinhard Ostermeier - I added Private WithEvents eth As EthernetENC28J60 plus the event handler, but that alone is not sufficient to allow it to work.

Thanks


#5

It was my mistake as I did not notice it was a Gadgeteer application. I was only ensuring you were either adding the ENC28 module in the designer or if you were manually constructing it via the above namespace.


#6

@ James - Thanks. Do you have any idea why this does not connect, or can you point me at any code for gadgeteer/raptor/ENC28/DHCP enabled that works? I see plenty of examples for other combinations,k but nothing for gadgeteer and raptor and ENC28 and DHCP. Maybe I have not searched long enough…


#7

@ rockybooth - Not for the Raptor specifically. Use of the ENC28 between systems is generally the same, except in the open source offerings where there is a static firmware. I do not off hand know what is causing the issue, but we will look into this more tomorrow.


#8

I’m still trying to get up to speed with C# but this snippet seems to be working for me on the Raptor and ECN28 combination …


using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using GHI.Premium.Net;
using Microsoft.SPOT;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace EthernetTest
{
    public class WebServer
    {
        // Static IP Address to put it next to NAS
        private const string MyIP = "192.168.0.210";
        private bool useStatic = false;

        private Thread serverThread = null;
        private readonly Queue responseQueue;
        private string prefix;
        private int port = 8080;
        private int timeout = 200;
        private ManualResetEvent networkAvailablityBlocking = null;
        private EthernetENC28J60 ethernet;
        private displayLCD touchPanel;

        public WebServer(string prefix, int port, int timeout, EthernetENC28J60 ethernet, displayLCD touchPanel)
        {
            this.touchPanel = touchPanel;
            this.responseQueue = new Queue();

            this.prefix = prefix;
            this.port = port;
            this.timeout = timeout;
            this.ethernet = ethernet;

            this.setupWebServer();

            this.serverThread = new Thread(() => RunServer());
            this.serverThread.Start();
        }

        private void setupWebServer()
        {
            // This methods opens Ethernet driver. This must be called before accessing any other member of this object.
            ethernet.Open();

            // Assign network interface to the TCP/IP stack. 
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet);

            // Fires on Ethernet cable connectivity changes 
            ethernet.CableConnectivityChanged += (o, args) => ConnectivityChanged(o, args);

            // Fires on a change of IP address
            ethernet.NetworkAddressChanged += (o, args) => NetworkAddressChanged(o, args, ethernet);


            if (!ethernet.IsCableConnected)
            {
                networkAvailablityBlocking = new ManualResetEvent(false);

                do
                {
                    if (!ethernet.IsCableConnected)
                    {
                        touchPanel.WriteLine("Ethernet cable is not connected.");
                    }
                    else
                    {
                        break;
                    }
                } while (!networkAvailablityBlocking.WaitOne(5000, false));
            }

            if (useStatic)
            {
                ethernet.NetworkInterface.EnableStaticIP(MyIP, "255.255.255.0", "192.168.0.1");
                while (Equals(IPAddress.GetDefaultLocalAddress(), IPAddress.Any))
                {
                    touchPanel.WriteLine("ENC28J60 IP Address is not set.");
                }
            }
            else
            {
                ethernet.NetworkInterface.EnableDynamicDns();
                ethernet.NetworkInterface.EnableDhcp();
                while (Equals(IPAddress.Any))
                {
                    touchPanel.WriteLine("ENC28J60 IP Address is not set.");
                }
            }

            touchPanel.WriteLine("ENC28J60 IP address is set: " + ethernet.NetworkInterface.IPAddress);
        }

        private void NetworkAddressChanged(object sender, EventArgs e, EthernetENC28J60 ethernet)
        {
            touchPanel.WriteLine("_____________________________________________________________");
            touchPanel.WriteLine("New address for the ENC28J60 Ethernet Interface ");
            touchPanel.WriteLine("_____________________________________________________________");

            touchPanel.WriteLine("Is DhCp enabled: " + ethernet.NetworkInterface.IsDhcpEnabled);
            touchPanel.WriteLine("Is DynamicDnsEnabled enabled: " + ethernet.NetworkInterface.IsDynamicDnsEnabled);
            touchPanel.WriteLine("NetworkInterfaceType " + ethernet.NetworkInterface.NetworkInterfaceType);
            touchPanel.WriteLine("Network settings:");
            touchPanel.WriteLine("_________________");
            touchPanel.WriteLine("IP Address: " + ethernet.NetworkInterface.IPAddress);
            touchPanel.WriteLine("Subnet Mask: " + ethernet.NetworkInterface.SubnetMask);
            touchPanel.WriteLine("Default Getway: " + ethernet.NetworkInterface.GatewayAddress);
            touchPanel.WriteLine("Number of DNS servers:" + ethernet.NetworkInterface.DnsAddresses.Length);

            for (var i = 0; i < ethernet.NetworkInterface.DnsAddresses.Length; i++)
            {
                touchPanel.WriteLine("DNS Server " + i.ToString() + ":" + ethernet.NetworkInterface.DnsAddresses[i]);
            }

            touchPanel.WriteLine("_____________________________________________________________");
        }

        private void ConnectivityChanged(object sender, EthernetENC28J60.CableConnectivityEventArgs e)
        {
            touchPanel.WriteLine("ENC28J60 Ethernet Cable is " + (e.IsConnected ? "Connected." : "Disconneced."));

            if (e.IsConnected)
            {
                networkAvailablityBlocking.Set();
            }
        }

        private void RunServer()
        {
        }


    }
}



#9

@ Sprigo
Thanks for sharing that code. I have been trying to build this into an example I can test and am having trouble in calling the webserver. As I understand your code (I am used to VB) ethernet is being passed as GI.Premium.Net.EthernetENC28J60 while the Gadgeteer environment, at least in the case of VB, casts in Program.Generated.VB ethernet as follows:
’’'

The Ethernet_ENC28 (Premium) module using socket 11 of the mainboard.
Private WithEvents ethernet_ENC28 As Gadgeteer.Modules.GHIElectronics.Ethernet_ENC28

I do not know how to recast this to the extended version that you routines call for.
The way Gadgeteer instantiates ethernet_ENC28 is the version that does not have the extended connectivity events and methods. I am sure the answer is obvious to most, but not to me.

I would have thought that with Gadgeteer building a simple webserver would be more straightforward.


#10

[quote]’’'

The Ethernet_ENC28 (Premium) module using socket 11 of the mainboard.
Private WithEvents ethernet_ENC28 As Gadgeteer.Modules.GHIElectronics.Ethernet_ENC28
[/quote]

I saw a post in the forum (which I can’t find now) which recommended that you keep the Ethernet or WiFi module in Socket 1. Something to do with shared SPI I believe. I’ll have another look later.

I’m trying to make the move away from the Arduino so all of this event driven VS stuff is almost double Dutch at the moment. lol


#11

@ Sprigo - Thanks
@ James - you were going to look into this yesterday, were you able to figure out what I am doing wrong, or get a simple FEZ Raptor DHCP/ENC28 web server to function?


#12

@ rockybooth - I’m definitely stale on my VB, and James isn’t available for me to consult, but try this and let us know what happens

Change:

Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            If listening = False Then
                If iface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & iface.IsDhcpEnabled.ToString & ", but no connection")
                    Exit Sub
                Else
                    Debug.Print("Has IP address of " & iface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
            Else

to:


	Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick	        
            If listening = False Then
			    iface = NetworkInterface.GetAllNetworkInterfaces(0)
                If iface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & iface.IsDhcpEnabled.ToString & ", but no connection")
                    Exit Sub
                Else
                    Debug.Print("Has IP address of " & iface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
				listening = True
            Else		

Given my ignorance of VB I’m not sure what happens to your event handlers when you change “iface” ???


#13

Hi Jeff:
Thanks for the reply. This did not work - the revised code is below in case I did something wrong:
I also notice the the NetworkDown event fires before the timer fires, but after printing “Program Started”. I have verified that my laptop can connect using the same cable connection.
I also attached the version information below in case I have something out of sync.

Sorry about the VB - I have been trying to get a handle on C# without much sccess. If you can give me something to try in C#, if it works, I can change it to VB.


Namespace GadgeteerApp1
    Partial Public Class Program
        'Set iface to the first available network interface

        Private Shared WithEvents iface As Microsoft.SPOT.Net.NetworkInformation.NetworkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(1000)

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            iface.EnableDhcp()
            iface.EnableDynamicDns()
            InternetTimer.Start()
        End Sub

        Private listening As Boolean = False
        Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            Dim i As Integer = 0
            Debug.Print("tic...")

            If listening = False Then
                iface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

                If iface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & iface.IsDhcpEnabled.ToString & ", but no connection")
                    Exit Sub
                Else
                    Debug.Print("Has IP address of " & iface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
                listening = True
            Else
            End If
            Dim clientSocket As Socket = server.Accept ' wait for client to accept
            ' Process the client request.
            ProcessClientRequest(clientSocket)
        End Sub

        Private Sub ethernet_ENC28_NetworkDown(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkDown
            Debug.Print("network down fired")
        End Sub


Attaching deployed file.

Assembly: GTM.GHIElectronics.Display_HD44780 (4.2.102.0) Attaching deployed file.

Assembly: RaptorNetServer (1.0.0.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.SDCard (4.2.102.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.Ethernet_ENC28 (4.2.102.0) Attaching deployed file.

Assembly: Microsoft.VisualBasic (1.0.0.0) Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.IO (4.2.11.1) Attaching deployed file.

Assembly: GTM.GHIElectronics.UsbClientDP (4.2.102.0) Attaching deployed file.

Assembly: GHI.Premium.Net (4.2.11.1) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.2.102.0) Attaching deployed file.

Assembly: Gadgeteer.SPI (2.42.0.0) Attaching deployed file.

Assembly: GHI.Hardware.G400 (4.2.11.1) Attaching deployed file.

Assembly: GTM.Seeed.Barometer (1.6.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.11.1) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.11.1) Attaching deployed file.

Assembly: GTM.GHIElectronics.LED7C (4.2.102.0) Resolving.


#14

I looked at your code and realized that you don’t open the interface and nor do you bind it to the network stack. see Sprigo’s code especially “setupWebServer()” . Also see the forum thread https://www.ghielectronics.com/community/forum/topic?id=14410

The line I suggested, “iface = NetworkInterface.GetAllNetworkInterfaces(0)”, should either be removed or replaced depending on your event handlers:
[ul]if you decide to handle “ethernet_ENC28.NetworkAddressChanged”, remove the line; otherwise,[/ul][ul]replace it with a call to “RefreshNetworkInterface”[/ul]


#15

@ Jeff, thanks for the reply.
The link you send is to a post by Mano, not sure if that is the correct one, but I did add opening the interface, but had a problem in the binding syntax. Following the link you sent (see code below) I get an error
Error 17 Value of type ‘Gadgeteer.Modules.GHIElectronics.Ethernet_ENC28’ cannot be converted to ‘GHI.Premium.Net.NetworkInterfaceExtension’. D:\FIRMWARE\NetMF\Examples\RaptorNetServer\RaptorNetServer\Program.vb 33 63 RaptorNetServer
when I add the line NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28)

I do not understand what you say to remove the line “iface = …” - are you saying I do not need to define a NetworkInterface?

I do not see where to find “RefreshNetworkInterface”. What is it part of?

Sorry to be so much trouble…


Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Seeed
Imports Microsoft.SPOT.Hardware
Imports GHI.Hardware.G400
Imports System
Imports System.Net
Imports System.Collections
Imports Microsoft.SPOT
Imports GHI.Premium.Net
Imports GHI.Premium.Net.EthernetENC28J60
Imports System.Text
Imports System.Threading
Imports Microsoft.SPOT.Net.NetworkInformation
Imports System.Net.Sockets
Imports GHI.Premium.Hardware.LowLevel


Namespace GadgeteerApp1
    Partial Public Class Program
        'Set iface to the first available network interface

        Private Shared WithEvents iface As Microsoft.SPOT.Net.NetworkInformation.NetworkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(1000)

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            ethernet_ENC28.Interface.Open()
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28)  ??????


            iface.EnableDhcp()
            iface.EnableDynamicDns()
            iface.RenewDhcpLease()
            InternetTimer.Start()
        End Sub

        Private Sub ethernet_ENC28_NetworkDown(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkDown
            Debug.Print("network down fired")
        End Sub

        Private listening As Boolean = False
        Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            Dim i As Integer = 0
            Debug.Print("tic...")
            If listening = False Then
                iface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)

                If iface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & iface.IsDhcpEnabled.ToString & ", but no connection")
                    Exit Sub
                Else
                    Debug.Print("Has IP address of " & iface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
                listening = True
            Else
            End If
            Dim clientSocket As Socket = server.Accept ' wait for client to accept
            ' Process the client request.
            ProcessClientRequest(clientSocket)
        End Sub



#16

@ rockybooth - The error message is telling you exactly what is the problem. Check the documentation to see what is the expected parameter for the AssignNetworkingStackTo method, and then provide it with the proper information.


#17

@ Mike - Thanks for the hint. Unfortunately, I do not have a clue what you mean. It is asking for a GHI.Premium.Net.NetworkInterfaceExtension but I do not know how to instantiate it?


#18

Below is my test code. This always connects if useDHCP is FALSE, never connects if true. This sounds like a similar problem as reported in this post today: https://www.ghielectronics.com/community/forum/topic?id=14849&page=2
This, plus the lack of being able to find any working examples for Raptor + Ethernet_ENC28 using DHCP, leads me to conclude that there is a flaw in the driver or underlying code.
Or am I missing something?

Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Seeed
Imports Microsoft.SPOT.Hardware
Imports GHI.Hardware.G400
Imports System
Imports System.Net
Imports System.Collections
Imports Microsoft.SPOT
Imports GHI.Premium.Net
Imports GHI.Premium.Net.EthernetENC28J60
Imports System.Text
Imports System.Threading
Imports Microsoft.SPOT.Net.NetworkInformation
Imports System.Net.Sockets
Imports GHI.Premium.Hardware.LowLevel


Namespace GadgeteerApp1
    Partial Public Class Program

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(1000)

        Private useDHCP As Boolean = False

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            If ethernet_ENC28.Interface.IsOpen Then
                ethernet_ENC28.Interface.Close()
            End If
            ethernet_ENC28.Interface.Open()
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface)
            With ethernet_ENC28.Interface
                Debug.Print("Cable connected = " & .IsCableConnected.ToString)
                Debug.Print("activated = " & .IsActivated.ToString)
                If useDHCP Then
                    .NetworkInterface.EnableDhcp()
                    .NetworkInterface.RenewDhcpLease() ' no clue if this is needed, or if this hurts
                Else
                    .NetworkInterface.EnableStaticIP("192.168.250.234", "255.255.255.0", "192.168.250.1")
                End If
                Dim dnses() As String = {"4.4.4.4", "8.8.8.8"}
                .NetworkInterface.EnableStaticDns(dnses)
            End With

            Debug.Print(ethernet_ENC28.Interface.IsOpen.ToString)

            InternetTimer.Start()
        End Sub

        Private Sub ethernet_ENC28_NetworkDown(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkDown
            Debug.Print("network down fired")
        End Sub

        Private listening As Boolean = False
        Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            Dim i As Integer = 0
            Debug.Print("tic...")
            If listening = False Then
                'iface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)
                Debug.Print(ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)

                If ethernet_ENC28.Interface.NetworkInterface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled.ToString & ", but no connectionL " & ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
                    Exit Sub
                Else
                    Debug.Print(ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
                listening = True

                DisplayNetworkStuff(ethernet_ENC28.Interface.NetworkInterface)
            Else
            End If
                Dim clientSocket As Socket = server.Accept ' wait for client to accept
                ' Process the client request.
                ProcessClientRequest(clientSocket)
        End Sub

        Private Shared Sub ProcessClientRequest(ByVal m_clientSocket As Socket)
            Const c_microsecondsPerSecond As Int32 = 1000000
            ' 'using' ensures that the client's socket gets closed.
            ' Wait for the client request to start to arrive.
            Using m_clientSocket
                Dim buffer() As Byte = New Byte((1024) - 1) {}
                If m_clientSocket.Poll((5 * c_microsecondsPerSecond), SelectMode.SelectRead) Then
                    ' If 0 bytes in buffer, 
                    ' then the connection has been closed,
                    ' reset, or terminated.
                    If (m_clientSocket.Available = 0) Then
                        Return
                    End If
                    ' Read the first chunk of the request 
                    ' (we don't actually do anything with it).
                    Dim bytesRead As Int32 = m_clientSocket.Receive(buffer, m_clientSocket.Available, SocketFlags.None)
                    ' Return a static HTML document to the client.
                    Dim s As String = ("HTTP/1.1 200 OK" & vbCrLf & "Content-Type: text/html; charset=utf-8" & vbCrLf & vbCrLf & "<html><head><title>.NET Micro Framework We" & _
                "b Server</title></head>" + "<body><bold><a href=\""http://www.ghielectronics.com/\"">Learn more about the .NET Micro Framework with" & _
                " FEZ by clicking here</a></bold></body></html>")
                    Dim buf() As Byte = System.Text.Encoding.UTF8.GetBytes(s)
                    Dim offset As Integer = 0
                    Dim ret As Integer = 0
                    Dim len As Integer = buf.Length

                    While (len > 0)
                        ret = m_clientSocket.Send(buf, offset, len, SocketFlags.None)
                        len = (len - ret)
                        offset = (offset + ret)

                    End While
                    Debug.Print("Client endpoint " & m_clientSocket.RemoteEndPoint.ToString)

                    m_clientSocket.Close()
                End If
            End Using
        End Sub

        Private Sub display(s As String)
            Debug.Print(s)
        End Sub

        Private Sub DisplayNetworkStuff(ethernet As NetworkInterface)
            display("_____________________________________________________________")
            display("New address for the ENC28J60 Ethernet Interface ")
            display("_____________________________________________________________")

            display("Is DhCp enabled: " & ethernet.IsDhcpEnabled.ToString)
            display("Is DynamicDnsEnabled enabled: " & (ethernet.IsDynamicDnsEnabled))
            display("NetworkInterfaceType " & (ethernet.NetworkInterfaceType))
            display("Network settings:")
            display("_________________")
            display("IP Address: " & (ethernet.IPAddress))
            display("Subnet Mask: " & (ethernet.SubnetMask))
            display("Default Getway: " & (ethernet.GatewayAddress))
            display("Number of DNS servers:" & (ethernet.DnsAddresses.Length))

            For i As Integer = 0 To ethernet.DnsAddresses.Length - 1
                display(("DNS Server " & i.ToString() & ":") + ethernet.DnsAddresses(i))
            Next

            display("_____________________________________________________________")
        End Sub

        Private Sub ethernet_ENC28_NetworkUp(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkUp
            Debug.Print("Network up fired")
        End Sub
    End Class



#19

Try this

Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports Gadgeteer.Modules.Seeed
Imports Microsoft.SPOT.Hardware
Imports GHI.Hardware.G400
Imports System
Imports System.Net
Imports System.Collections
Imports Microsoft.SPOT
Imports GHI.Premium.Net
Imports GHI.Premium.Net.EthernetENC28J60
Imports System.Text
Imports System.Threading
Imports Microsoft.SPOT.Net.NetworkInformation
Imports System.Net.Sockets
Imports GHI.Premium.Hardware.LowLevel


Namespace GadgeteerApp1
    Partial Public Class Program

        Private Shared server As Socket

        Dim WithEvents InternetTimer As GT.Timer = New GT.Timer(1000)

        Private useDHCP As Boolean = False

        Public Sub ProgramStarted()
            Debug.Print("Program Started")
            If ethernet_ENC28.Interface.IsOpen Then
                ethernet_ENC28.Interface.Close()
            End If
            ethernet_ENC28.Interface.Open()
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface)
            With ethernet_ENC28.Interface
                Debug.Print("Cable connected = " & .IsCableConnected.ToString)
                Debug.Print("activated = " & .IsActivated.ToString)
                If useDHCP Then
                    .NetworkInterface.EnableDhcp()
                    .NetworkInterface.RenewDhcpLease() ' no clue if this is needed, or if this hurts
                Else
                    .NetworkInterface.EnableStaticIP("192.168.250.234", "255.255.255.0", "192.168.250.1")
                End If
               
            End With

            Debug.Print(ethernet_ENC28.Interface.IsOpen.ToString)

            InternetTimer.Start()
        End Sub

        Private Sub ethernet_ENC28_NetworkDown(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkDown
            Debug.Print("network down fired")
        End Sub

        Private listening As Boolean = False
        Private Sub InternetTimer_Tick(timer As Gadgeteer.Timer) Handles InternetTimer.Tick
            Dim i As Integer = 0
            Debug.Print("tic...")
            If listening = False Then
                'iface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0)
				ethernet_ENC28.Interface.RefreshNetworkInterface()
                Debug.Print(ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)

                If ethernet_ENC28.Interface.NetworkInterface.IPAddress = "0.0.0.0" Then
                    Debug.Print("DHCP=" & ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled.ToString & ", but no connectionL " & ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
                    Exit Sub
                Else
					Dim dnses() As String = {"4.4.4.4", "8.8.8.8"}
					.NetworkInterface.EnableStaticDns(dnses)
                    Debug.Print(ethernet_ENC28.Interface.NetworkInterface.IPAddress.ToString)
                End If

                server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'Initialize a local endpoint to listen on the default http port 80
                Dim localEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 80)
                server.Bind(localEndPoint)
                server.Listen(1)
                listening = True

                DisplayNetworkStuff(ethernet_ENC28.Interface.NetworkInterface)
            Else
            End If
                Dim clientSocket As Socket = server.Accept ' wait for client to accept
                ' Process the client request.
                ProcessClientRequest(clientSocket)
        End Sub

        Private Shared Sub ProcessClientRequest(ByVal m_clientSocket As Socket)
            Const c_microsecondsPerSecond As Int32 = 1000000
            ' 'using' ensures that the client's socket gets closed.
            ' Wait for the client request to start to arrive.
            Using m_clientSocket
                Dim buffer() As Byte = New Byte((1024) - 1) {}
                If m_clientSocket.Poll((5 * c_microsecondsPerSecond), SelectMode.SelectRead) Then
                    ' If 0 bytes in buffer, 
                    ' then the connection has been closed,
                    ' reset, or terminated.
                    If (m_clientSocket.Available = 0) Then
                        Return
                    End If
                    ' Read the first chunk of the request 
                    ' (we don't actually do anything with it).
                    Dim bytesRead As Int32 = m_clientSocket.Receive(buffer, m_clientSocket.Available, SocketFlags.None)
                    ' Return a static HTML document to the client.
                    Dim s As String = ("HTTP/1.1 200 OK" & vbCrLf & "Content-Type: text/html; charset=utf-8" & vbCrLf & vbCrLf & "<html><head><title>.NET Micro Framework We" & _
                "b Server</title></head>" + "<body><bold><a href=\""http://www.ghielectronics.com/\"">Learn more about the .NET Micro Framework with" & _
                " FEZ by clicking here</a></bold></body></html>")
                    Dim buf() As Byte = System.Text.Encoding.UTF8.GetBytes(s)
                    Dim offset As Integer = 0
                    Dim ret As Integer = 0
                    Dim len As Integer = buf.Length

                    While (len > 0)
                        ret = m_clientSocket.Send(buf, offset, len, SocketFlags.None)
                        len = (len - ret)
                        offset = (offset + ret)

                    End While
                    Debug.Print("Client endpoint " & m_clientSocket.RemoteEndPoint.ToString)

                    m_clientSocket.Close()
                End If
            End Using
        End Sub

        Private Sub display(s As String)
            Debug.Print(s)
        End Sub

        Private Sub DisplayNetworkStuff(ethernet As NetworkInterface)
            display("_____________________________________________________________")
            display("New address for the ENC28J60 Ethernet Interface ")
            display("_____________________________________________________________")

            display("Is DhCp enabled: " & ethernet.IsDhcpEnabled.ToString)
            display("Is DynamicDnsEnabled enabled: " & (ethernet.IsDynamicDnsEnabled))
            display("NetworkInterfaceType " & (ethernet.NetworkInterfaceType))
            display("Network settings:")
            display("_________________")
            display("IP Address: " & (ethernet.IPAddress))
            display("Subnet Mask: " & (ethernet.SubnetMask))
            display("Default Getway: " & (ethernet.GatewayAddress))
            display("Number of DNS servers:" & (ethernet.DnsAddresses.Length))

            For i As Integer = 0 To ethernet.DnsAddresses.Length - 1
                display(("DNS Server " & i.ToString() & ":") + ethernet.DnsAddresses(i))
            Next

            display("_____________________________________________________________")
        End Sub

        Private Sub ethernet_ENC28_NetworkUp(sender As Gadgeteer.Modules.Module.NetworkModule, state As Gadgeteer.Modules.Module.NetworkModule.NetworkState) Handles ethernet_ENC28.NetworkUp
            Debug.Print("Network up fired")
        End Sub
    End Class

#20

@ Jeff:
ethernet_ENC28.Interface.RefreshNetworkInterface() gives me the following error.

Error 25 ‘refreshnetworkinterface’ is not a member of ‘GHI.Premium.Net.EthernetENC28J60’. D:\FIRMWARE\NetMF\Examples\RaptorNetServer\RaptorNetServer\Program.vb 63 17 RaptorNetServer

I have searched everywhere I can think to find such a method with no luck. I mentioned that in a message in this thread last week when you suggested it the first time.

Has this method just been introduced? I thought I was running the latest code (see list of assemblies below).

By just moving the DNS lines to later in the code makes no difference.

Assembly: GTM.GHIElectronics.Display_HD44780 (4.2.102.0) Attaching deployed file.

Assembly: RaptorNetServer (1.0.0.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.SDCard (4.2.102.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.Ethernet_ENC28 (4.2.102.0) Attaching deployed file.

Assembly: Microsoft.VisualBasic (1.0.0.0) Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.IO (4.2.11.1) Attaching deployed file.

Assembly: GTM.GHIElectronics.UsbClientDP (4.2.102.0) Attaching deployed file.

Assembly: GHI.Premium.Net (4.2.11.1) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.2.102.0) Attaching deployed file.

Assembly: Gadgeteer.SPI (2.42.0.0) Attaching deployed file.

Assembly: GHI.Hardware.G400 (4.2.11.1) Attaching deployed file.

Assembly: GTM.Seeed.Barometer (1.6.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.11.1) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.11.1) Attaching deployed file.

Assembly: GTM.GHIElectronics.LED7C (4.2.102.0) Resolving.