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);
}