You are viewing an older revision! See the latest version

WiflyInterface

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 (now Microchip). 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.

For some applications, it can be useful to dig a little deeper, in which case the Wifly User Manual will be helpful.

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.

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

Connections that match "Hello Example" code shown below

/media/uploads/WiredHome/wifly_wiflyexample.png

Connections that match mbed Application Board

/media/uploads/WiredHome/wifly_mbedappboard.png
mbed Application Board

Connections that match SmartBoard

/media/uploads/WiredHome/wifly_smartboard.png
SmartBoard Wifly

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);
// mbed Application Board
//WiflyInterface wifly(p9, p10, p30, p29, "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.

More details

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

Import 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

Links to Wifly Resources

Roving networks was acquired by Microchip, and there are a number of online resources. If you do not already have it, be sure to download the user manual, as there are a lot of 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 inteference/distance). Your mbed application should also implement a watchdog, which in turn can then reset the Wifly module.
  • 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.
  • If you hang your module, and can't seem to get back in control of it, you may need to perform the hardware reset procedure described in section A.13 (of user manual v1.2r). This can happen if you inadvertently save a bad configuration.

Stuff the WiFly can do

  • Communicate over wifi
  • Upgrade its firmware over TCP
  • Sleep
  • Be controlled completely using GPIO pins.
  • Operate as a wifi client, or as an access point or ad-hoc mode. (ad-hoc replaced with access point mode - see User manual section 4.8)
  • Operate as a standalone server

Programs using this library:

Projects with this module:

Troubleshooting

Occasionally, people have had a challenge getting the Wifly module to work. This section may have a few tips for troubleshooting.

  1. Check your wiring carefully. There are only a few signals to connect, but it is not uncommon to mis-wire one.
    1. Do you have the ground connection?
    2. Is your power connection to the Wifly module from the VOUT pin of the mbed?
    3. Review RXD and TXD - be sure they are not swapped.
  2. Power Quaity. This should not be a problem when the Wifly module is powered from the mbed and that from the USB connector. If you have a separate power supply powering the module, you may want to check it, or try another.
  3. Which mbed UART is your module wired to? Check the schematics up above, and take careful note of the pin assignments used in the corresponding WiflyInterface constructor.
  4. Factory Reset the WiFly module (this is described in section A.13 of the RN171 User Manual)
    1. If you have a good software connection and the module is responding, you can issue "factory RESET" to the module, followed by "reboot".
    2. If you cannot get the a response, you can issue a hardware reset of the module. GPIO9 is a pin on the Wifly module. Set it high and then apply power. Then toggle the pin 5 times slowly.

All wikipages