Potential IPAddress Bug in Wifi

First I wanted to say great job on the wifi module updates and overall 4.2 upgrade!

I have been able to successfully connect and disconnect wifi without a problem.

However, my up address keeps coming up 0.0.0.0 no matter what. My init setting code is:


 // Set the object up
            wifi.Interface.Open();
            wifi.Interface.NetworkInterface.EnableDhcp();

            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi.Interface);
                     
            wifi.Interface.WirelessConnectivityChanged += new GHI.Premium.Net.WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);

            t = new Thread(new ThreadStart(Connect));
            t.Start();

Some of the output I get:
Using mainboard GHI Electronics FEZSpider version 1.0
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Connecting to Home_Slow
IsConnected: True
Network is Up

The thread ‘’ (0x6) has exited with code 0 (0x0).
IsLinkConnected: True
IsOpen: True
IsActivated: True
IsNetworkConnected: True
IsNetworkUp: False
IPAddress: 0.0.0.0

I’m I doing something wrong? I thought DHCP was supposed to pull an available IP address? I need this IP address to start a local web server.
Thanks!

@ Weston Bridgewater - for me 30% of the time I get leased an IP address and the and rest of the time nothing… Interface_WirelessConnectivityChanged gets fired but not the Interface_NetworkAddressChanged event.

@ carpenoctem I tried that static IP setup and that works fine but not the DHCP

The same thing is happening to me under 4.2 using FEZspider and a WiFi RS21 module. It seems like all the signals are okay, just DHCP fails to do it’s service (it worked normally under 4.1 using the non-premium library). Static IP works, but fails to create a web server.

What I get back using DHCP:


------------------------------------------------
IP Address:   0.0.0.0
DHCP Enabled: True
Subnet Mask:  0.0.0.0
Gateway:      0.0.0.0
DNS server:   208.67.222.222
------------------------------------------------
Actvated: True
Link connected: True
------------------------------------------------
Web server started at http://0.0.0.0:80/

Any ideas for a workaround? Thanks, I’d appreciate it.

We are investigating this still.

calling wifiMod.Interface.Open(); seemed to intermittently fail on socket 6 and then constantly started failing; right now I just moved to socket 9 and I haven’t received the exceptions I was getting on socket 6. hope this helps at all.

Hm… now NetworkInterfaceExtension.AssignNetworkingStackTo(wifi.Interface); is causing exceptions:

#### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (1) ####
#### Message: 
#### GHI.Premium.Net.NetworkInterfaceExtension::Activate [IP: 001a] ####
#### Via_prototype.Program::ProgramStarted [IP: 003b] ####
#### Via_prototype.Program::Main [IP: 0015] ####

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

Switching sockets doesn’t help.

@ carpenoctem - now when connected to another network I get an exception when I either SCAN and JOIN or just explicitly JOIN:

#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (8) ####
#### Message: 
#### PetComm.Program::ConnectToWifiNetwork [IP: 005e] ####
#### PetComm.Program::InitializationStep2OnSecondaryThread [IP: 001f] ####

A first chance exception of type ‘System.NullReferenceException’ occurred in PetComm.exe
#### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (8) ####
#### Message:
#### GHI.Premium.Net.WiFiRS9110::Join [IP: 0027] ####
#### PetComm.Program::ConnectToWifiNetwork [IP: 013e] ####
#### PetComm.Program::InitializationStep2OnSecondaryThread [IP: 001f] ####

Is there an alternative library that I can use until this is resolved? It was working normally under 4.1, but since the wifi features now moved to the Premium library, is there a way I can still use the old library? Or maybe some other suggestions?

I hate to bitch, but I have a project on hold because of this.

This shouldn’t take more than one or 2 weeks but if you need it sooner then you can try 4.1 if this helps.

We just noticed this

NetworkInterfaceExtension.AssignNetworkingStackTo(wifi.Interface);

it should be

NetworkInterfaceExtension.AssignNetworkingStackTo(wifi);

I tried that but get this error when I do that:


NetworkInterfaceExtension.AssignNetworkingStackTo(wifi);

