How to connect to a WiFi Network with RN171?

I have the RN171 module (https://www.ghielectronics.com/catalog/product/444) connected to the FEZCerbot board. If I run it as a server (e.g. generate its own Wifi SSID), it works fine.

However, I want to connect it to another network. I’ve tried the following on a bunch of networks (with and without security) and nothing seems to work.


bool result = wifi_RN171.JoinWirelessNetwork("ardrone2_014167", "", 6);
Debug.Print(result.ToString());

No matter what I do the result value is always false. Do I need to do something else prior to joining the network?

I’ve also tried issuing a wifi_RN171.Initialize(WiFi_RN171.SocketProtocol.TCP_Client); before joining the network but it didn’t work either.

Am I missing something simple?

Hi,
you could try it with this driver:

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

@ RoSchmi… I’ve actually tried your driver before posting the question. I had to convert it back to .NET MF 4.2, but I’ve been primarily using your driver…

I turned on debugging (e.g. Debug.Print) to see everything that went in and out and it seems like it associating with the SSID but doesn’t get an IP address. Perhaps there is an extra step…

In addition, in the DoJoinWirelessMethod, I had to change (for now):


if (!_Command_Execute("join"))
    return false;

to

 because the code is not processing the "Associate" message correctly.

Anyway here is the output - perhaps you can spot what's missing.

FlowControl = False
Trying Baudrate: 115200 Parity: 0
Message from Class RN171: Could connect on first try
Constructor ended
FEZ-Baudrate = 115200 Parity = 0 FlowCtrl= False
Program Started
Recd: wifly-EZX Ver 4.00.1, Apr 19 2013 11:47:16 on RN-171
Recd: MAC Addr=00:06:66:53:59:30
Recd: *READY*
Recd: AP mode as GHI HotSpot on chan 1
Recd: Listen on 80
Recd: DCHP Server Init
Recd: CMD
Sent: set ip dhcp 1
Recd: set ip dhcp 1
Recd: AOK
Sent: set ip localport 2000
Recd: <4.00> set ip localport 2000
Recd: AOK
Sent: set ip protocol 2
Recd: <4.00> set ip protocol 2
Recd: AOK
Sent: set wlan join 0
Recd: <4.00> set wlan join 0
Recd: AOK
Sent: set wlan ssid ardrone2_014167
Recd: <4.00> set wlan ssid ardrone2_014167
Recd: AOK
Sent: set wlan channel 6
Recd: <4.00> set wlan channel 6
Recd: AOK
Sent: set wlan auth 0
Recd: <4.00> set wlan auth 0
Recd: AOK
I set wlan key to - No
Sent: set wlan hide 1
Recd: <4.00> set wlan hide 1
Recd: AOK
Sent: join
Recd: <4.00> join
Recd: Auto-Assoc ardrone2_014167 chan=6 mode=OPEN SCAN OK
Recd: Joining ardrone2_014167 now..
Recd: <4.00> Associated!
Recd: DHCP: Start
Sent: get ip
Recd: get ip
Recd: IF=DOWN
Recd: DHCP=ON
Recd: IP=0.0.0.0:2000
Recd: NM=0.0.0.0
Recd: GW=0.0.0.0
Recd: HOST=0.0.0.0:2000
Recd: PROTO=TCP,
Recd: MTU=1524
Recd: FLAGS=0x7
Recd: TCPMODE=0x0
Recd: BACKUP=0.0.0.0
Recd: <4.00> exit
Recd: EXIT

Looks good :). At least they communicate.
Can you please post your actual code in the program.started method.
You took my latest Version, right?

With WPA-2 encryption I got something like this

Program Started
Call Constructor
FlowControl = False
Trying Baudrate: 57600 Parity: 0

Message from Class RN171: Could connect on first try

Constructor ended
FEZ-Baudrate = 57600 Parity = 0 FlowCtrl= False
CMD

set ip dhcp 1

AOK
<4.41>
set ip gateway 192.168.1.1

AOK
<4.41>
set ip netmask 255.255.255.0

AOK
<4.41>
set dns address 192.168.1.1

AOK
<4.41>
exit

EXIT

wifly-EZX
Ver: 4.41 Build: r1057, Jan 17 2014 10:23:54 on RN-171
MAC Addr=00:06:66:53:15:b6
READY

CMD

set ip dhcp 1

AOK
<4.41>
set ip localport 80

AOK
<4.41>
set ip protocol 2

AOK
<4.41>
set ip protocol 2

AOK
<4.41>
set comm time 20

AOK
<4.41>
set wlan ssid FriBo24

AOK
<4.41>
set wlan channel 0

AOK
<4.41>
set wlan auth 4

AOK
<4.41>
set wlan phrase **************

AOK
<4.41>
set wlan hide 1

AOK
<4.41>
join

<4.41>
Auto-Assoc FriBo24 chan=1 mode=MIXED SCAN OK

