Library to use a wifly module: RN 131 C/G

Dependents:   RN-XV_simple_server

Embed: (wiki syntax)

« Back to documentation index

Wifly Class Reference

Wifly Class Reference

Wifly Class. More...

#include <Wifly.h>

Public Member Functions

 Wifly (PinName tx, PinName rx, PinName reset, char *ssid, char *phrase, bool wpa, char *ip=NULL, char *netmask=NULL, bool dhcp=true, int baudrate=9600)
 Constructor for joining open, wep or wpa secured networks.
 Wifly (PinName tx, PinName rx, PinName reset, char *ssid, char *ip="169.254.1.1", char *netmask="255.255.0.0", int channel=1, int baudrate=9600)
 Constructor to create an adhoc network.
bool send (char *str, char *ACK=NULL, char *res=NULL)
 Send a string to the wifi module by serial port.
bool join ()
 Connect the wifi module to the ssid contained in the constructor.
bool createAdhocNetwork ()
 Create an adhoc network with the ssid contained in the constructor.
bool read (char *str)
 Read a string if available.
void reset ()
 Reset the wifi module.
int readable ()
 Check if characters are available.
char getc ()
 Read a character.
void flush ()
 Flush the buffer.
void putc (char c)
 Write a character.
bool cmdMode ()
 To enter in command mode (we can configure the module)
bool exit ()
 To exit the command mode.
bool changeBaudrate (int baudrate)
 Change the baudrate of the wifi module.
template<typename T >
void attach (T *tptr, void(T::*mptr)(void))
 Attach a member function to call when a character is received.
void attach (void(*fn)(void))
 Attach a callback for when a character is received.

Detailed Description

Wifly Class.

Example:

 #include "mbed.h"
 #include "Wifly.h"

 Wifly wifly(p9, p10, p20, "network", "password", true);
 Serial pc(USBTX, USBRX);

 int main()
 {

   if(wifly.join())
       pc.printf("network joined!\r\n");
   else
       pc.printf("join failed!\r\n");

 }

Definition at line 62 of file Wifly.h.


Constructor & Destructor Documentation

Wifly ( PinName  tx,
PinName  rx,
PinName  reset,
char *  ssid,
char *  phrase,
bool  wpa,
char *  ip = NULL,
char *  netmask = NULL,
bool  dhcp = true,
int  baudrate = 9600 
)

Constructor for joining open, wep or wpa secured networks.

Parameters:
txmbed pin to use for tx line of Serial interface
rxmbed pin to use for rx line of Serial interface
resetreset pin of the wifi module
ssidssid of the network
phraseWEP or WPA key
wpatrue if wpa security false otherwise
ipip of the wifi module if dhcp = false (default: NULL)
netmasknetmask if dhcp = false (default: NULL)
dhcpenable or disable dhcp (default: true)
baudratespeed of the communication (default: 9600)

Definition at line 7 of file Wifly.cpp.

Wifly ( PinName  tx,
PinName  rx,
PinName  reset,
char *  ssid,
char *  ip = "169.254.1.1",
char *  netmask = "255.255.0.0",
int  channel = 1,
int  baudrate = 9600 
)

Constructor to create an adhoc network.

Parameters:
txmbed pin to use for tx line of Serial interface
rxmbed pin to use for rx line of Serial interface
ssidssid of the adhoc network which will be created
ipip of the wifi module (default: "169.254.1.1")
netmasknetmask (default: "255.255.0.0")
channelchannel (default: "1")
baudratespeed of the communication (default: 9600)

Definition at line 23 of file Wifly.cpp.


Member Function Documentation

void attach ( T *  tptr,
void(T::*)(void)  mptr 
)

Attach a member function to call when a character is received.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 196 of file Wifly.h.

void attach ( void(*)(void)  fn )

Attach a callback for when a character is received.

Parameters:
fptrfunction pointer

Definition at line 208 of file Wifly.h.

bool changeBaudrate ( int  baudrate )

Change the baudrate of the wifi module.

The modification will be effective after a reboot. After a baudrate modification, you have to use the correct parameters in the Wifly constructor.

Parameters:
baudratenew baudrate
Returns:
true if the baudrate has been changed, false otherwise

Definition at line 478 of file Wifly.cpp.

bool cmdMode (  )

To enter in command mode (we can configure the module)

Returns:
true if successful, false otherwise

Definition at line 425 of file Wifly.cpp.

bool createAdhocNetwork (  )

Create an adhoc network with the ssid contained in the constructor.

Returns:
true if the network is well created, false otherwise

Definition at line 325 of file Wifly.cpp.

bool exit (  )

To exit the command mode.

Returns:
true if successful, false otherwise

Definition at line 467 of file Wifly.cpp.

void flush (  )

Flush the buffer.

Definition at line 420 of file Wifly.cpp.

char getc (  )

Read a character.

Returns:
the character read

Definition at line 509 of file Wifly.cpp.

bool join (  )

Connect the wifi module to the ssid contained in the constructor.

Returns:
true if connected, false otherwise

Definition at line 153 of file Wifly.cpp.

void putc ( char  c )

Write a character.

Parameters:
thecharacter which will be written

Definition at line 446 of file Wifly.cpp.

bool read ( char *  str )

Read a string if available.

Parameters:
strpointer where will be stored the string read

Definition at line 454 of file Wifly.cpp.

int readable (  )

Check if characters are available.

Returns:
number of available characters

Definition at line 474 of file Wifly.cpp.

void reset (  )

Reset the wifi module.

Definition at line 436 of file Wifly.cpp.

bool send ( char *  str,
char *  ACK = NULL,
char *  res = NULL 
)

Send a string to the wifi module by serial port.

This function desactivates the user interrupt handler when a character is received to analyze the response from the wifi module. Useful to send a command to the module and wait a response.

Parameters:
strstring to be sent
ACKstring which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
resthis field will contain the response from the wifi module, result of a command sent. This field is available only if ACK = "NO" AND res != NULL (default: NULL)
Returns:
true if ACK has been found in the response from the wifi module. False otherwise or if there is no response in 5s.

Definition at line 55 of file Wifly.cpp.