WifiHQ
 All Classes Files Functions Pages
Public Member Functions | Public Attributes
WiFly Class Reference

List of all members.

Public Member Functions

boolean begin (Stream *serialdev, Stream *debugPrint=NULL)
char * getSSID (char *buf, int size)
uint8_t getJoin ()
char * getDeviceID (char *buf, int size)
char * getIP (char *buf, int size)
uint16_t getPort ()
char * getNetmask (char *buf, int size)
char * getGateway (char *buf, int size)
char * getDNS (char *buf, int size)
char * getMAC (char *buf, int size)
int8_t getDHCPMode ()
uint32_t getRate ()
uint8_t getTxPower ()
uint16_t getConnection ()
int8_t getRSSI ()
bool setJoin (uint8_t join)
boolean setDeviceID (const char *buf)
boolean setBaud (uint32_t baud)
uint32_t getBaud ()
uint8_t getUartMode ()
uint8_t getIpFlags ()
uint8_t getProtocol ()
uint8_t getFlushChar ()
uint16_t getFlushSize ()
uint16_t getFlushTimeout ()
char getSpaceReplace (void)
char * getHostIP (char *buf, int size)
uint16_t getHostPort ()
boolean setSSID (const char *buf)
boolean setIP (const char *buf)
boolean setIP (const __FlashStringHelper *buf)
boolean setPort (const uint16_t port)
boolean setNetmask (const char *buf)
boolean setNetmask (const __FlashStringHelper *buf)
boolean setGateway (const char *buf)
boolean setDNS (const char *buf)
boolean setChannel (uint8_t channel)
boolean setKey (const char *buf)
boolean setPassphrase (const char *buf)
boolean setSpaceReplace (char ch)
boolean setDHCP (const uint8_t mode)
boolean setRate (uint32_t rate)
boolean setTxPower (uint8_t dBm)
boolean setHostIP (const char *buf)
boolean setHostIP (const __FlashStringHelper *buf)
boolean setHostPort (const uint16_t port)
boolean setHost (const char *buf, uint16_t port)
boolean setProtocol (const uint8_t protocol)
boolean setIpProtocol (const uint8_t protocol)
boolean setIpFlags (const uint8_t flags)
boolean setUartMode (const uint8_t mode)
boolean setBroadcastInterval (const uint8_t seconds)
boolean setTimeAddress (const char *buf)
boolean setTimePort (const uint16_t port)
boolean setTimezone (const uint8_t zone)
boolean setTimeEnable (const uint16_t enable)
boolean setAdhocBeacon (const uint16_t msecs)
boolean setAdhocProbe (const uint16_t secs)
uint16_t getAdhocBeacon ()
uint16_t getAdhocProbe ()
uint16_t getAdhocReboot ()
boolean setFlushTimeout (const uint16_t timeout)
boolean setFlushChar (const char flushChar)
boolean setFlushSize (uint16_t size)
boolean enableDataTrigger (const uint16_t flushtime=10, const char flushChar=0, const uint16_t flushSize=64)
boolean disableDataTrigger ()
boolean enableUdpAutoPair ()
boolean disableUdpAutoPair ()
boolean setIOFunc (const uint8_t func)
char * getTime (char *buf, int size)
uint32_t getUptime ()
uint8_t getTimezone ()
uint32_t getRTC ()
bool getHostByName (const char *hostname, char *buf, int size)
boolean ping (const char *host)
boolean enableDHCP ()
boolean disableDHCP ()
boolean createAdhocNetwork (const char *ssid, uint8_t channel)
boolean join (const char *ssid, uint16_t timeout=20000)
boolean join (uint16_t timeout=20000)
boolean join (const char *ssid, const char *password, bool dhcp=true, uint8_t mode=WIFLY_MODE_WPA, uint16_t timeout=20000)
boolean leave ()
boolean isAssociated ()
boolean save ()
boolean reboot ()
boolean factoryRestore ()
boolean sendto (const uint8_t *data, uint16_t size, const char *host, uint16_t port)
boolean sendto (const uint8_t *data, uint16_t size, IPAddress host, uint16_t port)
boolean sendto (const char *data, const char *host, uint16_t port)
boolean sendto (const char *data, IPAddress host, uint16_t port)
boolean sendto (const __FlashStringHelper *data, const char *host, uint16_t port)
boolean sendto (const __FlashStringHelper *data, IPAddress host, uint16_t port)
void enableHostRestore ()
void disableHostRestore ()
boolean open (const char *addr, int port=80, boolean block=true)
boolean open (IPAddress addr, int port=80, boolean block=true)
boolean close ()
boolean openComplete ()
boolean isConnected ()
boolean isInCommandMode ()
virtual size_t write (uint8_t byte)
virtual int read ()
virtual int available ()
virtual void flush ()
virtual int peek ()
char * iptoa (IPAddress addr, char *buf, int size)
IPAddress atoip (char *buf)
boolean isDotQuad (const char *addr)
void sendChunk (const char *str)
void sendChunk (const __FlashStringHelper *str)
void sendChunkln (const char *str)
void sendChunkln (const __FlashStringHelper *str)
void sendChunkln (void)
int getFreeMemory ()
void terminal ()
void dbgBegin (int size=256)
void dbgDump ()
void dbgEnd ()
boolean match (const char *str, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT)
boolean match (const __FlashStringHelper *str, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT)
int multiMatch_P (uint16_t timeout, uint8_t count,...)
int gets (char *buf, int size, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT)
int getsTerm (char *buf, int size, char term, uint16_t timeout=WIFLY_DEFAULT_TIMEOUT)
void flushRx (int timeout=WIFLY_DEFAULT_TIMEOUT)
boolean setFtpDefaults (void)
boolean setFtpAddress (const char *addr)
boolean setFtpPort (uint16_t port)
boolean setFtpDirectory (const char *dir)
boolean setFtpUser (const char *user)
boolean setFtpPassword (const char *password)
boolean setFtpFilename (const char *filename)
boolean setFtpTimer (uint16_t msecs)
boolean setFtpMode (uint8_t mode)
boolean ftpGet (const char *addr, const char *dir, const char *user, const char *password, const char *filename)

