System.Net.WebException: host not available

Hi All,

Today I updated one of my FEZ cobra boards to latest 4.2 firmware. It is also running exactly the same configuration and code as another box (Cobra + RS21) however on this box, I always seem to get the above host not available exception. Any ideas why?

Extract of log:

RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5

Network settings:
IP Address: 10.1.1.76
Subnet Mask: 255.255.0.0
Default Getway: 10.1.1.254
DNS Server: 10.1.1.254
Getting from google
LWIP Assertion “DNS response for wrong host name” failed at line 1251 in C:\MicroFrameworkPK_v4_2\DeviceCode\GHI\pal\lwip\lwip_1_3_2\src\api\api_msg.c

Web Exception caught [System.Net.WebException: host not available]

I have put in a simple test to check it:

HttpWebRequest httpRequest = HttpWebRequest.Create("http://www.google.com") as HttpWebRequest;
                try
                {
                    Debug.Print("Getting from google");
                    httpRequest.GetResponse();
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.ToString());
                }

I have another box that is running fine, and connect to the internet without any issues, all the PCs in the house connect / resove DNS OK, it just seems to be this box. Is there a way to test the RS21 to make sure it is behaving as it should? I have tried re-flashing to 4.2 again, but still get the same issue.

the error talks about DNS failure, can you explore that a bit? Do some DNS lookups and see what is being returned.b

I’ve tried a basic sample, code and error is below. Help appreciated, quite stuck and getting frustrated!!

 public class Program
    {
        static WiFiRS9110 wifi;
        public static void Main()
        {
            string ssid = "AAA";
            string phrase = "BBB";

            //FEZ Cobra OEM board V1.2 or V1.3 UEXT header with WiFi RS21 Module: P/N:GHI-WIFIEXP2-298
            SPI.SPI_module _spi = SPI.SPI_module.SPI2; /*SPI bus*/
            Cpu.Pin chipSelect = GHI.Premium.Hardware.EMX.Pin.IO2; /*ChipSelect*/
            Cpu.Pin externalInterrupt = GHI.Premium.Hardware.EMX.Pin.IO26; /*External Interrupt*/
            Cpu.Pin resetPin = GHI.Premium.Hardware.EMX.Pin.IO3; /*Reset*/

            // Create the object
            wifi = new WiFiRS9110(_spi, chipSelect, externalInterrupt, resetPin);

            // Subscribe to events
            wifi.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(wifi_WirelessConnectivityChanged);
            wifi.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(wifi_NetworkAddressChanged);


            // Set the object up
            if (!wifi.IsOpen)
                wifi.Open();

            Debug.Print("Using Static IP");
            wifi.NetworkInterface.EnableStaticDns(new string[] { "1.1.1.254" });
            wifi.NetworkInterface.EnableStaticIP("10.1.1.43", "255.255.0.0", "10.1.1.254");

            Debug.Print("Scanning for network.");

            // Scan for networks
            WiFiNetworkInfo[] ScanResp = wifi.Scan();


            int i = 0;
            for (i = 0; i < ScanResp.Length; i++)
            {
                if (string.Compare(ScanResp[i].SSID, ssid) == 0)
                {
                    break;
                }
            }


            // Join your network
            wifi.Join(ScanResp[i], phrase);

            Debug.Print("Joined.");

            Thread.Sleep(2000);

            if (wifi.IsLinkConnected)
            {
                Debug.Print("Network details set.");

                var details = Dns.GetHostEntry("google.com");

                Debug.Print("Found DNS: " + details.AddressList.Length);
                foreach (var x in details.AddressList)
                {
                    Debug.Print(x.ToString());
                }

            }
            else
            {
                Debug.Print("Not connected");
            }
            Thread.Sleep(-1);
           
        }

        static void wifi_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + wifi.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + wifi.NetworkInterface.SubnetMask);
            Debug.Print("Default Getway: " + wifi.NetworkInterface.GatewayAddress);
            Debug.Print("DNS Server: " + wifi.NetworkInterface.DnsAddresses[0]);
        }

        static void wifi_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("Is Connected? " + e.IsConnected.ToString());
        }


    }

Debug output:

RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Using Static IP
Scanning for network.
Is Connected? True
Network settings:
IP Address: 10.1.1.43
Subnet Mask: 255.255.0.0
Default Getway: 10.1.1.254
DNS Server: 1.1.1.254
Joined.
Network details set.
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### EmbeddedCobraTest.Program::Main [IP: 010b] ####
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = -1
An unhandled exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll

#### SocketException ErrorCode = -1

Uncaught exception
The thread ‘’ (0x1) has exited with code 0 (0x0).
#### Exception System.Exception - 0xffffffff (3) ####
#### Message:
#### GHI.Premium.Net.RS9110Helper::QueryConnectionStatus [IP: 0000] ####
#### GHI.Premium.Net.RS9110Helper::CheckForEvent [IP: 001e] ####
An unhandled exception of type ‘System.Exception’ occurred in GHI.Premium.Net.dll

Uncaught exception
The thread ‘’ (0x3) has exited with code 0 (0x0).
Done.
The program ‘[17] Micro Framework application: Managed’ has exited with code 0 (0x0).

Your network doesn’t seem to be working. You are failing to get a response from the DNS server. Can you do any network analysis on your router that can tell you if it’s getting traffic from the device?

Also, have you had this setup working before, or is this the first time you’ve been trying to get it to work?

After playing around a bit, I’ve found out that if i comment out the code as below:

     // Set the object up
            if (!wifi.IsOpen)
                wifi.Open();

            //Debug.Print("Using Static IP");
            //wifi.NetworkInterface.EnableStaticDns(new string[] { "1.1.1.254" });
            //wifi.NetworkInterface.EnableStaticIP("10.1.1.43", "255.255.0.0", "10.1.1.254");

            Debug.Print("Scanning for network.");

The code works as below!

RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Scanning for network.
Is Connected? True
Network settings:
IP Address: 10.1.1.43
Subnet Mask: 255.255.0.0
Default Getway: 10.1.1.254
DNS Server: 1.1.1.254
Joined.
Network details set.
Found DNS: 1
74.125.237.133

Why would setting the details be causing this issue? Is it not safe to always set the static IP details on startup? If not how should I be?

I have another Cobra + RS21 that is running the same WIFI setup code and it works just fine which is the weird thing.

The other one is running 4.1 though, isn’t it? There were a lot of networking changes in 4.2 so there could be an issue…