Main Site Documentation

4.3 - Fez Spider WiFiRS21


#1

Hello,

I’m trying to get my wifiRS21 module to connect after upgrading to 4.3 with no luck. I’ve seen the documentation that gives the following line of code but when it executes it gives an error: “This interface type is already created”.

netif = new WiFiRS9110(SPI.SPI_module.SPI1, Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3);

I’ve looked around to see if there are settings I should know about regarding the pins that module uses but no luck. And I’m new to this so I wasn’t expecting much luck in the first place :open_mouth:

Thanks in advance -

Steve


#2

@ scicco - That exception is thrown when you have an existing wifi interface created. Are you by any chance using Gadgeteer and have the module in the designer?


#3

Hi john,

Yes and yes. I am using gadgeteer and I do have the module in the designer. I’m trying to reproduce the sample code provided in the wifi rs21 module documentation but for 4.3

Thanks


#4

then remove the wifi module from the designer, or remove the creation of the object. You’ve just duplicated the setup of this object for no reason.


#5

I tried both suggestions with no luck.

If I remove it from the designer I get the following error on the line of code that’s creating it:

netif = new WiFiRS9110(SPI.SPI_module.SPI1, Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3);

An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll

If I keep it in the designer and don’t create it I get the following error when I try the next line of code provided in the GHI docoument:

netif.Open();

An unhandled exception of type ‘System.NullReferenceException’ occurred in prog.exe


#6

Progress…

I can scan the available networks and join my network. Kind of. I get no exceptions on the join but never get an IP address. I gave my network an invalid key to make sure it was really trying to join and sure enough that did throw an exception. I am also getting the NetworkAvailabilityChanged event firing after I join. It just sits in the while loop with an IP address of 0.0.0.0 even though IsNetworkConnected is evaluating to true. And the ActiveNetwork property of my wifi module has all the expected info:

Channel: 6
Key: "MyPassword"
NetworkType: AccessPoint
PhysicalAddress: {byte[6]}
Rssi: 13
SecurityMode: Wpa2
Ssid: "MyNetworkSSID"

The exact error I’m getting when trying to do something online is

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


NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
           
            wifiRS21.NetworkInterface.EnableDhcp();
            wifiRS21.NetworkInterface.EnableDynamicDns();         

            WiFiRS9110.NetworkParameters[] scanResults = wifiRS21.NetworkInterface.Scan();

            ArrayList options = new ArrayList();
            int i = 0;

            // go through each network and print out settings in the debug window
            foreach (WiFiRS9110.NetworkParameters result in scanResults)
            {

                Debug.Print("****" + result.Ssid + "****");
                Debug.Print("ChannelNumber = " + result.Channel);
                Debug.Print("networkType = " + result.NetworkType);
                Debug.Print("PhysicalAddress = " + GetMACAddress(result.PhysicalAddress));
                Debug.Print("RSSI = " + result.Rssi);
                Debug.Print("SecMode = " + result.SecurityMode);

                options.Add(new object[2] { result.Ssid, i });
                i += 1;

                if (result.Ssid == "MyNetworkSSID")
                {
                    wifiRS21.NetworkInterface.Join(result.Ssid, "MyPassword");                   

                    Debug.Print("IP: " + wifiRS21.NetworkInterface.IPAddress);
                    Debug.Print("Network: " + result.Ssid);

                    characterDisplay.SetCursorPosition(1, 0);
                    characterDisplay.Print(GetMACAddress(result.PhysicalAddress));
                }
            }

            while (wifiRS21.NetworkInterface.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP");
                if (wifiRS21.IsNetworkConnected == false)
                {
                    Debug.Print("Not connected");
                }
                else
                {
                    Debug.Print(wifiRS21.NetworkInterface.ActiveNetwork.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.IPAddress.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.PhysicalAddress.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.Opened.ToString());
                }
                Thread.Sleep(250);
            }

#7

@ scicco - in your foreach loop, after you find your network and do a join, add a break statement. if there are more then one network heard, and there is one after yours, you will also try to join it. only after you have tried to join the last network heard will try to see if you have an IP address.


#8

HI Mike,

Thanks for the suggestion but no dice. Also tried added my SSID to the .Scan to ensure there was only one result and I’m still stuck in the while loop with an IP of 0.0.0.0


#9

@ scicco - In a new NETMF (non-gadgeteer) application, can you try the WiFi sample on https://www.ghielectronics.com/docs/30/networking#3121


#10

We you able to get it working using NETMF 4.2? I had some problems there too, but got things working after some experiments. My Codeshare article

https://www.ghielectronics.com/community/codeshare/entry/913

uses the same Wifi from the designer and works well, it’s only NETMF 4.2, but might help in some small way.


#11

I was getting a similar issue with my raptor and RS21. Got it working by removing



and adding


```cs
wifiRS21.NetworkInterface.EnableDhcp();
wifiRS21.NetworkInterface.EnableDynamicDns();

Seems if I add in the UseDHCP() it never gets an IP address.


#12

@ Jason

Yes - I had it working on 4.2 and was actually doing something similar to you with uCloudy and Azure. I decided to upgrade when I was getting inconsistent responses from uCloudy and thought that using the uCloudy 4.3 version might help. I have an unanswered post on that (https://www.ghielectronics.com/community/forum/topic?id=14322&page=1#msg161912) in case you maybe ran into something similar during your coding.

@ jmerriweather

I’ve tried with and without it and in every possible order. Although since I’ve tried so many combinations I will double check it.

Thanks for the replies -

Steve


#13

Like I said I had tried so many combinations and it finally worked. Thank you everyone for the help.

@ Mike - I was almost positive I tried your suggestion about the break and it didn’t work but that is the only difference I can see between this code and the code I posted earlier so thank you very much

            wifiRS21.NetworkInterface.EnableDhcp();
            wifiRS21.NetworkInterface.EnableDynamicDns();

            WiFiRS9110.NetworkParameters[] scanResults = wifiRS21.NetworkInterface.Scan("MySSID");

            ArrayList options = new ArrayList();
            int i = 0;

            // go through each network and print out settings in the debug window
            foreach (WiFiRS9110.NetworkParameters result in scanResults)
            {

                Debug.Print("****" + result.Ssid + "****");
                Debug.Print("ChannelNumber = " + result.Channel);
                Debug.Print("networkType = " + result.NetworkType);
                Debug.Print("PhysicalAddress = " + GetMACAddress(result.PhysicalAddress));
                Debug.Print("RSSI = " + result.Rssi);
                Debug.Print("SecMode = " + result.SecurityMode);

                options.Add(new object[2] { result.Ssid, i });
                i += 1;

                if (result.Ssid == "MySSID")
                {
                    wifiRS21.NetworkInterface.Join(result.Ssid, "MyPassword");
                    //Display_Text("IP: " + wifiRS21.NetworkInterface.IPAddress);
                    //Display_Text("Network: " + result.Ssid);

                    Debug.Print("IP: " + wifiRS21.NetworkInterface.IPAddress);
                    Debug.Print("Network: " + result.Ssid);

                    characterDisplay.SetCursorPosition(1, 0);
                    characterDisplay.Print(GetMACAddress(result.PhysicalAddress));

                    break;
                }
            }

            //list = new List(options, 150);

            while (wifiRS21.NetworkInterface.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP");
                if (wifiRS21.IsNetworkConnected == false)
                {
                    Debug.Print("Not connected");
                }
                else
                {
                    Debug.Print(wifiRS21.NetworkInterface.ActiveNetwork.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.IPAddress.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.PhysicalAddress.ToString());
                    Debug.Print(wifiRS21.NetworkInterface.Opened.ToString());
                }
                Thread.Sleep(250);
            }

#14

Spoke too soon. That same code that gave me an IP address (192.168.1.20) worked exactly once. I stopped the debugger and was getting back into development and the next time I ran it I was right back in the neverending loop of 0.0.0.0

:’( :’( :’(


#15

@ scicco - Did you try the example on https://www.ghielectronics.com/docs/30/networking#3121


#16

@ John - yes that was the first thing I tried. If I remove the module from the designer and specify the SPI module and pins (3, 3, 4, 6 I think?)I get ASSERT over and over on my display. If I just use the wifi module instead of the variable netif (wifiRS21.NetworkInterface) I still get stuck in the loop with no IP address.


#17

@ scicco - Can you post the complete code you used the give the ASSERT error here?


#18

I’ll copy the exact code over when I get home but it should be pretty similar to this (with netif declared above the ProgramStarted) and obviously my SSID and password:

        NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
        NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

        netif = new WiFiRS9110(SPI.SPI_module.SPI3, Cpu.Pin.GPIO_Pin6, Cpu.Pin.GPIO_Pin3, Cpu.Pin.GPIO_Pin4);
        netif.Open();
        netif.EnableDhcp();
        netif.EnableDynamicDns();
        netif.Join("SSID", "Password");

        while (netif.IPAddress == "0.0.0.0")
        {
            Debug.Print("Waiting for DHCP");
            Thread.Sleep(250);
        }

It doesn’t make it past the creation of netif though and that’s when the ASSERT error shows on my 4.3’’ display


#19

@ scicco - What socket is the wifi module connected to on the Spider?


#20

9

I was able to figure out the pins from the wifi module diagram in your catalog but I just went thru all the available enums for the SPI module. 1, 2 and 4 errored out (can’t remember the exact error) but 3 sat there and gave the assert error.

Thanks -