wifly

Import 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 library

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.

Getting started

First determine which pins of your WiFly module are power, ground, TX & RX. These should be connected to the mbed's pins accordingly. Make sure you haven't got the TX and RX mixed up. Murphy's law states this will be the case if you do not check beforehand. If you receive no response from the module, this is probably the case. For this stage I wrote a simple mbed program to pass input from a terminal on the pc to the device - program. If you are experimenting, it is advisable to have write in a few hotkeys that will execute commands you use often (HTTP GET request for example).

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

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
    • the response is AOK (AOK has replaced set... local echo activated)
  • set wlan phrase my_password (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 my_ssid
    • 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.

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 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.

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: