WiFi RS21 / IP Address Not being assigned

I followed examples and am able to go thur and connect to the available SSID’s. My issue is that the IP Address is never assigned (stays) at 0.0.0.0.

It shows I am connected and the actual DNS is set. If I change the WPa2 key it will indicate that it is incorrect and fails Appears my connection count goes up on my phone hotspot.

In the below code, I provide two connections, one to my local network and the second is to my phone hotspot.

Is there a command that needs to be sent after you join? How long should I wait for this. I inserted a counter to eliminate the infinite loop.

Here is a snapshot of my code…
wifiRS21.UseDHCP();
wifiRS21.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifiRS21_NetworkUp);
wifiRS21.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifiRS21_NetworkDown);

 Debug.Print("Scan for wireless networks");
        wifiRS21.NetworkInterface.Open();
        wifiRS21.NetworkInterface.EnableDhcp();
        wifiRS21.NetworkInterface.EnableDynamicDns();
       
        GHI.Networking.WiFiRS9110.NetworkParameters[] scanResult = wifiRS21.NetworkInterface.Scan();
 
        for (int i = 0 ;i < scanResult.Length;i++)
        {
            Debug.Print("Connecting to " + scanResult[i].Ssid.ToString()) ;
            try
            {
                var parms = new GHI.Networking.WiFiRS9110.NetworkParameters();

                parms.Ssid = scanResult[i].Ssid;
                parms.Channel = scanResult[i].Channel;
                parms.NetworkType = GHI.Networking.WiFiRS9110.NetworkType.AccessPoint;
                parms.NetworkType = scanResult[i].NetworkType ;
                parms.SecurityMode = GHI.Networking.WiFiRS9110.SecurityMode.Wpa2;
              
                if (scanResult[i].Ssid == "mynetwork")
                {
                    parms.Key = "mywepkey";
                }
                else
                {
                    parms.Key = "codefrombyphone";
                }
                wifiRS21.NetworkInterface.Join(parms);
            }
            catch (GHI.Networking.WiFiRS9110.JoinException e)
            {
                Debug.Print("Error Message: " + e.Message);
                throw new NotImplementedException();
            }
            break;
        }
        var k = 0 ;
        while (wifiRS21.NetworkInterface.IPAddress == "0.0.0.0" && k < 5)
        {
            Thread.Sleep(500);
            k++;
        }
        var Connected = wifiRS21.IsNetworkUp.ToString();
        var CurrInfo = wifiRS21.NetworkSettings.IPAddress;
        Debug.Print("Ip-Address = " + wifiRS21.NetworkInterface.IPAddress);

Here are results in debug window. (actual comes from NetworkUp/Down Event handlers).

The thread ‘’ (0x3) has exited with code 0 (0x0).
Wired Network is Down
Network is Down
Network is Up
IP Address: 0.0.0.0
Subnet Mask: 0.0.0.0
Gateway: 0.0.0.0
DNS Server: 208.67.222.222
The program ‘[67] Micro Framework application: Managed’ has exited with code 0 (0x0).

I can remember an issue wit the EN28 interface, that when you don’t add an event handler to the NetworkAvialablitityChanged and IPAddressChanged events, the address was never assigned.
The rs21 ethernet object should provide similar events.
May be they have moved to an common NETMF class, it’s been a while.
And may be this issue was already solved, you yours is different.

Anyway you should check any logs of your router if possible, so you can see if your device is requesting an address from the DHCP server.

Also as a next step, you could try a fixed IP address, just to see if it works.

I wouldn’t use the NetworkDown or NetworkUp events but, as Reinhard points out, use the NetworkAvialablitityChanged and IPAddressChanged instead as I find them a more reliable event.

It would also help if you use the code tags in your post in order to make it more readable.

Network Changed Event is not listing in wifiRS21 as an event. Network Up / Down is what is printed in your examples also.

I did try to use a fixed IP using an Ethernet module with similar results.

I am running this on 4.3 Framework with a FEZ Spider 1.0.

I did try to use the FEZ Config tool but after I run, I’m not able to ping.

I’m confused how this all works. To set IP, can you do this with just mini USB? Should I hook up Ethernet? Can I do this with WiFi? Must I run FEZ Config prior to all of this?

I will look into using the code tags. Bear with me as I am new to this stuff.

Also, Codeshare GlieWiFi Scanner shows a variety of methods like:

WiFi.Connect
WiFi.ConnectWEP
WiFi.ConnectWPA
WiFi.ConnectInfrastructure

What library are these in. I don’t see any of those as options.

Take a look at my reply in this post

https://www.ghielectronics.com/community/forum/topic?id=19028&page=1#msg188438

which gives a working example.

Well I read it and attempted to implement. Much cleaner code but same result…

Here are two snapshots of my output in connecting to two different Access Points…

Program Started
Network is Down
The thread ‘’ (0x3) has exited with code 0 (0x0).
Attempt to Join
Scan for wireless networks
Connecting to NOKIA Lumia 928_6945
Netword Availability True
Address : 0.0.0.0

Using mainboard GHI Electronics FEZ Spider version 1.0
Program Started
Program Started
Network is Down
The thread ‘’ (0x3) has exited with code 0 (0x0).
Attempt to Join
Scan for wireless networks
Connecting to Sensible
Netword Availability True
Address : 0.0.0.0

I added an image of the Log from my Router

One more. The ENC28 does not come with an valid MAC Address, so you have to set it with FEZ Config or on startup.
Not sure about the RS21, but if it is the same with this one, you should try to give it a valid MAC Address.
Many DHCP servers have a problem, if the MAC Address is not valid.
There is some code on CodeShare to generate a random and valid MAC address.

try to move:
wifiRS21.NetworkInterface.EnableDhcp();
wifiRS21.NetworkInterface.EnableDynamicDns();

before the NetworkInterface.Open()

It is working now… I’ve tried so many things that quite frankly, I’m not sure what corrected it. Example given by Springo was very helpful but evenso was buried in a lot of dialog.

One thing I did notice was that at one point in the NetworkAvailabilityChanged event to check if (e.Available) before printing IPAddress etc… My output shows it was available before and was printing 0.0.0.0. Perhaps it first assigns 0.0.0.0 and then switches to the DHCP assigned later but Availability doesn’t change?

I only discovered that it was working because I added code to connect to a website and noticed after response came back, IPAddress was actually assigned / correct.

Along the way, I also tried using the FEZ Config. When using WiFi, what are the steps to configure… Select RS910WiFi? Generate MAC? Load/Apply? It would be helpful if I knew the order or what you should see after each step. Is this even required?

Given that this is something that a lot of people would do, I’d like to suggest a tutorial to walk you thru without guess work.}

Thanks again for all your comments and help.

Which kind of makes sense in that the network has too become available before an IP Address can be assigned. You would therefore receive this event first.

Did you not receive an NetworkAddressChanged event after the NetworkAvailabilityChanged event?

@ Fast_EddieD - You should receive an address. The events need to be handled in a particular way to make sure the address can be seen. If you post your code, we can take a look quickly.

Thanks, it works now. May I suggest you post the code you sent by email? I did ask a question so perhaps you can clarify and upload.

@ Fast_EddieD - We are working on getting better documentation up. Most of our extensions have some documentation under https://www.ghielectronics.com/docs