WiFi DHCP problems (0.0.0.0) using EMX

I’m having a similar issue with WiFi. I’m using an EMX based project with firmware 4.2.11.
I’m using a D-LINK DIR-625 router with no password.

I’m experiencing two problems.

(1) Sometimes (most of the time) the wifi.Join returns the following error: “An unhandled exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll”

(2) Other times it will join the network, but the IP address, subnet mask, and gateway are all 0.0.0.0.

Some observations I’ve made…

  • Static IPs work fine
  • I can switch from a static to DHCP and the first time after I do this, the DHCP will work fine.
  • Making a permanent reservation in my router makes no difference

My code is below. The “BigText” function just displays the debug results to my LCD display.

Any thoughts as to what might be going wrong?

Thanks,
Dustin



.......
 wifi = new WiFiRS9110(SPI.SPI_module.SPI1,
       (Cpu.Pin)GHI.Hardware.EMX.Pin.IO2, // Chip Select
       (Cpu.Pin)GHI.Hardware.EMX.Pin.IO26, // Interrupt
       (Cpu.Pin)GHI.Hardware.EMX.Pin.IO3); // Reset

 if (wifi.IsActivated)
      wifi.Close();

 if (!wifi.IsOpen)
       wifi.Open();

 //Enable DHCP
 if (!wifi.NetworkInterface.IsDhcpEnabled)
       wifi.NetworkInterface.EnableDhcp();

 // Set this as the current interface on the TCP/IP stack
 NetworkInterfaceExtension.AssignNetworkingStackTo(wifi);

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

 for (int count2 = 0; count2 < 3; count2++)
 {
       GHINET.WiFiNetworkInfo[] scanResult = wifi.Scan();

       for (int i = 0; i < scanResult.Length; i++)
       {
             if (scanResult[i].SSID.IndexOf("iBoss") == 0)
             {
             BigText("iBoss Found.");
             string passPhrase = "";
             wifi.Join(scanResult[i], passPhrase);
             BigText("Join Successful");
             break;
       }
 }

 try
 {
       if (wifi != null && wifi.IsLinkConnected)
       {
             Thread.Sleep(2000);
             //Debug.Print("Network settings for: Count1 = " + (count1 + 1).ToString() + " Count2 = " + (count2 + 1).ToString());
             Debug.Print("IP Address: " + wifi.NetworkInterface.IPAddress);
             BigText("IP Address: " + wifi.NetworkInterface.IPAddress);
             Debug.Print("Subnet Mask: " + wifi.NetworkInterface.SubnetMask);
             BigText("Subnet Mask: " + wifi.NetworkInterface.SubnetMask);
             Debug.Print("Default Getway: " + wifi.NetworkInterface.GatewayAddress);
             BigText("Default Getway: " + wifi.NetworkInterface.GatewayAddress);
             for (int j = 0; j < wifi.NetworkInterface.DnsAddresses.Length; j++)
             {
                   Debug.Print("DNS Server: " + wifi.NetworkInterface.DnsAddresses[j]);
                   BigText("DNS Server: " + wifi.NetworkInterface.DnsAddresses[j]);
             }
             Debug.Print("------------------------------------------------------");
       }
       else
       {
             Debug.Print("The WiFi link is not connected!");
             BigText("The WiFi link is not connected!");
       }
 }
 catch (SocketException e)
 {
       Debug.Print("DHCP Failed");
       if (e.ErrorCode == 11003) 
       Debug.Print("Re-Enable the module.");
       throw;
 }

 try
 {
       string hostName = "www.ghielectronics.com";
       IPHostEntry myIP = Dns.GetHostEntry(hostName);

       if (myIP != null)
       {
             Debug.Print("Testing access to Internet and DNS:");
             Debug.Print(hostName + ": " + myIP.AddressList[0].ToString());
       }
 }
 catch (SocketException e)
 {
       Debug.Print("Failed to Get the host entry of the FQN from DNS server!");
       if (e.ErrorCode == 11003)
             Debug.Print("Re-Enable the module.");
       throw;
 }

 Debug.Print("------------------------------------------------------");
 Debug.Print("Disconnecting WiFi link.");
 wifi.Disconnect();
 Thread.Sleep(2000);
 }
 Debug.Print("Closing WiFi interface");
 wifi.Close();
 Thread.Sleep(2000);
 }

After doing some more testing. Even with Static IP, I’m getting the following message when trying to join:

A first chance exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll

My code has not changed.

Thanks. I just gave it a try, but am still having the same issue.

I’m really puzzled… I’m still getting an error on the Join:

A first chance exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll

If there is a handler for this exception, the program may be safely continued. One time the code did catch the error and it was error code #7, but it only caught it once. The next time running, everything worked. Now, I get the error all the time again.

I’m getting this error despite my try / catch loop.

Any thoughts?

Thank you.


try
{
  wifi.Join(scanResult[i], passPhrase);
}
catch (GHI.Premium.Net.NetworkInterfaceExtensionException puzzled)
{
  Int16 intErrorCode = Convert.ToInt16(puzzled.errorCode.ToString());
  switch (intErrorCode)
{
  case 0: BigText("Unknown Network Interface"); break;
  case 1: BigText("The Interface is assigned to another object. "); break;
  case 2: BigText("AlreadyActivated "); break;
  case 3: BigText("Currently, only one interface can be activate at a time. Other interface can not be activated before deactivating the active one. "); break;
  case 4: BigText("AlreadyDeactivated"); break;
  case 5: BigText("Already Joined or associated."); break;
  case 6: BigText("The SSID (AP name) provided not found"); break;
  case 7: BigText("Authentication failure or Wrong pass phrase "); break;
  case 8: BigText("Invalid radio channel"); break;
  case 9: BigText("Unknown Error "); break;
  case 10: BigText("The WiFi module is not enabled. "); break;
  case 11: BigText("It means that the system could not communicate with the WiFi module. "); break;
   case 12: BigText("It means that the system could communicate with the WiFi module but it did not get the expected initialization response. This happens when the WiFi module firmware is corrupted. The firmware can be updated using WiFi FirmwareUpdate() method. "); break;
  case 13: BigText("It means that WiFi module firmware version and the current supported version with the hosting system mismatches. The firmware can be updated using WiFi FirmwareUpdate() method."); break;
  case 14: BigText("WiFi module firmware is corrupted. "); break;
  case 15: BigText("Not Supported Feature."); break;
  case 16: BigText("Time out "); break;
  case 17: BigText("The interface is not open. "); break;
}
}

try to put wifi.scan and wifi.join in a retry loop.

Could you step through the code and copy the exception text in the output window here? It should look something like:

#### Exception System.Exception - 0x00000000 (1) ####
#### Message: 
#### GHI.Premium.Net.RS9110Helper::Join [IP: 003b] ####
#### GHI.Premium.Net.WiFiRS9110::Join [IP: 008b] ####
#### EMXWiFi.Program::Main [IP: 00be] ####
#### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (1) ####
#### Message: 
#### GHI.Premium.Net.WiFiRS9110::Join [IP: 00e7] ####
#### EMXWiFi.Program::Main [IP: 00be] ####

A first chance exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll
An unhandled exception of type ‘GHI.Premium.Net.NetworkInterfaceExtensionException’ occurred in GHI.Premium.Net.dll

Could you also show the functions wifi_WirelessConnectivityChanged and wifi_NetworkAddressChanged? Are you using the FEZ Spider or the EMX in a custom board?

Hi. I’ll get this info sent in soon. I’ve been sick the past few days. Thank you.