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

Resources

Derivative from mbed Official

  • Documentation update, improved consistency, documented parameters that were inadvertently omitted.
  • Avoid c++ string handling, which causes dynamic allocation and free, side effect, fewer CPU cycles spent for same purpose.
  • Fixed socket APIs to support non-blocking mode.
  • Increase communication baud-rate to Wifly module
  • sendCommand - added retries for improved robustness.
  • setConnectionState - method to force the connection state (used by TCPSocketServer)
  • gethostbyname - added a length parameter to the size of the buffer being written
  • flushIn - a private method to flush the input buffer
  • Changed the timeout from 500 to 2500 msec for commands - measured some at 700 to 850 msec.
  • Performance improvements - reduced some unnecessary delays.
  • Added additional security options for the wi-fi connection (that are supported by the WiFly module).
  • Added setSecurity API which permits revising the security when connecting to, or selecting from, one of several access points.
  • Improved DEBUG interface (slightly more consistent printout).
  • gathers information from the Wifly module on reboot (SW version info), which permits customizing behavior based on Wifly capabilities (like the improved security).
  • Avoid potential for recursive crash (if exit fails, it calls sendcommand, which calls exit...)
  • Update to support permissible SSID and PassCode lengths.

Robustness testing

I've had some mixed behavior with the Wifly module, some of which seems to be traceable to the module itself, and some in my derivative code. The result, after running for minutes, hours, sometimes days, it hangs and I have to reset the module.

To test, I created a fairly simple test program -

  • check for Watchdog induced reset and count it.
  • initialize the Watchdog for 60 sec timeout.
  • Init the Wifly interface and connect to my network.
  • Wait 10 seconds and force mbed_reset().

If the Watchdog induces the restart, then it is pretty clear that either:

  • The communications hung with the Wifly module causing the failure.
  • The Wifly module decided to go unresponsive.

If it gets to the end, it typically takes about 4 to 6 seconds for the boot and connect, then the 10 second delay.

But I can't really pin down the root cause easily. My strongest theory is that the Wifly module has rebooted, and since I don't store the high baud rate I configure it for, it resets back to 9600.

Also, one of the objectives for my revised send( ) is to avoid the c++ string, as that can fragment memory, and it wasn't very well bounded in behavior.

Latest tests:

Warm BootsWatchdog EventsNotes
100's30An early version of my derivative WiflyInterface, including my derivative of "send( )" API. Let's call this version 0.1.
26684My derivative WiflyInterface, but with the mbed official "send( )" API. Much improved. This was over the course of about 12 hours.
24003Most recent derivative - incremental change to "send( )", but this relative number does not rule out the Wifly module itself.

I think with these numbers, +/- 1 means that the changes have had no measurable effect. Which is good, since this incremental change eliminates the c++ string handling.

Test Software

This is pieces of a test program, clipped and copied to here. What I have compiled and run for hours and hours is almost exactly what you see. This uses this simple Watchdog library.

#include "mbed.h"
#include "WiflyInterface.h"
#include "Watchdog.h"

Serial pc(USBTX, USBRX);

Watchdog wd;
extern "C" void mbed_reset();

// Pinout for SmartBoard
WiflyInterface wifly(p9, p10, p30, p29, "ssid", "pass", WPA);

int main() {
    pc.baud(460800);                         // I like a snappy terminal
    
    wd.Configure(60.0);                     // Set time limit for the test to 1 minute
    LPC_RTC->GPREG0++;                      // Count boots here
    if (wd.WatchdogCausedReset()) {
        LPC_RTC->GPREG1++;                  // Count Watchdog events here
        pc.printf("\r\n\r\nWatchdog event.\r\n");
    }
    pc.printf("\r\nWifly Test: %d boots, %d watchdogs. %s %s\r\n", LPC_RTC->GPREG0, LPC_RTC->GPREG1, __DATE__, __TIME__);
    
    wifly.init(); // use DHCP
    pc.printf("Connect...  ");
    while (!wifly.connect());               // join the network
    pc.printf("Address is %s.  ", wifly.getIPAddress());
    pc.printf("Disconnect...  ");
    wifly.disconnect();
    pc.printf("OK. Reset in 10 sec...\r\n");
    wait(10);
    if (pc.readable()) {
        if (pc.getc() == 'r') {             // secret 'r'eset of the counters
            LPC_RTC->GPREG0 = 0;
            LPC_RTC->GPREG1 = 0;
            pc.printf("counters reset\r\n");
        }
    }
    mbed_reset();                           // reset here indicates successful communication
}

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Thu Nov 28 18:17:00 2013 +0000
Parent:
50:cc173c24a316
Child:
52:ffc0b655a23c
Commit message:
Documentation updates - put all files into a more similar format for the doxygen tags.; Reduce some of the verbose debugging information.; Small amount of code size reduction (reduced some redundancy)

