WiFi_RS21 seems to be joining but can't allocate IP address

My WiFi_RS21 module seems to be joining my WiFi network ok in that the Join method executes without throwing an exception but as soon as I try and assign the interface a static IP address (I tried DHCP as well but had similar problems) I do get an exception.

 
wifi_RS21.NetworkDown += new GT.Modules.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown);
wifi_RS21.NetworkUp += new GT.Modules.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp);

//wifi_RS21.UseDHCP();

wifi_RS21.Interface.Open();
NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);

// look for avaiable networks
var scanResults = wifi_RS21.Interface.Scan();

WiFiNetworkInfo myNetwork = null;

// go through each network and print out settings in the debug window
foreach (var result in scanResults)
{
	Debug.Print("****" + result.SSID + "****");
	Debug.Print("ChannelNumber = " + result.ChannelNumber);
	Debug.Print("networkType = " + result.networkType);
	//Debug.Print("PhysicalAddress = " + GetMACAddress(result.PhysicalAddress));
	Debug.Print("RSSI = " + result.RSSI);
	Debug.Print("SecMode = " + result.SecMode);

	if (result.SSID == WIFI_NETWORK)
	{
		myNetwork = result;
	}
}

if (myNetwork != null)
{
	wifi_RS21.Interface.Join(myNetwork, WIFI_PASSWORD);
	Debug.Print("Network joined");

	wifi_RS21.UseStaticIP("10.1.1.25", "255.255.255.0", "10.1.1.1", new string[] { "10.1.1.1" });
}

The output from the debugger is:

[quote]Using mainboard GHI Electronics FEZSpider version 1.0
Program Started
Camera now connected
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
aza
ChannelNumber = 6
networkType = 1
RSSI = 46
SecMode = 2
The thread ‘’ (0x3) has exited with code 0 (0x0).
Network joined
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) ####
#### Message:
#### Gadgeteer.Modules.Module+NetworkModule::UseStaticIP [IP: 000f] ####
#### GadgeteerApp4.Program::t_Tick [IP: 011c] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type ‘System.NullReferenceException’ occurred in Gadgeteer.dll
Exception performing Timer operation
Network Up event; state = Down[/quote]

Any ideas what I’m doing wrong?

Try different wireless securities - http://www.tinyclr.com/forum/topic?id=9995 . It’s not the same exception, but it’s worth to try.

enable static ip before you join?

aaronc

Not sure about Join but I ‘Think’ it also happened to me using Join.

I DO KNOW that it happened to me on Connect

Partial code Snip…



//Using GHI .NET Micro Framework 4.2

        void StartWIFI()
        {
            wifi_RS21.Interface.Open();

            if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)
                wifi_RS21.Interface.NetworkInterface.EnableDhcp();
   
            wifi_RS21.Interface.WirelessConnectivityChanged += 
                new WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
            wifi_RS21.Interface.NetworkAddressChanged += 
                new WiFiRS9110.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
            
            WiFiRS9110.AssignNetworkingStackTo(wifi_RS21.Interface);

            try
            {
                WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan(ssid);
                
                //Use to Scan for all SSID's
                //WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan( ); 

                if (ScanResp != null && ScanResp.Length > 0)
                {
                    //Your passkey needed here
                    wifi_RS21.Interface.Join(ScanResp[0], PassKey);
                    if (useDebug) { Debug.Print("Connected to Wireless network - " + ssid); }
                }
                else
                {
                    if (useDebug) { Debug.Print("Failed to connect to Wireless network - " + ssid); }
                }
            }
            catch (Exception e)
            {
                Debug.Print("!!Exception : " + e.Message);
            }

            ipep = new IPEndPoint(IPAddress.Parse(ip), port);
            AndroidSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            
            //Exception on Connect(ipep) if a delay is not used?
            //Exception using 1000, 2000,
            //3000 seemed to work without an exception,, So I'll use 4000 ;>)

            Thread.Sleep(4000);
            
            AndroidSocket.Connect(ipep);

            //Inform user that connection was successful
            multicolorLed.TurnGreen();
           
            //Send a greeting message to the Android device
            data = Encoding.UTF8.GetBytes("Hello from the Fez Spider.");

            //Send greeting to the Android Tablet
            AndroidSocket.Send(data);

            //ReceiveDataThread = new Thread(ReceiveData);
            //ReceiveDataThread.Start();

            Readtimer = new Timer(new TimerCallback(ReceiveData), null, 100, 500);

            Thread.Sleep(Timeout.Infinite);
        }




See my comments in code above
//Exception on Connect(ipep) if a delay is not used?
//Exception using 1000, 2000,
//3000 seemed to work without an exception, So I’ll use 4000 ;>)

Thread.Sleep(4000);

ERROR WITHOUT Delay added shown below.

No error with Thread.Sleep(4000); added

I do not know why the delay is needed but adding it solved my problem. (Took me hours to solve)
Frankly, I just added the delay on a wild thought…

RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
The thread ‘’ (0x3) has exited with code 0 (0x0).
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::poll [IP: 0000] ####
#### System.Net.Sockets.Socket::Poll [IP: 0011] ####
#### System.Net.Sockets.Socket::Connect [IP: 0029] ####
#### AndroidWifiSpider.Program::StartWIFI [IP: 010b] ####
#### AndroidWifiSpider.Program::Startbutton_ButtonPressed [IP: 004d] ####
#### Gadgeteer.Modules.GHIElectronics.Button::OnButtonEvent [IP: 0058] ####
#### Gadgeteer.Modules.GHIElectronics.Button::_input_Interrupt [IP: 0068] ####
#### Gadgeteer.Interfaces.InterruptInput::OnInterruptEvent [IP: 0055] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
Error invoking method “Gadgeteer.Interfaces.InterruptInput” (check arguments to Program.BeginInvoke are correct)

The delay was indeed part of my problem although the thing which threw me is getting a NetworkUp event with a state of Down.

I guess that’s normal and the state refers to the IP address allocation or something above the physical level.

Thanks to willgeorge’s sample I was able to get up and running and the wifi_RS21.Interface.NetworkAddressChanged event was the key one to know that the WiFi adapter is actually working and ready to start doing something with.

I suspect the tutorial at http://wiki.tinyclr.com/index.php?title=WiFi_RS21_Module could do with an update as running the code sample in it OOB does not work.