Joining FriBo24 now…

Associated!
DHCP: Start

WARN: Total initialization time exceeds 10 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
DHCP in 6123ms, lease=864000s
IF=UP
DHCP=ON
IP=192.168.1.49:80
NM=255.255.255.0
GW=192.168.1.1
Listen on 80

get ip

IF=UP
DHCP=ON
IP=192.168.1.49:80
NM=255.255.255.0
GW=192.168.1.1
HOST=0.0.0.0:2000
PROTO=TCP,
MTU=1524
FLAGS=0x7
TCPMODE=0x0
BACKUP=0.0.0.0
<4.41>
exit

EXIT

CMD

set ip protocol 2

AOK
<4.41>
exit

EXIT

CMD

set ip local 80

AOK
<4.41>
set comm remote 0

AOK
<4.41>
exit

EXIT

This is my ProgramStarted code


            wifi = new WiFi_RN171(3);

            wifi.DebugPrintEnabled = true;
            //wifi.JoinWirelessNetwork("ardrone2_014167", "", 6, WiFi_RN171.WirelessEncryptionMode.Open, "80");
            bool result = wifi.JoinWirelessNetwork("ardrone2_014167", "", 6, WiFi_RN171.WirelessEncryptionMode.Open, true, "2000", "", "192.168.1.1", "255.255.255.0", "192.168.1.1");
            Debug.Print(result.ToString());
            Debug.Print(wifi.LocalIP);


I tried both constructors - no success.
One thing I don’t understand from your output is how you set DHCP to on, but then you also set DNS/Gateway/Netmask. In the DoJoinWirelessNetwork, none of that happens if DHCP is on.

Please try this:
bool ActionResult = wifi_RN171.JoinWirelessNetwork(“ardrone2_014167”, “”, 0, Gadgeteer.Modules.RoSchmi.WiFi_RN171.WirelessEncryptionMode.Open, “80”);

or try to set your router to WPA2-PSK, or try a shorter SSID my SSID was FriBo24

I had a look on my driver. My code in the ProgramStarted() method was:


wifi_RN171 = new WiFi_RN171(2, 57600, GTI.SerialParity.None, GTI.HardwareFlowControl.NotRequired);
wifi_RN171.SetDebugLevel(WiFi_RN171.DebugLevel.DebugAll);
wifi_RN171.EnableDHCP();
bool ActionResult = wifi_RN171.JoinWirelessNetwork("FriBo24", "********", 0, Gadgeteer.Modules.RoSchmi.WiFi_RN171.WirelessEncryptionMode.WPA2_PSK, "80");
wifi_RN171.SetProtocol(WiFi_RN171.SocketProtocol.TCP_Server);
wifi_RN171.EnableHttpServer(); //Enable HTTP Parsing

At the moment I don’t understand it myself: It’s done in the method:
wifi_RN171.EnableDHCP();
I can not say, why it is there. May be it‘ s something I forgot to delete, may be it has a reason which I don’t remember at the moment. However it seems not to be harmful.

No success. I’ve tried connecting to 2 networks using code you provided as a starting point… Number one is an open one:


wifi = new WiFi_RN171(3, 115200, Gadgeteer.Interfaces.Serial.SerialParity.None, Gadgeteer.Interfaces.Serial.HardwareFlowControl.NotRequired);
wifi.SetDebugLevel(WiFi_RN171.DebugLevel.DebugAll);
wifi.EnableDHCP();
bool ActionResult = wifi.JoinWirelessNetwork("ardrone2_014167", "", 0, Gadgeteer.Modules.RoSchmi.WiFi_RN171.WirelessEncryptionMode.Open, "80");

Debug.Print(ActionResult.ToString());
Debug.Print(wifi.LocalIP);

It all goes swimmingly in DoJoinWirelessNetwork, until the driver issues “join” command


            if (!_Command_Execute("join"))
                return false;

to which the following is received:

Auto-Assoc ardrone2_014167 chan=6 mode=OPEN SCAN OK
Joining ardrone2_014167 now…
<4.00>
Associated!
DHCP: Start

So seemingly success. However, the _Serial_Line_Received method has the following:


                if (!_DHCP && _Command_Mode_Response.IndexOf("Associated!") >= 0)
                {
                    _Command_Mode_Response_Okay = true;
                    _Command_Mode_Response_Complete = true;
                }

which means it will process the Associated message only if DHCP is off. However, we enabled DHCP, so _Command_Mode_Response_Okay never gets set to true…

Regardless…lets say I remove the !_DHCP line and processed Associated! message, thus returning true. The next thing is that it calls “get ip” command. To that I get 0.0.0.0 as the IP address… There must be something else that I need to fire.

IF=DOWN
DHCP=ON
IP=0.0.0.0:80
NM=0.0.0.0
GW=0.0.0.0
HOST=0.0.0.0:2000
PROTO=TCP,
MTU=1524
FLAGS=0x7
TCPMODE=0x0
BACKUP=0.0.0.0