Changed in this revision

Socket/Endpoint.h Show annotated file Show diff for this revision Revisions of this file
Socket/Socket.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.h Show annotated file Show diff for this revision Revisions of this file
Socket/UDPSocket.h Show annotated file Show diff for this revision Revisions of this file
Wifly/Wifly.cpp Show annotated file Show diff for this revision Revisions of this file
Wifly/Wifly.h Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.cpp Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Endpoint.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Socket/Endpoint.h	Thu Nov 28 18:17:00 2013 +0000
@@ -40,19 +40,19 @@
     void reset_address(void);
     
     /** Set the address of this endpoint
-    \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS).
-    \param port The endpoint port
-    \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS).
+    @param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS).
+    @param port The endpoint port
+    @return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS).
      */
     int  set_address(const char* host, const int port);
     
     /** Get the IP address of this endpoint
-    \return The IP address of this endpoint.
+    @return The IP address of this endpoint.
      */
     char* get_address(void);
     
     /** Get the port of this endpoint
-    \return The port of this endpoint
+    @return The port of this endpoint
      */
     int get_port(void);
 
--- a/Socket/Socket.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Socket/Socket.h	Thu Nov 28 18:17:00 2013 +0000
@@ -30,9 +30,9 @@
     
     /** Set blocking or non-blocking mode of the socket and a timeout on
         blocking socket operations
-    \param blocking  true for blocking mode, false for non-blocking mode.
-    \param timeout   timeout in ms [Default: (1500)ms] when non-blocking.
-    \note if timeout is < 10 msec, it is set to 10 to avoid problems
+    @param blocking  true for blocking mode, false for non-blocking mode.
+    @param timeout   timeout in ms [Default: (1500)ms] when non-blocking.
+    @note if timeout is < 10 msec, it is set to 10 to avoid problems
           in other parts of the socket interface.
     */
     void set_blocking(bool blocking, unsigned int timeout=1500);
--- a/Socket/TCPSocketConnection.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Socket/TCPSocketConnection.h	Thu Nov 28 18:17:00 2013 +0000
@@ -33,42 +33,42 @@
     TCPSocketConnection();
     
     /** Connects this TCP socket to the server
-    \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
-    \param port The host's port to connect to.
-    \return 0 on success, -1 on failure.
+    @param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
+    @param port The host's port to connect to.
+    @return 0 on success, -1 on failure.
     */
     int connect(const char* host, const int port);
     
     /** Check if the socket is connected
-    \return true if connected, false otherwise.
+    @return true if connected, false otherwise.
     */
     bool is_connected(void);
     
     /** Send data to the remote host.
-    \param data The buffer to send to the host.
-    \param length The length of the buffer to send.
-    \return the number of written bytes on success (>=0) or -1 on failure
+    @param data The buffer to send to the host.
+    @param length The length of the buffer to send.
+    @return the number of written bytes on success (>=0) or -1 on failure
      */
     int send(char* data, int length);
     
     /** Send all the data to the remote host.
-    \param data The buffer to send to the host.
-    \param length The length of the buffer to send.
-    \return the number of written bytes on success (>=0) or -1 on failure
+    @param data The buffer to send to the host.
+    @param length The length of the buffer to send.
+    @return the number of written bytes on success (>=0) or -1 on failure
     */
     int send_all(char* data, int length);
     
     /** Receive data from the remote host.
-    \param data The buffer in which to store the data received from the host.
-    \param length The maximum length of the buffer.
-    \return the number of received bytes on success (>=0) or -1 on failure
+    @param data The buffer in which to store the data received from the host.
+    @param length The maximum length of the buffer.
+    @return the number of received bytes on success (>=0) or -1 on failure
      */
     int receive(char* data, int length);
     
     /** Receive all the data from the remote host.
-    \param data The buffer in which to store the data received from the host.
-    \param length The maximum length of the buffer.
-    \return the number of received bytes on success (>=0) or -1 on failure
+    @param data The buffer in which to store the data received from the host.
+    @param length The maximum length of the buffer.
+    @return the number of received bytes on success (>=0) or -1 on failure
     */
     int receive_all(char* data, int length);
 };
