If you have a problem obtaining an IP over DHCP (or if you are not), please provide the exact info below to help us nail down the mystery. We have never had any issues at GHI but others have reported issues and we need your help to get this resolved quickly.
- Make sure you are running the latest firmware on your device GHI Electronics – Where Hardware Meets Software
- Run the code the bottom of this post
- What device are you running? What revision of the board?
- What interface? WiFi RS21, ENC28 (external Ethernet) or J11D (internal Ethernet) and what revision of the board?
- Description of network setup. (Modem, router, device and how they connect)
- Network hardware. (How many routers, sub nets etc)
- Outcome. Please include what happens after both a soft reboot (redeploy) and hard reboot (reset button).
If you had to alter code for any reason, such as using another mainboard or module, please include that information.
// The following example is a Console Project running on CobraII using the onboard Wifi.
// References:
// GHI.Premium.Hardware.G120
// GHI.Premium.Net
// Microsoft.SPOT.Hardware
// Microsoft.SPOT.Native
// Microsoft.SPOT.Net
// mscorlib
public class Program
{
public static GHINET.WiFiRS9110 wifi;
public static void Main()
{
wifi = new GHINET.WiFiRS9110(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, G120.Pin.P1_10, G120.Pin.P2_11, G120.Pin.P1_9, 4000);
if (!wifi.IsOpen)
wifi.Open();
if (!wifi.NetworkInterface.IsDhcpEnabled)
wifi.NetworkInterface.EnableDhcp();
wifi.NetworkAddressChanged += new GHINET.NetworkInterfaceExtension.NetworkAddressChangedEventHandler(wifi_NetworkAddressChanged);
wifi.WirelessConnectivityChanged += new GHINET.WiFiRS9110.WirelessConnectivityChangedEventHandler(wifi_WirelessConnectivityChanged);
GHINET.NetworkInterfaceExtension.AssignNetworkingStackTo(wifi);
GHINET.WiFiNetworkInfo[] scanResult = wifi.Scan();
for (int i = 0; i < scanResult.Length; i++)
{
if (scanResult[i].SSID == "Access Point Name")
{
wifi.Join(scanResult[i], "Access Point Password");
break;
}
}
Thread.Sleep(-1);
}
static void wifi_WirelessConnectivityChanged(object sender, GHINET.WiFiRS9110.WirelessConnectivityEventArgs e)
{
Debug.Print("Wireless is: " + (e.IsConnected ? "Connected" : "Disconnected"));
Debug.Print("SSID: " + e.NetworkInformation.SSID);
Debug.Print("WiFi Channel number: " + e.NetworkInformation.ChannelNumber);
DisplayNetworkType(e.NetworkInformation);
DisplayMACAddress(e.NetworkInformation);
Debug.Print("RSSI: -" + e.NetworkInformation.RSSI + "dB");
DisplaySecurityMode(e.NetworkInformation);
}
static void wifi_NetworkAddressChanged(object sender, EventArgs e)
{
Debug.Print("New address for the Wireless Network Interface ");
Debug.Print("Is DhCp enabled: " + wifi.NetworkInterface.IsDhcpEnabled);
Debug.Print("Is DynamicDnsEnabled enabled: " + wifi.NetworkInterface.IsDynamicDnsEnabled);
Debug.Print("NetworkInterfaceType " + wifi.NetworkInterface.NetworkInterfaceType);
Debug.Print("Network settings:");
Debug.Print("IP Address: " + wifi.NetworkInterface.IPAddress);
Debug.Print("Subnet Mask: " + wifi.NetworkInterface.SubnetMask);
Debug.Print("Default Gateway: " + wifi.NetworkInterface.GatewayAddress);
Debug.Print("Number of DNS servers:" + wifi.NetworkInterface.DnsAddresses.Length);
for (int i = 0; i < wifi.NetworkInterface.DnsAddresses.Length; i++)
Debug.Print("DNS Server " + i.ToString() + ":" + wifi.NetworkInterface.DnsAddresses[i]);
Debug.Print("------------------------------------------------------");
}
#region Helpers
static void DisplayNetworkType(GHINET.WiFiNetworkInfo info)
{
switch (info.networkType)
{
case GHINET.NetworkType.AccessPoint:
{
Debug.Print("Wireless Network Type: Access Point");
break;
}
case GHINET.NetworkType.AdHoc:
{
Debug.Print("Wireless Network Type: Ad Hoc");
break;
}
}
}
static void DisplayMACAddress(GHINET.WiFiNetworkInfo info)
{
string MAC = new string(null);
int splitCount = 0;
for (int i = 0; i < info.PhysicalAddress.Length; i++)
{
MAC += (info.PhysicalAddress[i].ToString("X"));
if (splitCount < 5)
{
MAC += ":";
splitCount++;
}
}
Debug.Print("MAC Address: " + MAC);
}
static void DisplaySecurityMode(GHINET.WiFiNetworkInfo info)
{
switch (info.SecMode)
{
case GHINET.SecurityMode.Open:
{
Debug.Print("Wireless Security Mode: Open");
break;
}
case GHINET.SecurityMode.WEP:
{
Debug.Print("Wireless Security Mode: WEP");
break;
}
case GHINET.SecurityMode.WPA:
{
Debug.Print("Wireless Security Mode: WPA");
break;
}
case GHINET.SecurityMode.WPA2:
{
Debug.Print("Wireless Security Mode: WPA2");
break;
}
}
}
#endregion
}