Public Attributes

boolean debugOn
uint8_t tcp
uint8_t assoc
uint8_t authen
uint8_t dnsServer
uint8_t dnsFound
uint8_t channel

Member Function Documentation

IPAddress WiFly::atoip ( char *  buf)

Convert a dotquad IP address string to an IPAddress. E.g. "192.168.1.100" -> { 192, 168, 1, 100 }.

Parameters:
buf- the string to convert
Returns:
the IPAddress form of the string
int WiFly::available ( )
virtual

Check to see if data is available to be read.

Returns:
the number of bytes that are available to read.
Return values:
0- no data available
-1- active TCP connection was closed,
boolean WiFly::begin ( Stream *  serialdev,
Stream *  debugPrint = NULL 
)

Start the WiFly device, set it up to handle commands, obtain some initial status (TCP connection status, WiFi association, etc).

Parameters:
serialdev- the serial stream to use to talk to the WiFly.
debugPrint- optional debug stream for errors and status.
Return values:
true- WiFly ready for use
false- failed to initialise WiFly
boolean WiFly::close ( )

Close the TCP connection

Return values:
true- connection closed
false- failed to close
boolean WiFly::createAdhocNetwork ( const char *  ssid,
uint8_t  channel 
)

Create an Adhoc WiFi network. The WiFly is assigned IP address 169.254.1.1.

Parameters:
ssidthe SSID to use for the network
channelthe WiFi channel to use; 1 to 13.
Return values:
true- successfully create Ad Hoc network
false- failed
Note:
the WiFly is rebooted as the final step of this command.
void WiFly::dbgBegin ( int  size = 256)

Start a capture of all the characters recevied from the WiFly.

Parameters:
size- the size of the capture buffer. This will be malloced.
void WiFly::dbgDump ( )

Do a hex and ASCII dump of the capture buffer, and free the buffer.

void WiFly::dbgEnd ( )

Stop debug capture and free buffer

void WiFly::disableHostRestore ( )

Don't preserve the IP and Port set via setIP() and setPort() when using sendto() function. The IP and Port will be left set by the last sendto() call.

boolean WiFly::enableDataTrigger ( const uint16_t  flushTimeout = 10,
const char  flushChar = 0,
const uint16_t  flushSize = 64 
)

Enable data trigger mode. This mode will automatically send a new packet based on several conditions:

  1. If no characters are sent to the WiFly for at least the flushTimeout period.
  2. If the character defined by flushChar is sent to the WiFly.
  3. If the number of characters sent to the WiFly reaches flushSize.
    Parameters:
    flushTimeoutSend a packet if no more characters are sent within this many milliseconds. Set to 0 to disable.
    flushCharSend a packet when this character is sent to the WiFly. Set to 0 to disable.
    flushSizeSend a packet when this many characters have been sent to the WiFly.
    Returns:
    true on success, else false.
    Note:
    as of 2.32 firmware, the flushTimeout parameter does not take affect until after a save and reboot.
void WiFly::enableHostRestore ( )

Preserve the IP and Port set via setIP() and setPort() when using sendto() function.

boolean WiFly::enableUdpAutoPair ( )

Enable the UDP auto-pair functionality. The WiFly will automatically set the Host IP and port to match the sender of the last UDP packet.

boolean WiFly::factoryRestore ( )

Restore factory default settings

void WiFly::flushRx ( int  timeout = WIFLY_DEFAULT_TIMEOUT)

Flush the incoming data from the WiFly.

Parameters:
timeout- the number of milliseconds to wait for additional data to flush. Default is 500msecs.
int WiFly::getFreeMemory ( )

Return number of bytes of memory available.

Returns:
number of bytes of free memory
bool WiFly::getHostByName ( const char *  hostname,
char *  buf,
int  size 
)

Do a DNS lookup to find the ip address of the specified hostname

Parameters:
hostname- host to lookup
buf- buffer to return the ip address in
size- size of the buffer
Returns:
true on success, false on failure
char * WiFly::getHostIP ( char *  buf,
int  size 
)

Get remote IP address

uint16_t WiFly::getHostPort ( )

Get remote port

char * WiFly::getIP ( char *  buf,
int  size 
)

Get local IP address

uint16_t WiFly::getPort ( )

Get local port

uint32_t WiFly::getRate ( )

Return the current WiFi data rate in bits/sec

Returns:
current data rate in bits/sec
int WiFly::gets ( char *  buf,
int  size,
uint16_t  timeout = WIFLY_DEFAULT_TIMEOUT 
)

Read characters into the buffer until a carriage-return and newline is reached. If the buffer is too small, the remaining characters in the line are discarded.

Parameters:
buf- the buffer to read into. If this is NULL then all characters in the line are discarded.
size- the size of the buffer (max number of characters it can store)
timeout- the number of milliseconds to wait for a new character to arrive
Returns:
the number of characters read into the buffer.
Return values:
0- timeout reading newline
Note:
The buffer will be null terminated, and in effect can hold size-1 characters.
uint8_t WiFly::getTxPower ( )

Get the current transmit power.

Returns:
tx power in dBm
char * WiFly::iptoa ( IPAddress  addr,
char *  buf,
int  size 
)

Convert an IPAdress to an ASCIIZ string

Parameters:
addr- the IP Address to convert
buf- the buffer to write the result to
size- the size of the buffer
Returns:
pointer to the result
boolean WiFly::isAssociated ( )

Check to see if the WiFly is connected to a wireless network

boolean WiFly::isConnected ( )

Check to see if there is a tcp connection.

Return values:
trueconnected
falsenot connected
boolean WiFly::isDotQuad ( const char *  addr)

See if the string is a valid dot quad IP address

boolean WiFly::join ( const char *  ssid,
uint16_t  timeout = 20000 
)

join a wireless network

boolean WiFly::join ( uint16_t  timeout = 20000)

join a wireless network

boolean WiFly::join ( const char *  ssid,
const char *  password,
bool  dhcp = true,
uint8_t  mode = WIFLY_MODE_WPA,
uint16_t  timeout = 20000 
)

Join a wireless network.

Parameters:
ssidThe SSID of the network to join
passwordThe WPA passphrase or WEP hex key.
dhcpset to true to enable DHCP
modeWIFLY_MODE_WPA for WPA security, or WIFLY_MODE_WEP for WEP security.
timeoutnumber of milliseconds to try connecting before timing out.
Returns:
true on success, false on failure.
boolean WiFly::leave ( )

leave the wireless network

boolean WiFly::match ( const char *  str,
uint16_t  timeout = WIFLY_DEFAULT_TIMEOUT 
)

Read characters from the WiFly and match them against the string. Ignore any leading characters that don't match. Keep reading, discarding the input, until the string is matched or until no characters are received for the timeout duration.

Parameters:
strThe string to match
timeoutfail if no data received for this period (in milliseconds).
Return values:
true- a match was found
false- no match found, timeout reached
boolean WiFly::match ( const __FlashStringHelper *  str,
uint16_t  timeout = WIFLY_DEFAULT_TIMEOUT 
)

Read characters from the WiFly and match them against the flash string. Ignore any leading characters that don't match. Keep reading, discarding the input, until the string is matched or until no characters are received for the timeout duration.

Parameters:
strThe string to match (in flash memory) fail if no data received for this period (in milliseconds).
Return values:
true- a match was found
false- no match found, timeout reached
int WiFly::multiMatch_P ( uint16_t  timeout,
uint8_t  count,
  ... 
)