Any thoughts?

I also tried to connect to another network which has WPA2-Personal authentication (I tried both MixedWPA1_WPA2 and WPA2_PSK authentications). On this one…following the “join” command, I’d get this:

Disconn from acumen24,AUTH-ERR

ERROR! — Disconn from acumen24,AUTH-ERR

One difference to my code seems to be that you set the channel to 6 insteat of 0. If it is set to 0 the RN171 will scan all the channels. Did you try to set channel 0 as Argument?

If you will note the last set of code I posted, I pass in channel 0.

I Send my actual Settings of my RN171. Perhaps there is a difference that makes it react in another way

Cmd 4 Execute Command: get everything
get everything

wifly-EZX Ver: 4.41 Build: r1057, Jan 17 2014 10:23:56 on RN-171
SSID=WiFly-EZX-b6
Pass=
Linkmon=3600
Beacon=102
Reboot=0
IF=UP
DHCP=ON
IP=1
92.168.1.49:80
NM=255.255.255.0
GW=192.168.1.1
HOST=0.0.0.0:2000
PROTO=TCP,
MTU=1524
FLAGS=0x7
TCPMODE=0x0
BACKUP=0.0.0.0
OPEN=OPEN
CLOSE=CLOS
REMOTE=
FlushSize=1420
MatchChar=0
FlushTimer=20
IdleTimer=0
CmdChar=$
DNS=192.168.1.1
Name=dns1
Backup=rn.microchip.com
Lease=86400
FTP=0.0.0.0:21
File=wifly-EZX.img
User=roving
Pass=Pass123
Dir=p
ublic
Timeout=200
FTP_mode=0x0
SSID=FriBo24
Chan=0
ExtAnt=0
Join=0
Auth=MIXED
Mask=0x1fff
Rate=12, 24 Mb
Linkmon=30
Passphrase=******
TxPower=12
EAP_Id=userid
EAP_User=peap-user
SleepTmr=0
WakeTmr=0
Trigger=0x1
Autoconn=0
IoFunc=0x0
IoMask=0x21f0
IoValu=0x0
DebugReg=0x0
PrintLvl=0x1
LaunchStr=web_app
TimeEna=0
TIMEADR=64.90.182.55:123
Zone=7
Baudrate=57600
Flow=0x0
Mode=0x0
Cmd_GPIO=0
JoinTmr=1000
Replace=0x24
DeviceId=WiFly-EZX
Password=
Format=0x0
Signal=0
Average=5
BCAST=255.255.255.255:55555
Interval=0x7
Backup=0.0.0.0:0
Sensor=0x0
SensePwr=0x0
<4.41>

Yes, you are right, but for me the code works even with this bug.

May be the reason why it does not work for you is your old Firmware Version.

https://developer.mbed.org/components/Roving-Networks-WiFly-RN-171-XV/

With your Firmware I would try to include a scan command before the join command.

[code=cs
_Command_Execute(“scan”);

if (!_Command_Execute(“join”))
return false;
]



If you got an IP-Address you should easily be able to update to Version 4.41 as shown in my example

Hmmm, you are right. I did manage to connect to it… However, somethings are weird… Scan does not work the first time. It returns 0 networks found (there are tons here). Then I run scan again… The first line of response is that it is disconnecting from GHI HotSpot ssid.

<4.00>
Disconn from GHI HotSpot,LOST-AP

And after that, it proceeds to actually list all the networks.
Executing “join” after that actually does connect to the network and I am able to get an IP address. Perhaps I need to find a way for it to programattically disconnect from the GHI HotSpot network. Not sure how.

So there is that.

My firmware is wifly-EZX Ver 4.00.1, Apr 19 2013, so it can stand updating to the new version. Its possible
Any idea how to update the firmware - the only connection I have is via the Gadgeteer cable?

O.K., nice that it worked so far.
You can simply update the firmware with my Utility by activating the #define directive to:

#define WorkJoinedToNetworkFirmwarUpdate

if it succeeds to get to get an IP-Address by DHCP it automatically fetches the Update-File via ftp from microchip.com and installs the new firmeware.
May be that you need to include one or more scan commands before the join command to get an IP-Adress. With the new firmware it should work as expected.
Keep in mind, that after updating the Firmware, the baudrate of the RN171 is set to 9600.

Chance to get this driver for 4.2?

So, if it’s already been done, i thought to have it too.
I Couldn’t find a simple example of how to use the RN171 in this whole site,
not sure how to use it and that is the only reasonable relevant post about.

You know, i’m not sure about something.
I’m using netmf 4.2 and I can add the wifi RN171 to my project as a module and all of the functions exists but i can’t seem to log on to my wifi at home.
Do I need another driver?

@ andre.m - ok thanks!