WiflyInterface

» Import this programWifly_HelloWorld

Hello World with a wifly module (RN 131 C/G - RN-XV)

1200

Information

With this library, you will be able to add a wireless connectivity to your mbed. This library relies on wifly modules from Roving Networks. These modules can be found on sparkfun for instance.

The objective of this library is to provide the same API as the EthernetInterface. So all programs using the EthernetInterface are compatible with the WiflyInterface.

Software

The WiflyInterface library provides you with a simple API to connect to the internet.

» Import this library into a program

Public Member Functions

  WiflyInterface (PinName tx, PinName rx, PinName reset, PinName tcp_status, const char *ssid, const char *phrase, Security sec=NONE)
  Constructor.
int  init ()
  Initialize the interface with DHCP.
int  init (const char *ip, const char *mask, const char *gateway)
  Initialize the interface with a static IP address.
int  connect ()
  Connect Bring the interface up, start DHCP if needed.
int  disconnect ()
  Disconnect Bring the interface down.
char *  getIPAddress ()
  Get IP address.

Hardware

A basic hardware configuration (if you don't use a battery to power the module) is:

RN-131+++++RN-XV
wifly pinMbed pinwifly_pinMbed pin
3.3V RINGND
GNDGNDGNDGND
VDD BATTVOUT
VDD INVOUTVDD_3V3VOUT
RXTXUART_RXTX
TXRXUART_TXRX
GPIO 6any DigitalInGPIO 6any DigitalIn
RESETany DigitalInRESETany DigitalIn

Hello World!

Please be sure to read the Wifly datasheet and API of Wifly class, if you are using it, for maximum ease of use.

#include "mbed.h"
#include "WiflyInterface.h"

Serial pc(USBTX, USBRX);

/* wifly object where:
*     - p9 and p10 are for the serial communication
*     - p25 is for the reset pin
*     - p26 is for the connection status
*     - "mbed" is the ssid of the network
*     - "password" is the password
*     - WPA is the security
*/
WiflyInterface wifly(p9, p10, p25, p26, "mbed", "password", WPA);

int main() {
    wifly.init(); // use DHCP
    while (!wifly.connect()); // join the network
    printf("IP Address is %s\n\r", wifly.getIPAddress());
    wifly.disconnect();
}

» Import this programWifly_HelloWorld

Hello World with a wifly module (RN 131 C/G - RN-XV)

The previous program tries to connect the network. If the network is joined, it prints the ip address of the wifly module.

More details

In order to test that your hardware has been setted up correctly, you can use this program:

» Import this programWifly_configure

Configure wifly module

.

Information

If everything is connected correctly, you should get the response "CMD" when you put in three consecutive dollar signs "$$$". The module is now in command mode. To return the module to this factory state, if you want to, you should enter in command mode "factory RESET\r".

Here is a configuration example:

/media/uploads/samux/wifly_conf.png

  • First I enter in command mode by pressing $$$
    • the response is CMD
  • set wlan ssid my_network\r
    • the response is AOK (AOK has replaced set... local echo activated)
  • set wlan phrase my_password\r (I use set wlan phrase because my network use WPA as security. If you have a WEP security, you have to use set wlan key your_password)
    • the response is AOK
  • join\r
    • the response is quite long but Associated! means that you are connected

There are a lot of commands to configure the wifly module. Please take a look to the user manual if you want more information on all possible commands.

Things to be aware of:

  • If sending data using the on board TCP/IP stack, it might be necessary, if you are experiencing problems, to change the flush size/timeout to the maximum, or it sends the data as it receives it.
  • Sometimes an unresponsive module will need an external reset (there is also a watchdog), might need to be part of a design to guard from total failure. This is not uncommon when the server is very unreliable (when you are using your own) or there is some disconnection between the module and the router (due to intefearance/distance)
  • Need to be aware of times to complete commands such as connecting to a network, as DHCP can take a while among other things. Rather than looking for ascii confirmation of things like an open TCP connection, it may be easier to configure one of the GPIO pins to do the job.

Stuff the WiFly can do

  • Communicate over wifi
  • Upgrade its firmware over TCP
  • Sleep
  • Be controlled completely using GPIO pins.
  • Operate in wifi or ad-hoc mode
  • Operate as a standalone server

Programs using this library:

Projects with this module:




3 related questions:


6 comments:

25 Oct 2012

I have bought a UART wifi module but wasn't quite sure if it can work with this library? could you please verify for me? many thanks http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=90_186&products_id=1007

26 Oct 2012

What does the pin "PinName tcp_status" refer to? I'm looking to connect to an Xbee XB24-WFWIT-001.

...kevin

01 Nov 2012

Hello Samuel, many thanks for your module and my compliments: it's excellent! I want just to ask you if you know about the new wifly firmware release. I'm speaking about the 2.45 version that adds the "Access Point" functionality.[1]. I have written down a quick and derty howto [2] about this.

Are you thinking to add this new feature in your library?

TIA Clemente

[1] http://ww1.microchip.com/downloads/en/DeviceDoc/rn-wiflycr-um-1.0r.pdf?from=rss [2] http://code.google.com/p/wifly-wonderland/

01 Nov 2012

Hi All, I originall posted this on Chris's "Homepage", but that is too generic since my issue is specific to the RN171 Xvee module from Roving Networks.....

Hi Chris,

I recently purchased a Roving Networks Xvee module, based on the RN171. I am running into a number of issues getting the module to initialize. The first issue I ran into, was that the module would not accept any commands. After some trial-and-error, I found that the module doesn't like the appreviated commands in Wifly.cpp. Example, in function "bool Wifly::join()", instead of using: if (!sendCommand("s c t 20\r", "AOK")) I changed the line to: if (!sendCommand("set comm time 20\r", "AOK")), etc.

Second, after changing all of the commands to their non-appreviated form, the module stopped at the 4th command "if (!sendCommand("set comm remote 0\r", "AOK"))". For the time being, I commented out that command.

The code then proceeded stopped at the 10th command "sprintf(cmd, "set wlan ssid %s\r", ssid);" I enabled one of the DBG functions and noted a fatal error being sent out of the module:

check: Unrecoverable failure (2) Illegal instruction at PC=4000f570The system will be reset"

check:

check: WiFly Ver 2.32, 02-13-2012 on RN-171MAC Addr=00:06:66:80:3a:22

check:

check: Auto-Assoc roving1 chan=0 mode=NONE FAILED*READYERR WATCHDOG*

Chris, are you running a different version of the module's internal code?

help!!

...kevin

02 Feb 2013

Has anyone been working on writing a library for getting an ad-hoc network using wifly?

28 Apr 2013

Does Wifly work with HTTP Clients. I have tried so many example programs, and yet my wifly is not able to do a get or put for http client. I am frustrated. It works for tcp and udp.