Change NETMF4.1 to 4.2 with WiFi module

Today, I update 4.1 to 4.2. Try moving my code of 4.1 to 4.2, but not works.

I use WiFi module in MF4.1. It works well ,but the 4.2 methods of WiFi module seems different to 4.1.

The examples do not work on 4.2 ?

http://www.tinyclr.com/codeshare/entry/361

How to change my old code to 4.2?

 private void InitializeWifi()
        {
            WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
            info.SSID = "ZyXEL9FA";
            info.SecMode = WiFi_RS21.SecurityMode.WPA2;
            info.networkType = WiFi_RS21.NetworkType.AccessPoint;
            wiFi_RS21.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wiFi_RS21_NetworkUp);
            wiFi_RS21.UseDHCP();
            wiFi_RS21.Join(info, "sinotech11569326");
           

        }

Thanks andre:
I will try it .
Who can recommend GHI to modify their tutorials?

I think a new user will confused to use this example and will waste time.
So If the new SDK released, maybe the tutorials can be modified in the same time.
It is better for many starters.

Dear andre

The example you gave is for plain NETMF?

I am using Gadegteer.

I change my code to

But can’t get the ip adress,

the Debug output

RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
IP=0.0.0.0
Program Started

         
 bool IsNetWorkUP = false;
string ssid = "ZyXEL9FA";     
        string PassKey = "sinotech11569326";    
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
           
            InitializeWifi();                          
            Debug.Print("Program Started");
        }
        private void InitializeWifi()
        {
                      
            wifi_RS21.Interface.Open();
            wifi_RS21.Interface.NetworkInterface.EnableDhcp();
            wifi_RS21.Interface.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
            try
            {
                WiFiNetworkInfo[] networkinfo = wifi_RS21.Interface.Scan(ssid);               

                if (networkinfo != null && networkinfo.Length > 0)
                {

                    wifi_RS21.Interface.Join(networkinfo[0], PassKey);//networkinfo[0] 
                   IsNetWorkUP = wifi_RS21.Interface.IsLinkConnected;
                  
                }
                
               
            }
            catch (Exception e)
            {
                Debug.Print("!!Exception : " + e.Message);
            }



        }

        void Interface_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("IP="+wifi_RS21.Interface.NetworkInterface.IPAddress);
        }

Tzu Hsuan

Maybe this will be of some help.
WiFi using 4.2 DOES work… Really…

I’m not a expert on anything but I was having problems trying to get WiFi to work using 4.2 and I saw this post.
A question from Weston Bridgewater “However, my up address keeps coming up 0.0.0.0 no matter what.”

http://www.tinyclr.com/forum/topic?id=9411&page=1

In the same post:
Duke Nukem posted some code using a Time Server. I tried it and it worked!

I posted a Project using Dukes code (Modified slightly for my use). I asked his permission to do so.

See: http://www.tinyclr.com/codeshare/entry/605
for the Project based on Dukes code…

This project worked for me and I have seen the ‘no ip’ …

However, I saw the NetworkAddressChanged event more than once and then I saw a valid IP.

Give the code a try and see if it works for you.

As stated: “I take no credit for the original code. I am only passing it along for others.”

Dear willgeorge
Thank you.
Actually, I have down load all your Wifi related project and take a part of your code to modify my code.
I don’t know why it do not work for me, I was also asking in http://www.tinyclr.com/forum/topic?id=9648

Dear andre,
Thank you for your reply.
Because I see

public static void Main()
        {
}

but not

void ProgramStarted()
        {
}

So I guess this is for plain NETMF.

I think i don’t really understand the real difference between the Gadgeteer and plain NETMF.
sorry.

Gadgeteer is a set of libraries that run on top of NETMF to simply accessing gadgeteer mainboards and modules.

Hi, andre
Thanks for your hint, I will try tomorrow.

Thank you Gus, I think I will pay more efforts in NETMF and Gadgeteer in 2013.
I conduct a research project in my company ,I recommend my boss to use GHI’s products to develop.
So I think I will frequently find help in the forum.

Thank you

We are here to help whenever you need us :slight_smile:

Dear willgeorge"
When I run your code (WiFi42), I got errors below.

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

Dear willgeorge"

The socket which you used is difference to mine. I changed it.

But still can’t connect to internet and shows IP=0.0.0.0

