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
@ 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?
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
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:
@ 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.
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
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.
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);
}
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
@ 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.
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
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.