Network problem WIZnet

I just recieved my Rhino with WIZnet. I’m using version 4.1.3.0 of the GHI SDK. I tried the simple webserver code from the documentation. I can’t get it to work. I’m sure i’ve set the ip, subnetmask, gateway and subnetmask correctly. I’ve searched the forum and found this thread: [url]http://www.tinyclr.com/forum/13/2216/[/url]
So I tried the tip to connect the device straight to a laptop without a switch. It worked straight away. When I connect the device and laptop to the Cisco SLM2024 switch it doesn’t work anymore. So it seems the device cann’t communicate through the switch. I even tried adding the dhcp lease manualy in the windows 2008 dhcp server as suggested in the forum thread, but that didn’t make any difference. How is this possible? What could be a next step to troubleshoot this problem?

what IP address did your PC get that could communicate to the device? What IP address did you put in your code?

The way to test this all is to set your IP address and subnet mask. That way you know things should work - while I think we all trust DHCP works, it’s another variable that is worth avoiding if possible. So if you have a Win2008 DHCP server, just enter a reservation in the DHCP scope, and then hardcode that address and a ficticious MAC address into your code, and try again.

HEre’s some minimal code that you can load onto your device (change pins as appropriate, it’s for a Panda with a Wiz812 module )

If you step to this point in the code or set a breakpoint, then the module at this point will respond to ICMP. I’ve just tested it on my board now, I can PING 192.168.0.22 and get a response (from Win7 machine) and I am connected to a Billion ADSL router with gigabit ethernet ports and PC on wireless.


            const Int32 c_port = 80;
            byte[] ip = { 192, 168, 0, 22 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 0, 254 };
            byte[] mac = { 00, 12, 12, 12, 12, 12 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di8, (Cpu.Pin)FEZ_Pin.Digital.Di10,false);
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 0, 254 });
            Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);
            server.Bind(localEndPoint);
            server.Listen(1);//Int32.MaxValue);

Are you sure you don’t have a MAC address conflict?

Thanks for the reply.
My device has the following network configuration:
IP: 192.168.1.201
Subnet: 255.255.255.0
Gateway: 192.168.1.1

The laptop has the following static network configuration (static so I can connect the device directly without changing settings)
IP: 192.168.1.199
Subnet: 255.255.255.0
Gateway: 192.168.1.1

My network is setup with a windows 2008 DHCP server with the pool: 192.168.1.11 <-> 192.168.1.100 with 192.168.1.1 for the router.

So if I connect the device directly with one cable to the laptop, it works. When I only disconnect this cable and connect the device and the laptop to the switch it doesn’t work any more.
I use the following code on the device:


using System;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
using GHIElectronics.NETMF.Net.NetworkInformation;

using Socket = GHIElectronics.NETMF.Net.Sockets.Socket;

/// <summary>
/// This is a simple web server. Given a request, it returns an HTML document. 
/// The same document is returned for all requests and no parsing of
/// the request is done.
/// </summary>
public static class MySocketServer {
    public static void Main() {
        const Int32 c_port = 80;

        byte[] ip = { 192, 168, 1, 201 };
        byte[] subnet = { 255, 255, 255, 0 };
        byte[] gateway = { 192, 168, 1, 1 };
        byte[] mac = { 1, 2, 3, 4, 5, 6 };

        WIZnet_W5100.Enable(SPI.SPI_module.SPI1,
                            (Cpu.Pin)38,
                            (Cpu.Pin)67, true);

        NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
        NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 1, 3 });

        Socket server = new Socket(AddressFamily.InterNetwork,
        SocketType.Stream, ProtocolType.Tcp);

        IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);

        server.Bind(localEndPoint);
        server.Listen(1);

        while (true) {
            // Wait for a client to connect.
            Socket clientSocket = server.Accept();

            // Process the client request. true means asynchronous.
            new ProcessClientRequest(clientSocket, true);
        }
    }
    /// <summary>
    /// Processes a client request.
    /// </summary>
    internal sealed class ProcessClientRequest {
        private Socket m_clientSocket;
        /// <summary>
        /// The constructor calls another method to handle the request, 
        /// but can optionally do so in a new thread.
        /// </summary>
        /// <param name="clientSocket"></param>
        /// <param name="asynchronously"></param>
        public ProcessClientRequest(Socket clientSocket,
                                    Boolean asynchronously) {
            m_clientSocket = clientSocket;
            if (asynchronously)
                // Spawn a new thread to handle the request.
                new Thread(ProcessRequest).Start();
            else ProcessRequest();
        }
        /// <summary>
        /// Processes the request.
        /// </summary>
        private void ProcessRequest() {
            const Int32 c_microsecondsPerSecond = 1000000;
            // 'using' ensures that the client's socket gets closed.
            using (m_clientSocket) {
                // Wait for the client request to start to arrive.
                Byte[] buffer = new Byte[1024];
                if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,
                SelectMode.SelectRead)) {
                    // If 0 bytes in buffer, 
                    // then the connection has been closed,
                    // reset, or terminated.
                    if (m_clientSocket.Available == 0)
                        return;
                    // Read the first chunk of the request 
                    // (we don't actually do anything with it).
                    Int32 bytesRead = m_clientSocket.Receive(buffer,
                    m_clientSocket.Available, SocketFlags.None);

                    // Return a static HTML document to the client.
                    String s =
                    "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<html><head><title>.NET Micro Framework Web Server on USBizi Chipset </title></head>"
                    + "<body><bold><a href=\"http://www.tinyclr.com/\">Learn more about the .NET Micro Framework with FEZ by clicking here</a></bold></body></html>";
                    byte[] buf = Encoding.UTF8.GetBytes(s);
                    int offset = 0;
                    int ret = 0;
                    int len = buf.Length;
                    while (len > 0) {
                        ret = m_clientSocket.Send(buf, offset, len,
                                                  SocketFlags.None);
                        len -= ret;
                        offset += ret;
                    }
                    m_clientSocket.Close();
                }
            }
        }
    }
}

Nothing works, not even ping?


NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 1, 3 });

Wrong ip here?

When connected to the switch nothing works.
192.168.1.3 is my DNS server in the network.

Tried ping?

Jep:

Reply from 192.168.1.199: Destination host unreachable.

It definitely has something to do with the Cisco switch. When I connect the device directly to a lan port of the router and access it with another computer connected to a lan port on the router it works. The cisco switch is also connected to a lan port on the router. When I try to connect to the device on the laptop connected to the cisco switch it doesn’t work. So the switch is somehow blocking the communication of the device.
In my oppinion the WIZnet has some compatibility issues. The Cisco switch is manageble and had never trouble with it before. I will try to find why the switch blocks communication with the device. Any tips are apreciated.

Try to clean the ARP cash on your PC

arp -c

I tried all kind of settings in the switch to get it working. Eventualy restoring the switch configuration back to factory defaults did the trick.

You say it’s a managed switch. Can it be the switch had a duplicated IP in your setup?