--- a/Socket/TCPSocketServer.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Socket/TCPSocketServer.h	Thu Nov 28 18:17:00 2013 +0000
@@ -30,15 +30,15 @@
     TCPSocketServer();
     
     /** Bind a socket to a specific port.
-    \param port The port to listen for incoming connections on.
-    \return 0 on success, -1 on failure.
+    @param port The port to listen for incoming connections on.
+    @return 0 on success, -1 on failure.
     */
     int bind(int port);
     
     /** Start listening for incoming connections.
-    \param backlog number of pending connections that can be queued up at any
+    @param backlog number of pending connections that can be queued up at any
                    one time [Default: 1].
-    \return 0 on success, -1 on failure.
+    @return 0 on success, -1 on failure.
     */
     int listen(int backlog=1);
     
@@ -47,8 +47,8 @@
     * For the Wifly module, this looks for *OPEN* in the stream, and
     * then indicates success.
     *
-    * \param connection A TCPSocketConnection instance that will handle the incoming connection.
-    * \return 0 on success, -1 on failure.
+    * @param connection A TCPSocketConnection instance that will handle the incoming connection.
+    * @return 0 on success, -1 on failure.
     */
     int accept(TCPSocketConnection& connection);
     
--- a/Socket/UDPSocket.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Socket/UDPSocket.h	Thu Nov 28 18:17:00 2013 +0000
@@ -35,30 +35,30 @@
     UDPSocket();
     
     /** Init the UDP Client Socket without binding it to any specific port
-    \return 0 on success, -1 on failure.
+    @return 0 on success, -1 on failure.
     */
     int init(void);
     
     /** Bind a UDP Server Socket to a specific port
-    \param port The port to listen for incoming connections on
-    \return 0 on success, -1 on failure.
+    @param port The port to listen for incoming connections on
+    @return 0 on success, -1 on failure.
     */
     int bind(int port = -1);
     
     /** Send a packet to a remote endpoint
-    \param remote   The remote endpoint
-    \param packet   The packet to be sent
-    \param length   The length of the packet to be sent
-    \return the number of written bytes on success (>=0) or -1 on failure
+    @param remote   The remote endpoint
+    @param packet   The packet to be sent
+    @param length   The length of the packet to be sent
+    @return the number of written bytes on success (>=0) or -1 on failure
     */
     int sendTo(Endpoint &remote, char *packet, int length);
     
     /** Receive a packet from a remote endpoint
-    \param remote   The remote endpoint
-    \param buffer   The buffer for storing the incoming packet data. If a packet
+    @param remote   The remote endpoint
+    @param buffer   The buffer for storing the incoming packet data. If a packet
            is too long to fit in the supplied buffer, excess bytes are discarded
-    \param length   The length of the buffer
-    \return the number of received bytes on success (>=0) or -1 on failure
+    @param length   The length of the buffer
+    @return the number of received bytes on success (>=0) or -1 on failure
     */
     int receiveFrom(Endpoint &remote, char *buffer, int length);
     
--- a/Wifly/Wifly.cpp	Sat Oct 12 23:38:43 2013 +0000
+++ b/Wifly/Wifly.cpp	Thu Nov 28 18:17:00 2013 +0000
@@ -23,9 +23,9 @@
 #include <ctype.h>
 
 // Defined to disable remote configuration via telnet which increases security of this device.
-//#define INCREASE_SECURITY
+#define INCREASE_SECURITY
 
-#define DEBUG       //Debug is disabled by default
+//#define DEBUG       //Debug is disabled by default
 
 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
 #define DBG(x, ...)  std::printf("[DBG Wifly%3d] "x"\r\n", __LINE__, ##__VA_ARGS__);