Error	2	Argument 1: cannot convert from 'Gadgeteer.Modules.GHIElectronics.WiFi_RS21' to 'GHI.Premium.Net.NetworkInterfaceExtension'	C:\Users\Weston\Google Drive\Senior Project\Past Projects\Wifi_Test\Wifi_Test\Wifi_Test\Program.cs	35	63	Wifi_Test
Error	1	The best overloaded method match for 'GHI.Premium.Net.NetworkInterfaceExtension.AssignNetworkingStackTo(GHI.Premium.Net.NetworkInterfaceExtension)' has some invalid arguments	C:\Users\Weston\Google Drive\Senior Project\Past Projects\Wifi_Test\Wifi_Test\Wifi_Test\Program.cs	35	13	Wifi_Test


private void InitializeModules()
        {   
            // Initialize GTM.Modules and event handlers here.		
            wifi = new GTM.GHIElectronics.WiFi_RS21(6);
        }

I have no idea if this has anything to do with anything, but I’ve just noticed that GHI.Premium.Net library includes misspelled “network” a couple of times (e.g. “AssignedNetwrokInterface”).

Either way, still nothing wrong if you correct it. :slight_smile:

Hello, this is the code that works for me (partially - code works for network at my work, at my home does not work, but I think that’s because some kind of problem with my router)

void ConnectMe()
        {
            if (!wifi_RS21.Interface.IsOpen)
                wifi_RS21.Interface.Open();
 
            if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)
                wifi_RS21.Interface.NetworkInterface.EnableDhcp();
 
            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);
 
            wifi_RS21.Interface.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
            wifi_RS21.Interface.NetworkAddressChanged       += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
            wifi_RS21.NetworkDown                           += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_RS21_NetworkDown);
            wifi_RS21.NetworkUp                             += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_RS21_NetworkUp);
 
            WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan("MyAP");
            if (ScanResp != null && ScanResp.Length > 0)
                wifi_RS21.Interface.Join(ScanResp[0], "MyPwd");
 
            Debug.Print("Connected to network...");
            Gadgeteer.Networking.HttpRequest wc = WebClient.GetFromWeb("http://www.google.com");
            wc.ResponseReceived += new HttpRequest.ResponseHandler(wc_ResponseReceived);
            Debug.Print("Waiting for response...");
        }
 
        void wifi_RS21_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("NetworkUp event!");
        }
 
        void wifi_RS21_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("NetworkDown event!");
        }
 
        void Interface_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("WirelessConnectivityChanged event!");
            Debug.Print("IP Address : " + wifi_RS21.Interface.NetworkInterface.IPAddress);
        }
 
        void wc_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("Response is received");
            string text = response.Text;
        }
 
        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("NetworkAddressChanged event!");
            Debug.Print("IP Address : " + wifi_RS21.Interface.NetworkInterface.IPAddress);
        }

@ tvinko Which socket are you using? Does it work normally on both 6 and 9?

NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);

This gives me an exception every time, no matter the socket I use.

NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21);

This gives me the same error as Weston Bridgewater gets.

Work on 9 and 6. Do you get socket error? What is error code?

From Gus’ message earlier, you do not pass the .Interface of your wifi object to the Assign Networking Stack call.

I’m using 4.2 sdk, and AssignNetworkingStackTo method doesn’t support wifi_RS21 object, but it’s interface property. I’m programming in Micro Framework for two days now, so I could say some nonsense things…

@ brett

To clarify again, if I do not pass it, I get this error:

Error	2	Argument 1: cannot convert from 'Gadgeteer.Modules.GHIElectronics.WiFi_RS21' to 'GHI.Premium.Net.NetworkInterfaceExtension'	C:\Users\jure\AppData\Local\Temporary Projects\GadgeteerApp1\Program.cs	40	63	GadgeteerApp1

If I do pass it, I get this exception:

    #### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (1) ####
    #### Message: 
    #### GHI.Premium.Net.NetworkInterfaceExtension::Activate [IP: 001a] ####
    #### GadgeteerApp1.Program::ProgramStarted [IP: 0024] ####
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