MODIFIED from mbed official WiflyInterface (interface for Roving Networks Wifly modules). Numerous performance and reliability improvements (see the detailed documentation). Also, tracking changes in mbed official version to retain functional parity.

Dependents:   Smart-WiFly-WebServer PUB_WiflyInterface_Demo

Fork of WiflyInterface by mbed official

Embed: (wiki syntax)

« Back to documentation index

Wifly Class Reference

the Wifly object More...

#include <Wifly.h>

Inherited by EthernetInterface.

Public Member Functions

 Wifly (PinName tx, PinName rx, PinName reset, PinName tcp_status, const char *ssid, const char *phrase, Security sec)
 Constructor.
 ~Wifly ()
 Destructor to clean up.
void SetSecurity (const char *ssid, const char *phrase, Security sec)
 Optional means to set/reset the security.
bool configure ()
 Configure the wifi module with the parameters contained in the constructor.
bool join ()
 Connect the wifi module to the ssid contained in the constructor.
bool disconnect ()
 Disconnect the wifly module from the access point.
bool connect (const char *host, int port)
 Open a tcp connection with the specified host on the specified port.
bool setProtocol (Protocol p)
 Set the protocol (UDP or TCP)
void reset ()
 Reset the wifi module.
bool reboot ()
 Reboot the wifi module.
int readable ()
 Check if characters are available.
int writeable ()
 Check if characters are available.
bool is_connected ()
 Check if associated with an access point (was checking if tcp link is active)
char getc ()
 Read a character.
void flush ()
 Flush the buffer.
int 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 close ()
 Close a tcp connection, and exit command mode.
int send (const char *str, int len, const char *ACK=NULL, char *res=NULL, int timeout=DEFAULT_WAIT_RESP_TIMEOUT)
 Send a string to the wifi module by serial port.
bool sendCommand (const char *cmd, const char *ack=NULL, char *res=NULL, int timeout=DEFAULT_WAIT_RESP_TIMEOUT)
 Put the device in command mode.
bool isDHCP ()
 Return true if the module is using dhcp.
bool gethostbyname (const char *host, char *ip)
 gets the host ip address
bool baud (int baudrate)
 Set the baud rate between the ARM and the WiFly.
void setConnectionState (bool state)
 Sets the connection state.
char * getWiflyVersionString ()
 Get the version information from the Wifly module.
float getWiflyVersion ()
 Get the software version from the Wifly module.
bool SWUpdateWifly (const char *file)
 Update the software in the Wifly module.
bool isCmdMode ()
 determine if the module is in command mode

Protected Member Functions

bool FixPhrase (char *dst, size_t dstLen, const char *src)
 Allocate space for the parameter (ssid or passphrase) and then fix it (change ' ' to '$').
void GatherLogonInfo ()
 Gather the Wifly module version information for later queries.

Detailed Description

the Wifly object

This object controls the Wifly module.

Definition at line 79 of file Wifly.h.


Constructor & Destructor Documentation

Wifly ( PinName  tx,
PinName  rx,
PinName  reset,
PinName  tcp_status,
const char *  ssid,
const char *  phrase,
Security  sec 
)

Constructor.

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 ()
tcp_statusconnection status pin of the wifi module (GPIO 6)
ssidssid of the network
phraseWEP or WPA key
secSecurity type (NONE, WEP_128, WPA1, WPA | WPA_MIXED, WPA2_PSK, WEP_64 )

Definition at line 54 of file Wifly.cpp.

~Wifly (  )

Destructor to clean up.

Definition at line 66 of file Wifly.cpp.


Member Function Documentation

bool baud ( int  baudrate )

Set the baud rate between the ARM and the WiFly.

This will set the WiFly module baud rate first and then set the ARM interface to match it. If it cannot get the proper acknowledge response, it will go on a hunt through the range of standard baud rates.

Note:
Baud rate must be one of 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, or 921600. (See Wifly manual 2.3.64)
Baud rate of 230400 has been seen to be marginal w/o flow control.
Setting a baud rate to a 460800 or above may be unrecoverable without resetting the Wifly module.
Parameters:
baudrateis the desired baudrate.
Returns:
true if it succeeded, which means that communications can continue,
false if it failed to establish a communication link.

Definition at line 726 of file Wifly.cpp.

bool close (  )

Close a tcp connection, and exit command mode.

Returns:
true if successful

Definition at line 518 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 394 of file Wifly.cpp.

bool configure (  )

Configure the wifi module with the parameters contained in the constructor.

Returns:
true if successful, false otherwise.

Definition at line 85 of file Wifly.cpp.

bool connect ( const char *  host,
int  port 
)

Open a tcp connection with the specified host on the specified port.

Parameters:
hosthost (can be either an ip address or a name. If a name is provided, a dns request will be established)
portport
Returns:
true if successful

Definition at line 269 of file Wifly.cpp.

bool disconnect (  )

Disconnect the wifly module from the access point.

Returns:
true if successful

Reimplemented in EthernetInterface.

Definition at line 438 of file Wifly.cpp.

bool exit (  )

To exit the command mode.

Returns:
true if successful, false otherwise

Definition at line 549 of file Wifly.cpp.

bool FixPhrase ( char *  dst,
size_t  dstLen,
const char *  src 
) [protected]

Allocate space for the parameter (ssid or passphrase) and then fix it (change ' ' to '$').

Parameters:
dstis a reference to the private member pointer.
dstLenis the size of the destination buffer
srcis a pointer to a passed in string.
Returns:
true if the src phrase was placed in the dst buffer.

Definition at line 768 of file Wifly.cpp.

void flush (  )

Flush the buffer.

Definition at line 349 of file Wifly.cpp.

void GatherLogonInfo (  ) [protected]

Gather the Wifly module version information for later queries.

Definition at line 786 of file Wifly.cpp.

char getc (  )

Read a character.

Returns:
the character read

Definition at line 573 of file Wifly.cpp.

bool gethostbyname ( const char *  host,
char *  ip 
)

gets the host ip address

Parameters:
hostis a pointer to the host string to look up
ipcontains the host IP in a string after the lookup.
sizeof_ipis the size of the buffer pointed to by ip
Returns:
true if successful

Definition at line 304 of file Wifly.cpp.

float getWiflyVersion (  )

Get the software version from the Wifly module.

This extracts the basic version number (e.g. 2.38, 4.00) as a float.

Returns:
the software version number as a float.

Definition at line 823 of file Wifly.cpp.

char * getWiflyVersionString (  )

Get the version information from the Wifly module.

Returns:
the version information as a string, or NULL

Definition at line 830 of file Wifly.cpp.

bool is_connected ( void   )

Check if associated with an access point (was checking if tcp link is active)

Follow this example to improve the automatic recovery after a lost association.

 WiflyInterface eth(p28, p27, p23, p24, "ssid", "pass", WPA);
 
 if (0 == eth.init()) {
     eth.baud(230400);     // speed up the interface
     do {
         if (0 == eth.connect()) {
             linkup = true;    // led indicator
             while (eth.is_connected()) {
                 wait_ms(1000);
             }
             linkup = false;   // led indicator
             eth.disconnect();
             wait_ms(1000);
         }
     } while (1);
 } else {
     wait(5);    // ... failed to initialize, rebooting...
     mbed_reset();
 }
Returns:
true if successful

Definition at line 470 of file Wifly.cpp.

bool isCmdMode (  )

determine if the module is in command mode

Returns:
true if in command mode, false otherwise

Definition at line 373 of file Wifly.h.

bool isDHCP (  )

Return true if the module is using dhcp.

Returns:
true if the module is using dhcp

Definition at line 289 of file Wifly.h.

bool join (  )

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

Returns:
true if connected, false otherwise

Definition at line 200 of file Wifly.cpp.

int putc ( char  c )

Write a character.

Parameters:
thecharacter which will be written
Returns:
the character written

Definition at line 541 of file Wifly.cpp.

int readable (  )

Check if characters are available.

Returns:
number of available characters

Definition at line 561 of file Wifly.cpp.

bool reboot (  )

Reboot the wifi module.

Returns:
true if it could send the command, false otherwise

Definition at line 503 of file Wifly.cpp.

void reset (  )

Reset the wifi module.

Definition at line 491 of file Wifly.cpp.

int send ( const char *  str,
int  len,
const char *  ACK = NULL,
char *  res = NULL,
int  timeout = DEFAULT_WAIT_RESP_TIMEOUT 
)

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
lenstring length
ACKstring which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknowledged. (default: NULL)
resthis field will contain the response from the wifi module, result of a command sent. This field is available only if ACK == NULL AND res != NULL (default: NULL)
timeoutis the time in msec to wait for the acknowledge
Returns:
true if ACK has been found in the response from the wifi module.
false if there is not a correct response in the timeout.

Definition at line 600 of file Wifly.cpp.

bool sendCommand ( const char *  cmd,
const char *  ack = NULL,
char *  res = NULL,
int  timeout = DEFAULT_WAIT_RESP_TIMEOUT 
)

Put the device in command mode.

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)
timeoutis the time in msec to wait for the acknowledge
Returns:
true if successful, false if it failed.

Definition at line 368 of file Wifly.cpp.

void setConnectionState ( bool  state )

Sets the connection state.

Typically used by external apps that detect an incoming connection.

Parameters:
statesets the connection state to true or false

Definition at line 866 of file Wifly.cpp.

bool setProtocol ( Protocol  p )

Set the protocol (UDP or TCP)

Parameters:
pprotocol
Returns:
true if successful

Definition at line 219 of file Wifly.cpp.

void SetSecurity ( const char *  ssid,
const char *  phrase,
Security  sec 
)

Optional means to set/reset the security.

If join() has not been called, then you can revise the security parameters from those in the constructor.

Parameters:
ssidssid of the network
phraseWEP or WPA key
secSecurity type (NONE, WEP_128, WPA1, WPA | WPA_MIXED, WPA2_PSK, WEP_64 )

Definition at line 76 of file Wifly.cpp.

bool SWUpdateWifly ( const char *  file )

Update the software in the Wifly module.

This attempts to connect to the microchip site, download a software update, install it as the primary image, and reboot to activate that image. It is compile-time defined to try for 30 seconds.

Parameters:
fileis the name of the file to fetch, to update to. The strlen(file) cannot exceed 60, and is typically like this: "Wifly7-475.mif"
Returns:
true if success or false for failure.

Definition at line 836 of file Wifly.cpp.

int writeable (  )

Check if characters are available.

Returns:
number of available characters

Definition at line 567 of file Wifly.cpp.