@@ -344,7 +344,7 @@
 
 void Wifly::flush()
 {
-#ifdef DEBUG
+#if 0 and defined(DEBUG)
     char chatter[500];
     int count = 0;
     char c;
@@ -385,9 +385,12 @@
     if (state.cmd_mode) {
         // Quick verify to ensure we really are in cmd mode
         flushIn(0);
+        //INFO("  send \\r to test for cmdMode");
         if (send("\r", 1, ">") == 1) {
+            //INFO("  is cmdMode");
             return true;
         } else {
+            INFO(" failed to detect command mode");
             setCmdMode(false);
         }
     }
@@ -436,7 +439,7 @@
 {
     if (sendCommand("reboot\r", "Reboot")) {
         setCmdMode(false);
-        INFO("  cmdMode = false");
+        //INFO("  cmdMode = false");
         wait_ms(500);
         wifi.baud(9600);
         baud(baudrate);
@@ -538,21 +541,21 @@
 
     attach_rx(false);
     tmr.start();
+    //INFO("send(%s) at %d", str, tmr.read_ms());
+    for (int i = 0; i < len; i++)
+        result = (putc(str[i]) == str[i]) ? result + 1 : result;    // count successful sends
     if (!ACK || !strcmp(ACK, "NO")) {
-        for (int i = 0; i < len; i++)
-            result = (putc(str[i]) == str[i]) ? result + 1 : result;
+        ;
     } else {
-        for (int i = 0; i < len; i++)
-            result = (putc(str[i]) == str[i]) ? result + 1 : result;
-
         while (1) {
             if (tmr.read_ms() > timeout) {
                 flushIn();
-                WARN("Can't find [%s] from [%s]", ACK, str);
+                WARN("Timeout seeking [%s] from [%s] at %d ms", ACK, str, tmr.read_ms());
                 attach_rx(true);
                 return -1;
             } else if (wifi.readable()) {
                 read = wifi.getc();
+                //INFO("  getc %2X  %d", read, tmr.read_ms());
                 if (tolower(read) != tolower(ACK[ackIndex]))
                     ackIndex = 0;
                 if (tolower(read) == tolower(ACK[ackIndex])) {
@@ -560,9 +563,11 @@
                     if (ackIndex == strlen(ACK))
                         break;
                 }
+            } else {
+                ; // INFO("  waiting %d", tmr.read_ms());
             }
         }
-        DBG(" found %s.", ACK);
+        //INFO(" found %s.", ACK);
         attach_rx(true);
         return result;
     }
@@ -583,13 +588,13 @@
                 if (wifi.readable()) {
                     read = wifi.getc();
                     // we drop \r and \n, but should we since it is for user code...
-                    if ( read != '\r' && read != '\n') {
-                        res[i++] = read;
-                    }
+                    //if ( read != '\r' && read != '\n') {
+                    res[i++] = read;
+                    //}
                 }
             }
         }
-        DBG("user str: {%s}", res);
+        //INFO("user str: {%s}", res);
     }
 
     flushIn();
@@ -601,7 +606,7 @@
 void Wifly::flushIn(int timeout_ms)
 {
     Timer tmr;
-#ifdef DEBUG
+#if 0 and defined(DEBUG)
     char chatter[500];
     int count = 0;
     int c;
@@ -613,7 +618,7 @@
     tmr.start();
     while (wifi.readable() || (tmr.read_ms() < timeout_ms)) {
         if (wifi.readable()) {
-#ifdef DEBUG
+#if 0 and defined(DEBUG)
             c = wifi.getc();
             if (count < sizeof(chatter)-1)  // guard overflow
                 chatter[count++] = c;
@@ -624,10 +629,10 @@
             tmr.start(); // start should not be necessary
         }
     }
-#ifdef DEBUG
+#if 0 and defined(DEBUG)
     chatter[count] = '\0';
     if (count)
-        DBG("Wifly::flushIn(%d) {%s}", count, chatter);
+        INFO("Wifly::flushIn(%d) {%s}", count, chatter);
 #endif
 }
 
@@ -646,29 +651,30 @@
     // change it back w/o a reset. So, we won't even permit those speeds.
     const int baudrates[] = {2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400}; //, 460800, 921600};
 #define BRCOUNT (sizeof(baudrates)/sizeof(baudrates[0]))
-    char cmd[20];       // sized for "set u i 460800\r" [15+1], plus margin [4]
+    char cmd[26];       // sized for "set u i 460800\r" [15+1], plus margin [4]
     int tryIndex = 0;
     bool res = false;
     int userIndex;
 
-    sprintf(cmd, "set u i %d\r", _targetBaud);
+    sprintf(cmd, "set uart instant %d\r", _targetBaud);
     // set u i # should cause it to exit command mode (manual 2.3.64),
     // but testing indicates that it does not.
     for (userIndex=0; userIndex < BRCOUNT; userIndex++) {
         if (_targetBaud == baudrates[userIndex]) {
             while (tryIndex <= BRCOUNT) {
-                DBG("baud() try: %d", tryIndex);
+                //INFO("baud() try: %d: %d", tryIndex, _targetBaud);
                 sendCommand(cmd); // shift Wifly to desired speed [it may not respond (see 2.3.64)]
-                // setCmdMode(false);  // see note above why this is disabled
+                flushIn(10);
+                //setCmdMode(false);  // see note above why this is disabled
                 wifi.baud(_targetBaud);     // shift the ARM uart to match
-                if (sendCommand("ver\r", "wifly", NULL, timeToRespond(4))) {  // use this to verify communications
+                if (sendCommand("ver\r", "wifly", NULL, 125)) {  // use this to verify communications
                     baudrate = _targetBaud;
                     res = true;
                     break;              // success
                 }
                 // keep trying baudrates between ARM and WiFly
                 if (tryIndex < BRCOUNT) {
-                    WARN(" baud() set to %d", baudrates[tryIndex]);
+                    //INFO(" baud() set to %d", baudrates[tryIndex]);
                     wifi.baud(baudrates[tryIndex]);
                 }
                 tryIndex++;
@@ -676,7 +682,7 @@
             break;  // if they selected a legitimate baud, try no others
         }
     }
-    DBG(" baud() result: %d", res);
+    //INFO(" baud() result: %d", res);
     return res;
 }
 
@@ -726,14 +732,17 @@
     if (p)
         *p = '\0';
     wiflyVersionString = (char *)malloc(strlen(logonText)+1);
-    if (wiflyVersionString)
+    if (wiflyVersionString) {
         strcpy(wiflyVersionString, logonText);
-    p = strstr(logonText, "Ver ");
+    }
+    p = strstr(logonText, "Ver ");          // "Ver 4.00" for ver <= 4.00
+    if (!p) p = strstr(logonText, "Ver: "); // "Ver: 4.40" new in ver 4.40
     if (p) {
-        p += 4;
+        while (*p && (*p < '0' || *p > '9'))
+            p++;
         swVersion = atof(p);
     }
-    INFO("swVersion: %3.2f, versionString: {%s}", swVersion, wiflyVersionString);
+    INFO("swVersion: %3.2f,\r\nverString: {%s}", swVersion, wiflyVersionString);
 }
 
 
--- a/Wifly/Wifly.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/Wifly/Wifly.h	Thu Nov 28 18:17:00 2013 +0000
@@ -28,6 +28,7 @@
 #define WIFLY_H
 
 #include "mbed.h"
+#include "RawSerial.h"
 #include "CBuffer.h"
 
 #define DEFAULT_WAIT_RESP_TIMEOUT 1000
@@ -96,7 +97,7 @@
     /**
     * Disconnect the wifly module from the access point
     *
-    * @ returns true if successful
+    * @return true if successful
     */
     bool disconnect();
 
@@ -105,7 +106,7 @@
     *
     * @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established)
     * @param port port
-    * @ returns true if successful
+    * @return true if successful
     */
     bool connect(const char * host, int port);
 
@@ -114,7 +115,7 @@
     * Set the protocol (UDP or TCP)
     *
     * @param p protocol
-    * @ returns true if successful
+    * @return true if successful
     */
     bool setProtocol(Protocol p);
 
@@ -125,6 +126,8 @@
     
     /**
     * Reboot the wifi module
+    *
+    * @return true if it could send the command, false otherwise
     */
     bool reboot();
 
@@ -145,7 +148,7 @@
     /**
     * Check if a tcp link is active
     *
-    * @returns true if successful
+    * @return true if successful
     */
     bool is_connected();
 
@@ -165,6 +168,7 @@
     * Write a character
     *
     * @param the character which will be written
+    * @return the character written
     */
     int putc(char c);
 
@@ -186,7 +190,7 @@
     /**
     * Close a tcp connection, and exit command mode.
     *
-    * @ returns true if successful
+    * @return true if successful
     */
     bool close();
 
@@ -213,14 +217,14 @@
     * @param 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)
     * @param timeout is the time in msec to wait for the acknowledge
     *