Read characters from the WiFly and match them against the set of progmem strings. Ignore any leading characters that don't match. Keep reading, discarding the input, until one of the strings is matched or until no characters are received for the timeout duration.
Example: res = multiMatch_P(500, 3, F("first="), F("second="), F("closed"));
Will return 0 if "first=" is matched, 1 if "second=" is matched, 2 if "closed" is matched, or -1 if nothing is matched and no data is received for 500 milliseconds.

Parameters:
timeout- fail if no data received for this period (in milliseconds).
count- the number of strings in the str array
...A list of count progmem strings to match
Returns:
the index of the matching string
Return values:
-1- no match found, timeout reached
boolean WiFly::open ( const char *  addr,
int  port = 80,
boolean  block = true 
)

Open a TCP connection. If there is already an open connection then that is closed first.

Parameters:
addr- the IP address or hostname to connect. A DNS lookup will be peformed for the hostname.
port- the TCP port to connect to
block- true = wait for the connection to complete false = start the connection and return. Use openComplete() to determine the result.
Return values:
true- success, the connection is open
false- failed, or connection already in progress
boolean WiFly::open ( IPAddress  addr,
int  port = 80,
boolean  block = true 
)

Open a TCP connection. If there is already an open connection then that is closed first.

Parameters:
addr- the IP address to connect to
port- the TCP port to connect to
block- true = wait for the connection to complete false = start the connection and return. Use openComplete() to determine the result.
Return values:
true- success, the connection is open
false- failed, or connection already in progress
boolean WiFly::openComplete ( )

Check to see if the non-blocking open has completed. When this returns true the open has finished with either success or failure. You can use isConnected() to see if the open was successful.

Return values:
true- the open operation has completed
false- the open is still in progress
int WiFly::peek ( )
virtual

Return the next byte that a read() would return, but leave the byte in the receive buffer.

Returns:
the next byte that would be read
Return values:
-1- no data in receive buffer
boolean WiFly::ping ( const char *  host)

Ping the specified host. Return true if a ping response is received, else false.

Parameters:
hostthe host or IP address to ping
Return values:
true- received ping response
false- no response from host
int WiFly::read ( )
virtual

Read the next byte from the WiFly.

Returns:
the byte read
Return values:
-1- nothing in the receive buffer to read
boolean WiFly::reboot ( )

Reboots the WiFly.

Note:
Depending on the shield, this may also reboot the Arduino.
void WiFly::sendChunk ( const char *  str)

Send a string as an HTTP chunk without a newline An HTTP chunk is the length of the string in HEX followed by the string.

Parameters:
strthe string to send
void WiFly::sendChunk ( const __FlashStringHelper *  str)

Send a progmem string as an HTTP chunk without a newline. An HTTP chunk is the length of the string in HEX followed by the string.

Parameters:
strthe string to send
void WiFly::sendChunkln ( const char *  str)

Send a string as an HTTP chunk with newline An HTTP chunk is the length of the string in HEX followed by the string.

Parameters:
strthe string to send
void WiFly::sendChunkln ( const __FlashStringHelper *  str)

Send a progmame string as an HTTP chunk with newline An HTTP chunk is the length of the string in HEX followed by the string.

Parameters:
strthe string to send
void WiFly::sendChunkln ( void  )

Send final chunk, end of HTTP message

boolean WiFly::sendto ( const uint8_t *  data,
uint16_t  size,
const char *  host,
uint16_t  port 
)

Send binary data as a UDP packet to a host.

Parameters:
data- pointer to an array of data to send
size- then number of bytes of data to send
host- the IP or hostname to send the packet to. If this is a hostname then a DNS lookup will be performed to find the IP address.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::sendto ( const uint8_t *  data,
uint16_t  size,
IPAddress  host,
uint16_t  port 
)

Send binary data as a UDP packet to a host.

Parameters:
data- pointer to an array of data to send
size- then number of bytes of data to send
host- the IP address to send the packet to.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::sendto ( const char *  data,
const char *  host,
uint16_t  port 
)

Send a string as a UDP packet to a host.

Parameters:
data- the null terminated string to send
host- the IP or hostname to send the packet to. If this is a hostname then a DNS lookup will be performed to find the IP address.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::sendto ( const char *  data,
IPAddress  host,
uint16_t  port 
)

Send a string as a UDP packet to a host.

Parameters:
data- the null terminated string to send
host- the IP address to send the packet to.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::sendto ( const __FlashStringHelper *  flashData,
const char *  host,
uint16_t  port 
)

Send a string as a UDP packet to a host.

