Library to use a wifly module: RN 131 C/G
Dependents:
RN-XV_simple_server
« Back to documentation index
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:
tx mbed pin to use for tx line of Serial interface
rx mbed pin to use for rx line of Serial interface
reset reset pin of the wifi module
ssid ssid of the network
phrase WEP or WPA key
wpa true if wpa security false otherwise
ip ip of the wifi module if dhcp = false (default: NULL)
netmask netmask if dhcp = false (default: NULL)
dhcp enable or disable dhcp (default: true)
baudrate speed 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:
tx mbed pin to use for tx line of Serial interface
rx mbed pin to use for rx line of Serial interface
ssid ssid of the adhoc network which will be created
ip ip of the wifi module (default: "169.254.1.1")
netmask netmask (default: "255.255.0.0")
channel channel (default: "1")
baudrate speed 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:
tptr pointer to the object to call the member function on
mptr pointer 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:
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:
Returns: true if the baudrate has been changed, false otherwise
Definition at line 478 of file Wifly.cpp .
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 .
To exit the command mode.
Returns: true if successful, false otherwise
Definition at line 467 of file Wifly.cpp .
Read a character.
Returns: the character read
Definition at line 509 of file Wifly.cpp .
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 .
Write a character.
Parameters:
the character which will be written
Definition at line 446 of file Wifly.cpp .
Read a string if available.
Parameters:
str pointer where will be stored the string read
Definition at line 454 of file Wifly.cpp .
Check if characters are available.
Returns: number of available characters
Definition at line 474 of file Wifly.cpp .
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:
str string to be sent
ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
res this 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 .