-    * @returns true if successful
+    * @return true if successful
     */
     bool sendCommand(const char * cmd, const char * ack = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT);
     
     /**
     * Return true if the module is using dhcp
     *
-    * @returns true if the module is using dhcp
+    * @return true if the module is using dhcp
     */
     bool isDHCP() {
         return state.dhcp;
@@ -232,7 +236,7 @@
     * @param host is a pointer to the host string to look up
     * @param ip contains the host IP in a string after the lookup.
     * @param sizeof_ip is the size of the buffer pointed to by ip
-    * @returns true if successful
+    * @return true if successful
     */
     bool gethostbyname(const char * host, char * ip);
 
@@ -252,8 +256,8 @@
     *
     * @param baudrate is the desired baudrate.
     *
-    * @returns true if it succeeded, which means that communications can continue, 
-    * @returns false if it failed to establish a communication link.
+    * @return true if it succeeded, which means that communications can continue, 
+    * @return false if it failed to establish a communication link.
     */
     bool baud(int baudrate);
 
@@ -271,7 +275,7 @@
     /**
     * Get the version information from the Wifly module.
     *
-    * @returns the version information as a string, or NULL
+    * @return the version information as a string, or NULL
     */
     char * getWiflyVersionString();
     
@@ -282,7 +286,7 @@
     * This extracts the basic version number (e.g. 2.38, 4.00)
     * as a float.
     *
-    * @returns the software version number as a float.
+    * @return the software version number as a float.
     */
     float getWiflyVersion();
 
@@ -305,7 +309,7 @@
     #ifdef MODSERIAL_H
     MODSERIAL wifi;
     #else
-    Serial wifi;
+    RawSerial wifi;
     #endif
     DigitalOut reset_pin;
     DigitalIn tcp_status;
@@ -348,7 +352,7 @@
     *
     * @param stringLen of the command to be sent, in characters.
     *
-    * @returns integer number of milliseconds (always rounded up a little)
+    * @return integer number of milliseconds (always rounded up a little)
     */
     int timeToRespond(int stringLen);
 
--- a/WiflyInterface.cpp	Sat Oct 12 23:38:43 2013 +0000
+++ b/WiflyInterface.cpp	Thu Nov 28 18:17:00 2013 +0000
@@ -1,70 +1,70 @@
-#include "WiflyInterface.h"
-
-WiflyInterface::WiflyInterface( PinName tx, PinName rx, PinName reset, PinName tcp_status,
-                                const char * ssid, const char * phrase, Security sec) :
-    Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec)
-{
-    ip_set = false;
-}
-
-int WiflyInterface::init()
-{
-    state.dhcp = true;
-    reset();
-    return 0;
-}
-
-int WiflyInterface::init(const char* ip, const char* mask, const char* gateway)
-{
-    state.dhcp = false;
-    this->ip = ip;
-    strcpy(ip_string, ip);
-    ip_set = true;
-    this->netmask = mask;
-    this->gateway = gateway;
-    reset();
-
-    return 0;
-}
-
-void WiflyInterface::setSecurity(const char * ssid, const char * phrase, Security sec)
-{
-    Wifly::SetSecurity(ssid, phrase, sec);
-}
-
-int WiflyInterface::connect()
-{
-    return join();
-}
-
-int WiflyInterface::disconnect()
-{
-    return Wifly::disconnect();
-}
-
-// typical response might be
-// 192.168.43.107\r
-// <4.00>
-char * WiflyInterface::getIPAddress()
-{
-    char * match = 0;
-    if (!ip_set) {
-        if (!sendCommand("get ip a\r", NULL, ip_string))
-            return NULL;
-        exit();
-        flush();
-        match = strstr(ip_string, "<");
-        if (match != NULL) {
-            *match = '\0';
-        }
-        if (strlen(ip_string) < 6) {
-            match = strstr(ip_string, ">");
-            if (match != NULL) {
-                int len = strlen(match + 1);
-                memcpy(ip_string, match + 1, len);
-            }
-        }
-        ip_set = true;
-    }
-    return ip_string;
+#include "WiflyInterface.h"
+
+WiflyInterface::WiflyInterface( PinName tx, PinName rx, PinName reset, PinName tcp_status,
+                                const char * ssid, const char * phrase, Security sec) :
+    Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec)
+{
+    ip_set = false;
+}
+
+int WiflyInterface::init()
+{
+    state.dhcp = true;
+    reset();
+    return 0;
+}
+
+int WiflyInterface::init(const char* ip, const char* mask, const char* gateway)
+{
+    state.dhcp = false;
+    this->ip = ip;
+    strcpy(ip_string, ip);
+    ip_set = true;
+    this->netmask = mask;
+    this->gateway = gateway;
+    reset();
+
+    return 0;
+}
+
+void WiflyInterface::setSecurity(const char * ssid, const char * phrase, Security sec)
+{
+    Wifly::SetSecurity(ssid, phrase, sec);
 }
+
+int WiflyInterface::connect()
+{
+    return join();
+}
+
+int WiflyInterface::disconnect()
+{
+    return Wifly::disconnect();
+}
+
+// typical response might be
+// \r192.168.43.107\r
+// <4.40>
+char * WiflyInterface::getIPAddress()
+{
+    char * match = ip_string;
+    if (!ip_set) {
+        if (!sendCommand("get ip a\r", NULL, ip_string))
+            return NULL;
+        exit();
+        flush();
+        // revised to find the IP string, following a small
+        // change where \r are permitted in the captured
+        // reply to a command.
+        while (*match && (*match < '0' || *match > '9'))
+            match++;
+        if (*match)
+            memcpy(ip_string, match, strlen(match));
+        match = ip_string;
+        while (strchr("0123456789.", *match))
+            match++;
+        *match = '\0';
+        ip_set = true;
+    }
+    return ip_string;
+}
--- a/WiflyInterface.h	Sat Oct 12 23:38:43 2013 +0000
+++ b/WiflyInterface.h	Thu Nov 28 18:17:00 2013 +0000
@@ -48,19 +48,19 @@
     * @note The optional ssid, phrase, and sec parameters may be deferred, or
     *       overridden prior to the connect().
     *
-    * \param tx mbed pin to use for tx line of Serial interface
-    * \param rx mbed pin to use for rx line of Serial interface
-    * \param reset reset pin of the wifi module ()
-    * \param tcp_status connection status pin of the wifi module (GPIO 6)
-    * \param ssid optional parameter which is the ssid of the network
-    * \param phrase optional parameter which is the WEP or WPA key/phrase
-    * \param sec optional security type (NONE[default], WEP_128 or WPA)
+    * @param tx mbed pin to use for tx line of Serial interface
+    * @param rx mbed pin to use for rx line of Serial interface
+    * @param reset reset pin of the wifi module ()
+    * @param tcp_status connection status pin of the wifi module (GPIO 6)
+    * @param ssid optional parameter which is the ssid of the network
+    * @param phrase optional parameter which is the WEP or WPA key/phrase
+    * @param sec optional security type (NONE[default], WEP_128 or WPA)
     */
     WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid = NULL, const char * phrase = NULL, Security sec = NONE);
 
     /** Initialize the interface with DHCP.
     * Initialize the interface and configure it to use DHCP (no connection at this point).
-    * \return 0 on success, a negative number on failure
+    * @return 0 on success, a negative number on failure
     */
     int init(); //With DHCP
 
@@ -69,10 +69,10 @@
     * Initialize the interface and configure it with the following static
     * configuration (no connection at this point).
     *
-    * \param ip the IP address to use
-    * \param mask the IP address mask
-    * \param gateway the gateway to use
-    * \return 0 on success, a negative number on failure
+    * @param ip the IP address to use
+    * @param mask the IP address mask
+    * @param gateway the gateway to use
+    * @return 0 on success, a negative number on failure
     */
     int init(const char* ip, const char* mask, const char* gateway);
 
@@ -83,27 +83,27 @@
     * points to be connected to. With this, the interface can be brought online far
     * enough to scan for available access points.
     *
-    * \param ssid optional parameter which is the ssid of the network
-    * \param phrase optional parameter which is the WEP or WPA key/phrase
-    * \param sec optional security type (NONE[default], WEP_128 or WPA)
+    * @param ssid optional parameter which is the ssid of the network
+    * @param phrase optional parameter which is the WEP or WPA key/phrase
+    * @param sec optional security type (NONE[default], WEP_128 or WPA)
     */
     void setSecurity(const char * ssid = NULL, const char * phrase = NULL, Security sec = NONE);
 
     /** Connect
     * Bring the interface up, start DHCP if needed.
-    * \return 0 on success, a negative number on failure
+    * @return 0 on success, a negative number on failure
     */
     int connect();
 
     /** Disconnect
     * Bring the interface down
-    * \return 0 on success, a negative number on failure
+    * @return 0 on success, a negative number on failure
     */
     int disconnect();
 
     /** Get IP address
     *
-    * @ returns ip address
+    * @return ip address
     */
     char* getIPAddress();