Parameters:
data- the null terminated flash string to send
host- the IP or hostname to send the packet to. If this is a hostname then a DNS lookup will be performed to find the IP address.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::sendto ( const __FlashStringHelper *  flashData,
IPAddress  host,
uint16_t  port 
)

Send a string as a UDP packet to a host.

Parameters:
data- the null terminated flash string to send
host- the IP address to send the packet to.
port- the UDP port to send the packet to
Return values:
true- packet send successfully
false- failed to send packet
boolean WiFly::setAdhocBeacon ( const uint16_t  msecs)

Set the ad hoc beacon period in milliseconds. The beacon is a management frame needed to keep the network alive. Default is 100 milliseconds.

Parameters:
msecsthe number of milliseconds between beacon
Returns:
true on success, false on failure.
boolean WiFly::setAdhocProbe ( const uint16_t  secs)

Set the ad hoc network probe period. When this number of seconds passes since last receiving a beacon then the network is declared lost. Default is 5 seconds..

Parameters:
secsthe number of seconds in the probe period.
Returns:
true on success, false on failure.
boolean WiFly::setBroadcastInterval ( const uint8_t  seconds)

Set the UDP broadcast time interval.

Parameters:
secondsthe number of seconds between broadcasts. Set this to zero to disable broadcasts.
Returns:
true if sucessful, else false.
boolean WiFly::setChannel ( uint8_t  channel)

Set the WiFi channel.

Parameters:
channelthe wifi channel from 0 to 13. 0 means auto channel scan.
Returns:
true if successful, else false.
boolean WiFly::setFlushChar ( const char  flushChar)

Set the comms flush character. 0 disables the feature. A packet will be sent whenever this character is sent to the WiFly. Used for auto connect mode or UDP packet sending.

Parameters:
flushCharsend a packet when this character is sent. Set to 0 to disable character based flush.
boolean WiFly::setFlushSize ( uint16_t  size)

Set the comms flush size. A packet will be sent whenever this many characters are sent.

Parameters:
sizenumber of characters to buffer before sending a packet
boolean WiFly::setFlushTimeout ( const uint16_t  timeout)

Set comms flush timeout. When using data trigger mode, this timer defines how long the WiFly will wait for the next character from the sketch before sending what it has collected so far as a packet.

Parameters:
timeoutnumber of milliseconds to wait before flushing the packet.
Note:
the flush timeout change does not actually work unless the config is saved and the wifly is rebooted.
boolean WiFly::setFtpDefaults ( void  )

Restore the default ftp settings. These are the settings needed to upgrade the firmware. Is this needed? Why not just use factory defaults?

boolean WiFly::setIOFunc ( const uint8_t  func)

Set the WiFly IO function option

boolean WiFly::setKey ( const char *  buf)

Set WEP key

boolean WiFly::setPassphrase ( const char *  buf)

Set WPA passphrase. Spaces are automatically replaced with the current space substitution character ('$' is the default). : If your passphrase contains a '$' then use setSpaceReplace() to change the replacement character to something you're not using.

boolean WiFly::setPort ( const uint16_t  port)

Set local port

boolean WiFly::setRate ( uint32_t  rate)

Set WiFi data rate

Parameters:
ratethe data rate to set in bits per second. valid values are 1000000, 2000000, 5500000, 6000000, 9000000, 11000000, 12000000, 18000000, 24000000, 36000000, 48000000, 54000000.
Returns:
true on success, false on failure.
Note:
rates are rounded up to the nearest valid value
boolean WiFly::setSpaceReplace ( char  ch)

Set the space replacement character in WPA passphrase. Default is '$'.

boolean WiFly::setTimeAddress ( const char *  buf)

Set NTP server IP address

boolean WiFly::setTimeEnable ( const uint16_t  period)

Set the NTP update period

boolean WiFly::setTimePort ( const uint16_t  port)

Set NTP server port

boolean WiFly::setTimezone ( const uint8_t  zone)

Set timezone for calculating local time based on NTP time.

boolean WiFly::setTxPower ( uint8_t  dBm)

Set the transmit power level.

Parameters:
dBmpower level from 1 to 12 dBm
Returns:
true on success, false on failure. @ Note: a setting of 0 means max power which is 12 dBm.
void WiFly::terminal ( )

Start a simple terminal that connects the debug stream to the WiFly. Useful for debugging and manually setting and reading WiFly options.

size_t WiFly::write ( uint8_t  byte)
virtual

Write a byte to the WiFly.

Parameters:
byte- the byte to write.
Returns:
the number of bytes written (1).

The documentation for this class was generated from the following files: