Main Site Documentation

Auto negotiate network speed with spider


#1

We have a problem with a fez spider 1.0 with SDK 4.2.10.1 it hangs when network is being initialized. Based on the debug info it seems to have a problem to agree on the network speed. It fails to obtain a ip address from dhcp or even with a static address it is a problem.

We are migrating from 4.1.8.x sdk to 4.2.10.1 and on several different locations the problem occurs. Mostly common network config is a router -> switch (-> switch) -> fez spider.

Because the switches are unmanaged we can’t set it to fixed speed (10 or 100mbps).

Does this sound familiar?

Network initialization code:

 void InitNic()
        {
            try
            {
                ethernet_J11D.Interface.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(ethernet_CableConnectivityChanged);
                ethernet_J11D.Interface.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(ethernet_NetworkAddressChanged);

                //ethernet_J11D.Interface.NetworkInterface.PhysicalAddress = Utils.MacAddressStringToBytes(MacAddress);
                byte[] macaddr = Utils.MacAddressStringToBytes(MacAddress);
                Util.SetMACAddress(NetworkInterface.Built_In_Ethernet , macaddr);

                ethernet_J11D.Interface.Open();

                if (NetworkInterfaceExtension.AssignedNetworkInterface == null)
                {
                    NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_J11D.Interface);
                }
                else
                {
                    if (NetworkInterfaceExtension.AssignedNetworkInterface.NetworkInterface.NetworkInterfaceType != Microsoft.SPOT.Net.NetworkInformation.NetworkInterfaceType.Ethernet)
                        NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_J11D.Interface);
                }
                if (ethernet_J11D.Interface.IsActivated && ethernet_J11D.Interface.IsOpen && ethernet_J11D.Interface.IsCableConnected)
                {

                    if (UseDHCP)
                    {
                        if (ethernet_J11D.Interface.NetworkInterface.IsDhcpEnabled)
                        {
                            DebugPrint("Renewing DHCP Lease");
                            ethernet_J11D.Interface.NetworkInterface.RenewDhcpLease();
                            ethernet_J11D.Interface.NetworkInterface.EnableDynamicDns();
                        }
                        else
                        {
                            DebugPrint("Enabling DHCP");
                            ethernet_J11D.Interface.NetworkInterface.EnableDhcp();
                            ethernet_J11D.Interface.NetworkInterface.EnableDynamicDns();
                        }
                        int waitSecs = 10;
                        IPAddress ip = IPAddress.GetDefaultLocalAddress();
                        while (ip == IPAddress.Any && waitSecs > 0)
                        {
                            Thread.Sleep(1000);
                            waitSecs--;
                            ip = IPAddress.GetDefaultLocalAddress();
                        }
                    }
                    else
                    {
                        DebugPrint("Assigning static IPAddress");
                        if (AddGoogleDNS)
                        {
                            ethernet_J11D.Interface.NetworkInterface.EnableStaticDns(new String[] { dns, "8.8.8.8", "8.8.4.4" });
                        }
                        else
                        {
                            ethernet_J11D.Interface.NetworkInterface.EnableStaticDns(new String[] { dns });
                        }
                        ethernet_J11D.Interface.NetworkInterface.EnableStaticIP(IP_Address, Subnetmask, Gateway);
                    }
                }
            }
            catch (Exception e)
            {
                DebugPrint(e.Message);
            }
        }

Modified: added code snippet


#2

@ Patrick -

if Auto negotiate failed then the speed will be fixed at 100m, will that be a problem?


#3

Hi Dat, no that wouldn’t be a problem. But the main issue is that it keeps negotiating over and over again.

-Edit- Did I initialize the NIC correctly, should I change things in code, please advise?


#4

No, as a matter of fact no there is no special reason (anymore). It must be a left over during development stage, because there is a network address change event active. I totally missed it… :frowning:

I’ll get rid of it and give it a try tomorrow.