- Added messages

Fork of WiflyInterface by Damien Frost

Embed: (wiki syntax)

« Back to documentation index

WiflyInterface Class Reference

WiflyInterface Class Reference

Interface using Wifly to connect to an IP-based network. More...

#include <WiflyInterface.h>

Inherits Wifly.

Public Member Functions

 WiflyInterface (PinName tx, PinName rx, PinName reset, PinName tcp_status, const char *ssid, const char *phrase, Security sec, Serial *messagesPort)
 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.
bool join ()
 Connect the wifi module to the ssid contained in the constructor.
void setBaud (int baudrate)
 Sets the baudrate of the serial port used to communicate with the ethernet/wifi adapter.
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 a 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.
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)
 Send a command to the wify module.
int checkNetworkStatus (void)
 Check if the wifly module is still connected to the network:
bool isDHCP ()
 Return true if the module is using dhcp.
void sleep (void)
 Puts the module to sleep.

Static Public Attributes

static Serial * SerialCommPort
 Serial port to display debug messages.

Detailed Description

Interface using Wifly to connect to an IP-based network.

Definition at line 28 of file WiflyInterface.h.


Constructor & Destructor Documentation

WiflyInterface ( PinName  tx,
PinName  rx,
PinName  reset,
PinName  tcp_status,
const char *  ssid,
const char *  phrase,
Security  sec,
Serial *  messagesPort 
)

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 or WPA)

Definition at line 11 of file WiflyInterface.cpp.


Member Function Documentation

int checkNetworkStatus ( void   ) [inherited]

Check if the wifly module is still connected to the network:

Returns:
0: if not connected 1: if connected

Definition at line 626 of file Wifly.cpp.

bool close (  ) [inherited]

Close a tcp connection.

Returns:
true if successful

Definition at line 438 of file Wifly.cpp.

bool cmdMode (  ) [inherited]

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

Returns:
true if successful, false otherwise

Definition at line 374 of file Wifly.cpp.

bool connect ( const char *  host,
int  port 
) [inherited]

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 262 of file Wifly.cpp.

int connect (  )

Connect Bring the interface up, start DHCP if needed.

Returns:
0 on success, a negative number on failure

Definition at line 39 of file WiflyInterface.cpp.

int disconnect (  )

Disconnect Bring the interface down.

Returns:
0 on success, a negative number on failure

Reimplemented from Wifly.

Definition at line 47 of file WiflyInterface.cpp.

bool exit (  ) [inherited]

To exit the command mode.

Returns:
true if successful, false otherwise

Definition at line 461 of file Wifly.cpp.

void flush (  ) [inherited]

Flush the buffer.

Definition at line 351 of file Wifly.cpp.

char getc (  ) [inherited]

Read a character.

Returns:
the character read

Definition at line 484 of file Wifly.cpp.

char * getIPAddress (  )

Get IP address.

Returns:
ip address

Definition at line 52 of file WiflyInterface.cpp.

int init ( const char *  ip,
const char *  mask,
const char *  gateway 
)

Initialize the interface with a static IP address.

Initialize the interface and configure it with the following static configuration (no connection at this point).

Parameters:
ipthe IP address to use
maskthe IP address mask
gatewaythe gateway to use
Returns:
0 on success, a negative number on failure

Definition at line 26 of file WiflyInterface.cpp.

int init ( void   )

Initialize the interface with DHCP.

Initialize the interface and configure it to use DHCP (no connection at this point).

Returns:
0 on success, a negative number on failure

Definition at line 18 of file WiflyInterface.cpp.

bool is_connected ( void   ) [inherited]

Check if a tcp link is active.

Returns:
true if successful

Definition at line 404 of file Wifly.cpp.

bool isDHCP (  ) [inherited]

Return true if the module is using dhcp.

Returns:
true if the module is using dhcp

Definition at line 221 of file Wifly.h.

bool join (  ) [inherited]

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

Returns:
true if connected, false otherwise

Definition at line 107 of file Wifly.cpp.

int putc ( char  c ) [inherited]

Write a character.

Parameters:
thecharacter which will be written

Definition at line 454 of file Wifly.cpp.

int readable (  ) [inherited]

Check if characters are available.

Returns:
number of available characters

Definition at line 474 of file Wifly.cpp.

bool reboot (  ) [inherited]

Reboot the wifi module.

Definition at line 426 of file Wifly.cpp.

void reset (  ) [inherited]

Reset the wifi module.

Definition at line 410 of file Wifly.cpp.

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

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 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 514 of file Wifly.cpp.

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

Send a command to the wify module.

Check if the module is in command mode. If not enter 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)
Returns:
true if successful

Definition at line 356 of file Wifly.cpp.

void setBaud ( int  baudrate ) [inherited]

Sets the baudrate of the serial port used to communicate with the ethernet/wifi adapter.

Parameters:
baudrateThe baudrate that the connection should be set to. Valid values are: 2400, 4800, 9600, 19200, 38400, 115200, 230400, 460800, 921600 do NOT go above 230400

Definition at line 86 of file Wifly.cpp.

bool setProtocol ( Protocol  p ) [inherited]

Set the protocol (UDP or TCP)

Parameters:
pprotocol
Returns:
true if successful

Definition at line 221 of file Wifly.cpp.

void sleep ( void   ) [inherited]

Puts the module to sleep.

Definition at line 657 of file Wifly.cpp.

int writeable (  ) [inherited]

Check if characters are available.

Returns:
number of available characters

Definition at line 479 of file Wifly.cpp.


Field Documentation

Serial * SerialCommPort [static, inherited]

Serial port to display debug messages.

Definition at line 235 of file Wifly.h.