Using mainboard GHI Electronics FEZSpider version 1.0
Press button to begin
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
***WirelessConnectivityChanged event!
***RSSI : 66
***IP Address : 0.0.0.0
***Connected to network…
***Waiting for response…
The thread ‘’ (0x3) has exited with code 0 (0x0).
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (5) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### WiFi42.Program::NTPTime [IP: 0008] ####
#### WiFi42.Program::Interface_WirelessConnectivityChanged [IP: 0056] ####
#### GHI.Premium.Net.WiFiRS9110::NetworkChangeExtension_NetworkAvailabilityChanged [IP: 0025] ####
#### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 0099] ####
#### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (5) ####
#### Message:
#### WiFi42.Program::NTPTime [IP: 0109] ####
#### WiFi42.Program::Interface_WirelessConnectivityChanged [IP: 0056] ####
#### GHI.Premium.Net.WiFiRS9110::NetworkChangeExtension_NetworkAvailabilityChanged [IP: 0025] ####
#### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 0099] ####
#### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
A first chance exception of type ‘System.NullReferenceException’ occurred in WiFi42.exe

Time Server : 06/01/2011 00:32:37

#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (6) ####
#### Message: 
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060

A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (6) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (6) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll

An exception occured while connecting to the Internet. Please, make sure that a valid URL is used and a network connection is up.

I have tried two days, but still not work. Depressed.

What’s wrong in my code below?

public partial class Program
    {


        string ssid = "ZyXEL9FA";     // <<<<< You need to enter your SSID here
        string PassKey = "sinotech11569326";    // <<<<< You need to enter your Password/Key here
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {

            wifi_RS21.Interface.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(Interface_WirelessConnectivityChanged);
            InitializeWifi();
            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }
        private void InitializeWifi()
        {


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

            try
            {
                WiFiNetworkInfo[] networkinfo = wifi_RS21.Interface.Scan(ssid);

                if (networkinfo != null && networkinfo.Length > 0)
                {

                    wifi_RS21.Interface.Join(networkinfo[0], PassKey);//networkinfo[0] 
                    Debug.Print("IP=" + wifi_RS21.Interface.NetworkInterface.IPAddress);
                }


            }
            catch (Exception e)
            {
                Debug.Print("!!Exception : " + e.Message);
            }



        }

        void Interface_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("IP=" + wifi_RS21.Interface.NetworkInterface.IPAddress);
            Debug.Print("IP=" + e.IsConnected.ToString());
            Gadgeteer.Networking.HttpRequest wc = WebClient.GetFromWeb("http://www.google.com");
            wc.ResponseReceived += new HttpRequest.ResponseHandler(wc_ResponseReceived);

        }

        void wc_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            string text = response.Text;
            Debug.Print("***Response is received : " + text);
        }
        
    }

The debug output

Using mainboard GHI Electronics FEZSpider version 1.0
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
IP=0.0.0.0
IP=True
IP=0.0.0.0
Program Started
The thread ‘’ (0x3) has exited with code 0 (0x0).
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (6) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (6) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (6) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll

An exception occured while connecting to the Internet. Please, make sure that a valid URL is used and a network connection is up.

The thread ‘’ (0x6) has exited with code 0 (0x0).

Please just post in one thread here. Carpet bombing every other person who mentioned this module isn’t necessary.

What is your access point? Do you have a different one that you can try? What about using different security settings for example trying wpa2?

No help I can offer but I wonder why you are receiving the #### SocketException ErrorCode = 10060

WSAETIMEDOUT
10060
Connection timed out.
A connection attempt failed because the connected party did not properly respond after a period of time,
or the established connection failed because the connected host has failed to respond.

Dear Brett:
Thanks your hint.

How to set the security setting?

In 4.1 I can use

WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
            
            info.SecMode = WiFi_RS21.SecurityMode.WPA2;

But in 4.2 I don’t know how to set it.

I mean at the wifi router, not on Fez

My wifi router is WPA2, and its works when I set the FEZ to WPA2 in NETMF 4.1.

can you change to wep then? my point is to try combinations to identify what is going on.

First post in 2013/1/1
I test the wifi module in my house, the router on my home is wep. But, still not works even use my code or willgeorge’s code.
Do not understand what is doing on? Maybe re-install the firmware?
Anyway , happy new year for you guys in this forum, thanks for your help in 2012.