The new documentation uses a class called WiFiRS9110.
Looking at the source code, it seems that Gadgeteer.Modules.GHIElectronics.WiFiRS21 class internally uses the WiFiRS9110 and exposes that class via the property “NetworkInterface”.
So I followed the example at https://www.ghielectronics.com/docs/30/networking and created the code as shown below:
wifiRS21.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifiRS21_NetworkDown);
wifiRS21.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifiRS21_NetworkUp);
wifiRS21.NetworkInterface.Open();
wifiRS21.NetworkInterface.EnableDhcp();
wifiRS21.NetworkInterface.EnableDynamicDns();
wifiRS21.NetworkInterface.Join("MySSID", "1234ABCD" /*hex code of passphrase*/);
while (wifiRS21.NetworkInterface.IPAddress == "0.0.0.0")
Thread.Sleep(500);
wifiRS21.NetworkInterface.Close();
This code is consistently throwing the error given below (at the Join call):
An unhandled exception of type ‘GHI.Networking.WiFiRS9110.JoinException’ occurred in GHI.Networking.dll
and the last post in that thread didn’t help ? It states there that the ASCII versus hex key was a difference. Maybe test with a very clear passphrase that does not use 0-9 and A-F so you know it’s ASCII.
Is it possible you might have some other protection set up as well? MAC address filtering ?
A big thanks to all for showing me direction. Here is what I found and made it working…
If the security type is WEP, then in the passphrase, you pass the hex code. So if passphrase is 12345, you pass 3132333435
If the security type is WPA/WPA2, then in the passphrase put the actual value and not the hex values. SO if passphrase is ABCD@ 1234, then you pass ABCD@ 1234
Thanks Brett for making me review my understanding.
To make this decision, it always makes sense to do a scan first. In the returned NetworkParameters array, the object contains what security type is configured (thanks Ro Schmi)
If above scheme is followed, then it connects. I’m not sure why this difference but it works.
Another thing to keep in mind is that once in a while, even when all parameters are correct, you might either get a JoinException or additionally an Authentication Denied exception. You should ideally try about 3 times before giving up. In my case, the code could always connect in about 3 attempts (if all parameters are correct).
@ vishnusharma - You should be able to find that information on the NetworkParameters.Key property. I will add it to the documentation and the Join method so it is more clear.