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
}
Committer:
WiredHome
Date:
Sat Apr 19 16:36:15 2014 +0000
Revision:
67:557ea7ad15c1
Parent:
64:6202428f37ec
Child:
68:d9a3920cc407
Revise the Wifly interface so that recovery from a lost connection is possible. See the "in_connected()" method for an example.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:fb4494783863 1 /* Copyright (C) 2012 mbed.org, MIT License
samux 1:fb4494783863 2 *
samux 1:fb4494783863 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 1:fb4494783863 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
samux 1:fb4494783863 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
samux 1:fb4494783863 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
samux 1:fb4494783863 7 * furnished to do so, subject to the following conditions:
samux 1:fb4494783863 8 *
samux 1:fb4494783863 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 1:fb4494783863 10 * substantial portions of the Software.
samux 1:fb4494783863 11 *
samux 1:fb4494783863 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 1:fb4494783863 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 1:fb4494783863 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 1:fb4494783863 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 1:fb4494783863 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 1:fb4494783863 17 *
samux 1:fb4494783863 18 * @section DESCRIPTION
samux 1:fb4494783863 19 *
samux 1:fb4494783863 20 * Wifly RN131-C, wifi module
samux 1:fb4494783863 21 *
samux 1:fb4494783863 22 * Datasheet:
samux 1:fb4494783863 23 *
samux 1:fb4494783863 24 * http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/WiFi/WiFly-RN-UM.pdf
samux 1:fb4494783863 25 */
samux 1:fb4494783863 26
samux 1:fb4494783863 27 #ifndef WIFLY_H
samux 1:fb4494783863 28 #define WIFLY_H
samux 1:fb4494783863 29
samux 1:fb4494783863 30 #include "mbed.h"
WiredHome 51:a4831b1cb9a4 31 #include "RawSerial.h"
samux 1:fb4494783863 32 #include "CBuffer.h"
samux 1:fb4494783863 33
WiredHome 58:f49aab8072ec 34 #define DEFAULT_WAIT_RESP_TIMEOUT 2500
samux 1:fb4494783863 35
WiredHome 30:f500260463b7 36 enum Security { // See Wifly user manual Table 2-13.
WiredHome 30:f500260463b7 37 NONE = 0,
WiredHome 30:f500260463b7 38 WEP_128 = 1,
WiredHome 30:f500260463b7 39 WPA1 = 2,
WiredHome 30:f500260463b7 40 WPA_MIXED = 3,
WiredHome 30:f500260463b7 41 WPA = 3, // maintained for backward compatibility
WiredHome 30:f500260463b7 42 WPA2_PSK = 4,
WiredHome 30:f500260463b7 43 ADHOC = 6,
WiredHome 30:f500260463b7 44 WPE_64 = 8,
WiredHome 30:f500260463b7 45 WEP_64 = 8 // probably what the last one should have been
samux 1:fb4494783863 46 };
samux 1:fb4494783863 47
samux 1:fb4494783863 48 enum Protocol {
samux 1:fb4494783863 49 UDP = (1 << 0),
samux 1:fb4494783863 50 TCP = (1 << 1)
samux 1:fb4494783863 51 };
samux 1:fb4494783863 52
WiredHome 15:121f473dae3f 53 /** the Wifly object
WiredHome 15:121f473dae3f 54 *
WiredHome 15:121f473dae3f 55 * This object controls the Wifly module.
WiredHome 15:121f473dae3f 56 */
samux 1:fb4494783863 57 class Wifly
samux 1:fb4494783863 58 {
samux 1:fb4494783863 59
samux 1:fb4494783863 60 public:
WiredHome 15:121f473dae3f 61 /**
samux 1:fb4494783863 62 * Constructor
samux 1:fb4494783863 63 *
samux 1:fb4494783863 64 * @param tx mbed pin to use for tx line of Serial interface
samux 1:fb4494783863 65 * @param rx mbed pin to use for rx line of Serial interface
samux 1:fb4494783863 66 * @param reset reset pin of the wifi module ()
samux 1:fb4494783863 67 * @param tcp_status connection status pin of the wifi module (GPIO 6)
samux 1:fb4494783863 68 * @param ssid ssid of the network
samux 1:fb4494783863 69 * @param phrase WEP or WPA key
WiredHome 30:f500260463b7 70 * @param sec Security type (NONE, WEP_128, WPA1, WPA | WPA_MIXED, WPA2_PSK, WEP_64 )
samux 1:fb4494783863 71 */
WiredHome 25:a740eb74a86a 72 Wifly(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec);
samux 1:fb4494783863 73
WiredHome 15:121f473dae3f 74 /**
WiredHome 25:a740eb74a86a 75 * Destructor to clean up
WiredHome 25:a740eb74a86a 76 */
WiredHome 25:a740eb74a86a 77 ~Wifly();
WiredHome 25:a740eb74a86a 78
WiredHome 45:21b7bbaad62b 79 /** Optional means to set/reset the security
WiredHome 45:21b7bbaad62b 80 *
WiredHome 45:21b7bbaad62b 81 * If join() has not been called, then you can revise the security parameters
WiredHome 45:21b7bbaad62b 82 * from those in the constructor.
WiredHome 45:21b7bbaad62b 83 *
WiredHome 45:21b7bbaad62b 84 * @param ssid ssid of the network
WiredHome 45:21b7bbaad62b 85 * @param phrase WEP or WPA key
WiredHome 45:21b7bbaad62b 86 * @param sec Security type (NONE, WEP_128, WPA1, WPA | WPA_MIXED, WPA2_PSK, WEP_64 )
WiredHome 45:21b7bbaad62b 87 */
WiredHome 45:21b7bbaad62b 88 void SetSecurity(const char * ssid, const char * phrase, Security sec);
WiredHome 45:21b7bbaad62b 89
WiredHome 25:a740eb74a86a 90 /**
WiredHome 67:557ea7ad15c1 91 * Configure the wifi module with the parameters contained in the constructor.
WiredHome 67:557ea7ad15c1 92 *
WiredHome 67:557ea7ad15c1 93 * @return true if successful, false otherwise.
WiredHome 67:557ea7ad15c1 94 */
WiredHome 67:557ea7ad15c1 95 bool configure();
WiredHome 67:557ea7ad15c1 96
WiredHome 67:557ea7ad15c1 97 /**
samux 1:fb4494783863 98 * Connect the wifi module to the ssid contained in the constructor.
samux 1:fb4494783863 99 *
samux 1:fb4494783863 100 * @return true if connected, false otherwise
samux 1:fb4494783863 101 */
samux 1:fb4494783863 102 bool join();
samux 1:fb4494783863 103
WiredHome 15:121f473dae3f 104 /**
samux 1:fb4494783863 105 * Disconnect the wifly module from the access point
samux 1:fb4494783863 106 *
WiredHome 51:a4831b1cb9a4 107 * @return true if successful
samux 1:fb4494783863 108 */
samux 1:fb4494783863 109 bool disconnect();
samux 1:fb4494783863 110
WiredHome 15:121f473dae3f 111 /**
samux 1:fb4494783863 112 * Open a tcp connection with the specified host on the specified port
samux 1:fb4494783863 113 *
samux 1:fb4494783863 114 * @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established)
samux 1:fb4494783863 115 * @param port port
WiredHome 51:a4831b1cb9a4 116 * @return true if successful
samux 1:fb4494783863 117 */
samux 1:fb4494783863 118 bool connect(const char * host, int port);
samux 1:fb4494783863 119
samux 1:fb4494783863 120
WiredHome 15:121f473dae3f 121 /**
samux 1:fb4494783863 122 * Set the protocol (UDP or TCP)
samux 1:fb4494783863 123 *
samux 1:fb4494783863 124 * @param p protocol
WiredHome 51:a4831b1cb9a4 125 * @return true if successful
samux 1:fb4494783863 126 */
samux 1:fb4494783863 127 bool setProtocol(Protocol p);
samux 1:fb4494783863 128
WiredHome 15:121f473dae3f 129 /**
samux 1:fb4494783863 130 * Reset the wifi module
samux 1:fb4494783863 131 */
samux 1:fb4494783863 132 void reset();
samux 3:9aa05e19c62e 133
WiredHome 15:121f473dae3f 134 /**
samux 3:9aa05e19c62e 135 * Reboot the wifi module
WiredHome 51:a4831b1cb9a4 136 *
WiredHome 51:a4831b1cb9a4 137 * @return true if it could send the command, false otherwise
samux 3:9aa05e19c62e 138 */
samux 3:9aa05e19c62e 139 bool reboot();
samux 1:fb4494783863 140
WiredHome 15:121f473dae3f 141 /**
samux 1:fb4494783863 142 * Check if characters are available
samux 1:fb4494783863 143 *
samux 1:fb4494783863 144 * @return number of available characters
samux 1:fb4494783863 145 */
samux 1:fb4494783863 146 int readable();
samux 1:fb4494783863 147
WiredHome 15:121f473dae3f 148 /**
samux 1:fb4494783863 149 * Check if characters are available
samux 1:fb4494783863 150 *
samux 1:fb4494783863 151 * @return number of available characters
samux 1:fb4494783863 152 */
samux 1:fb4494783863 153 int writeable();
samux 1:fb4494783863 154
WiredHome 15:121f473dae3f 155 /**
WiredHome 64:6202428f37ec 156 * Check if associated with an access point (was checking if tcp link is active)
samux 1:fb4494783863 157 *
WiredHome 67:557ea7ad15c1 158 * Follow this example to improve the automatic recovery
WiredHome 67:557ea7ad15c1 159 * after a lost association.
WiredHome 67:557ea7ad15c1 160 *
WiredHome 67:557ea7ad15c1 161 * @code
WiredHome 67:557ea7ad15c1 162 * WiflyInterface eth(p28, p27, p23, p24, "ssid", "pass", WPA);
WiredHome 67:557ea7ad15c1 163 *
WiredHome 67:557ea7ad15c1 164 * if (0 == eth.init()) {
WiredHome 67:557ea7ad15c1 165 * eth.baud(230400); // speed up the interface
WiredHome 67:557ea7ad15c1 166 * do {
WiredHome 67:557ea7ad15c1 167 * if (0 == eth.connect()) {
WiredHome 67:557ea7ad15c1 168 * linkup = true; // led indicator
WiredHome 67:557ea7ad15c1 169 * while (eth.is_connected()) {
WiredHome 67:557ea7ad15c1 170 * wait_ms(1000);
WiredHome 67:557ea7ad15c1 171 * }
WiredHome 67:557ea7ad15c1 172 * linkup = false; // led indicator
WiredHome 67:557ea7ad15c1 173 * eth.disconnect();
WiredHome 67:557ea7ad15c1 174 * wait_ms(1000);
WiredHome 67:557ea7ad15c1 175 * }
WiredHome 67:557ea7ad15c1 176 * } while (1);
WiredHome 67:557ea7ad15c1 177 * } else {
WiredHome 67:557ea7ad15c1 178 * wait(5); // ... failed to initialize, rebooting...
WiredHome 67:557ea7ad15c1 179 * mbed_reset();
WiredHome 67:557ea7ad15c1 180 * }
WiredHome 67:557ea7ad15c1 181 * @endcode
WiredHome 67:557ea7ad15c1 182 *
WiredHome 51:a4831b1cb9a4 183 * @return true if successful
samux 1:fb4494783863 184 */
samux 1:fb4494783863 185 bool is_connected();
samux 1:fb4494783863 186
WiredHome 15:121f473dae3f 187 /**
samux 1:fb4494783863 188 * Read a character
samux 1:fb4494783863 189 *
samux 1:fb4494783863 190 * @return the character read
samux 1:fb4494783863 191 */
samux 1:fb4494783863 192 char getc();
samux 1:fb4494783863 193
WiredHome 15:121f473dae3f 194 /**
samux 1:fb4494783863 195 * Flush the buffer
samux 1:fb4494783863 196 */
samux 1:fb4494783863 197 void flush();
samux 1:fb4494783863 198
WiredHome 15:121f473dae3f 199 /**
samux 1:fb4494783863 200 * Write a character
samux 1:fb4494783863 201 *
samux 1:fb4494783863 202 * @param the character which will be written
WiredHome 51:a4831b1cb9a4 203 * @return the character written
samux 1:fb4494783863 204 */
samux 1:fb4494783863 205 int putc(char c);
samux 1:fb4494783863 206
samux 1:fb4494783863 207
WiredHome 15:121f473dae3f 208 /**
samux 1:fb4494783863 209 * To enter in command mode (we can configure the module)
samux 1:fb4494783863 210 *
samux 1:fb4494783863 211 * @return true if successful, false otherwise
samux 1:fb4494783863 212 */
samux 1:fb4494783863 213 bool cmdMode();
samux 1:fb4494783863 214
WiredHome 15:121f473dae3f 215 /**
samux 1:fb4494783863 216 * To exit the command mode
samux 1:fb4494783863 217 *
samux 1:fb4494783863 218 * @return true if successful, false otherwise
samux 1:fb4494783863 219 */
samux 1:fb4494783863 220 bool exit();
samux 1:fb4494783863 221
WiredHome 15:121f473dae3f 222 /**
WiredHome 34:52e4eec8b790 223 * Close a tcp connection, and exit command mode.
samux 1:fb4494783863 224 *
WiredHome 51:a4831b1cb9a4 225 * @return true if successful
samux 1:fb4494783863 226 */
samux 1:fb4494783863 227 bool close();
samux 1:fb4494783863 228
WiredHome 15:121f473dae3f 229 /**
samux 1:fb4494783863 230 * 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.
samux 1:fb4494783863 231 * Useful to send a command to the module and wait a response.
samux 1:fb4494783863 232 *
samux 1:fb4494783863 233 *
samux 1:fb4494783863 234 * @param str string to be sent
samux 1:fb4494783863 235 * @param len string length
samux 1:fb4494783863 236 * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
samux 1:fb4494783863 237 * @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)
WiredHome 15:121f473dae3f 238 * @param timeout is the time in msec to wait for the acknowledge
samux 1:fb4494783863 239 *
samux 1:fb4494783863 240 * @return true if ACK has been found in the response from the wifi module. False otherwise or if there is no response in 5s.
samux 1:fb4494783863 241 */
samux 1:fb4494783863 242 int send(const char * str, int len, const char * ACK = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT);
samux 1:fb4494783863 243
WiredHome 15:121f473dae3f 244 /**
WiredHome 58:f49aab8072ec 245 * Send a command to the wify module. Check if the module is in command mode. If not enter in command mode
samux 1:fb4494783863 246 *
samux 1:fb4494783863 247 * @param str string to be sent
samux 1:fb4494783863 248 * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
samux 1:fb4494783863 249 * @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)
WiredHome 15:121f473dae3f 250 * @param timeout is the time in msec to wait for the acknowledge
samux 1:fb4494783863 251 *
WiredHome 51:a4831b1cb9a4 252 * @return true if successful
samux 1:fb4494783863 253 */
samux 1:fb4494783863 254 bool sendCommand(const char * cmd, const char * ack = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT);
samux 4:0bcec6272784 255
WiredHome 15:121f473dae3f 256 /**
samux 4:0bcec6272784 257 * Return true if the module is using dhcp
samux 4:0bcec6272784 258 *
WiredHome 51:a4831b1cb9a4 259 * @return true if the module is using dhcp
samux 4:0bcec6272784 260 */
samux 4:0bcec6272784 261 bool isDHCP() {
samux 4:0bcec6272784 262 return state.dhcp;
samux 4:0bcec6272784 263 }
samux 1:fb4494783863 264
WiredHome 15:121f473dae3f 265 /**
WiredHome 15:121f473dae3f 266 * gets the host ip address
WiredHome 15:121f473dae3f 267 *
WiredHome 15:121f473dae3f 268 * @param host is a pointer to the host string to look up
WiredHome 15:121f473dae3f 269 * @param ip contains the host IP in a string after the lookup.
WiredHome 15:121f473dae3f 270 * @param sizeof_ip is the size of the buffer pointed to by ip
WiredHome 51:a4831b1cb9a4 271 * @return true if successful
WiredHome 15:121f473dae3f 272 */
samux 1:fb4494783863 273 bool gethostbyname(const char * host, char * ip);
samux 1:fb4494783863 274
WiredHome 20:906b0f951bc3 275 /**
WiredHome 20:906b0f951bc3 276 * Set the baud rate between the ARM and the WiFly.
WiredHome 20:906b0f951bc3 277 *
WiredHome 20:906b0f951bc3 278 * This will set the WiFly module baud rate first and then
WiredHome 20:906b0f951bc3 279 * set the ARM interface to match it. If it cannot get the proper
WiredHome 20:906b0f951bc3 280 * acknowledge response, it will go on a hunt through the range
WiredHome 20:906b0f951bc3 281 * of standard baud rates.
WiredHome 20:906b0f951bc3 282 *
WiredHome 20:906b0f951bc3 283 * @note Baud rate must be one of 2400, 4800, 9600, 19200, 38400, 57600,
WiredHome 20:906b0f951bc3 284 * 115200, 230400, 460800, or 921600. (See Wifly manual 2.3.64)
WiredHome 20:906b0f951bc3 285 * @note Baud rate of 230400 has been seen to be marginal w/o flow control.
WiredHome 20:906b0f951bc3 286 * @note Setting a baud rate to a 460800 or above may be unrecoverable
WiredHome 20:906b0f951bc3 287 * without resetting the Wifly module.
WiredHome 20:906b0f951bc3 288 *
WiredHome 20:906b0f951bc3 289 * @param baudrate is the desired baudrate.
WiredHome 20:906b0f951bc3 290 *
WiredHome 51:a4831b1cb9a4 291 * @return true if it succeeded, which means that communications can continue,
WiredHome 51:a4831b1cb9a4 292 * @return false if it failed to establish a communication link.
WiredHome 20:906b0f951bc3 293 */
WiredHome 20:906b0f951bc3 294 bool baud(int baudrate);
WiredHome 20:906b0f951bc3 295
WiredHome 25:a740eb74a86a 296
WiredHome 25:a740eb74a86a 297 /**
WiredHome 25:a740eb74a86a 298 * Sets the connection state.
WiredHome 25:a740eb74a86a 299 *
WiredHome 25:a740eb74a86a 300 * Typically used by external apps that detect an incoming connection.
WiredHome 25:a740eb74a86a 301 *
WiredHome 25:a740eb74a86a 302 * @param state sets the connection state to true or false
WiredHome 25:a740eb74a86a 303 */
WiredHome 25:a740eb74a86a 304 void setConnectionState(bool state);
WiredHome 25:a740eb74a86a 305
WiredHome 26:78a1a09afdc9 306
WiredHome 25:a740eb74a86a 307 /**
WiredHome 25:a740eb74a86a 308 * Get the version information from the Wifly module.
WiredHome 25:a740eb74a86a 309 *
WiredHome 51:a4831b1cb9a4 310 * @return the version information as a string, or NULL
WiredHome 25:a740eb74a86a 311 */
WiredHome 25:a740eb74a86a 312 char * getWiflyVersionString();
WiredHome 25:a740eb74a86a 313
WiredHome 26:78a1a09afdc9 314
WiredHome 25:a740eb74a86a 315 /**
WiredHome 25:a740eb74a86a 316 * Get the software version from the Wifly module.
WiredHome 25:a740eb74a86a 317 *
WiredHome 25:a740eb74a86a 318 * This extracts the basic version number (e.g. 2.38, 4.00)
WiredHome 25:a740eb74a86a 319 * as a float.
WiredHome 25:a740eb74a86a 320 *
WiredHome 51:a4831b1cb9a4 321 * @return the software version number as a float.
WiredHome 25:a740eb74a86a 322 */
WiredHome 25:a740eb74a86a 323 float getWiflyVersion();
WiredHome 25:a740eb74a86a 324
WiredHome 58:f49aab8072ec 325 /**
WiredHome 58:f49aab8072ec 326 * Update the software in the Wifly module.
WiredHome 58:f49aab8072ec 327 *
WiredHome 58:f49aab8072ec 328 * This attempts to connect to the microchip site, download
WiredHome 58:f49aab8072ec 329 * a software update, install it as the primary image, and
WiredHome 58:f49aab8072ec 330 * reboot to activate that image. It is compile-time defined
WiredHome 58:f49aab8072ec 331 * to try for 30 seconds.
WiredHome 58:f49aab8072ec 332 *
WiredHome 58:f49aab8072ec 333 * @return true if success or false for failure.
WiredHome 58:f49aab8072ec 334 */
WiredHome 58:f49aab8072ec 335 bool SWUpdateWifly();
WiredHome 58:f49aab8072ec 336
WiredHome 26:78a1a09afdc9 337 /**
WiredHome 26:78a1a09afdc9 338 * determine if the module is in command mode
WiredHome 26:78a1a09afdc9 339 *
WiredHome 26:78a1a09afdc9 340 * @return true if in command mode, false otherwise
WiredHome 26:78a1a09afdc9 341 */
WiredHome 26:78a1a09afdc9 342 bool isCmdMode() {
WiredHome 26:78a1a09afdc9 343 return state.cmd_mode;
WiredHome 26:78a1a09afdc9 344 }
WiredHome 26:78a1a09afdc9 345
samux 1:fb4494783863 346 static Wifly * getInstance() {
samux 1:fb4494783863 347 return inst;
samux 1:fb4494783863 348 };
samux 1:fb4494783863 349
samux 1:fb4494783863 350 protected:
WiredHome 51:a4831b1cb9a4 351 RawSerial wifi;
samux 1:fb4494783863 352 DigitalOut reset_pin;
samux 1:fb4494783863 353 DigitalIn tcp_status;
WiredHome 20:906b0f951bc3 354 int baudrate;
WiredHome 24:5012a535b1d5 355 char * phrase;
WiredHome 24:5012a535b1d5 356 char * ssid;
WiredHome 25:a740eb74a86a 357 char * wiflyVersionString;
WiredHome 25:a740eb74a86a 358 float swVersion;
samux 1:fb4494783863 359 const char * ip;
samux 1:fb4494783863 360 const char * netmask;
samux 1:fb4494783863 361 const char * gateway;
samux 1:fb4494783863 362 CircBuffer<char> buf_wifly;
samux 1:fb4494783863 363
samux 1:fb4494783863 364 static Wifly * inst;
samux 1:fb4494783863 365
samux 1:fb4494783863 366 void attach_rx(bool null);
samux 1:fb4494783863 367 void handler_rx(void);
WiredHome 29:49876a8c445b 368 void flushIn(int timeout_ms = -1);
WiredHome 64:6202428f37ec 369 uint16_t hextoi(char * p);
samux 1:fb4494783863 370
samux 1:fb4494783863 371 typedef struct STATE {
samux 1:fb4494783863 372 bool associated;
samux 1:fb4494783863 373 bool tcp;
samux 1:fb4494783863 374 bool dhcp;
samux 1:fb4494783863 375 Security sec;
samux 1:fb4494783863 376 Protocol proto;
samux 1:fb4494783863 377 bool cmd_mode;
samux 1:fb4494783863 378 } State;
samux 1:fb4494783863 379
samux 1:fb4494783863 380 State state;
samux 1:fb4494783863 381 char * getStringSecurity();
WiredHome 20:906b0f951bc3 382
WiredHome 24:5012a535b1d5 383 /**
WiredHome 24:5012a535b1d5 384 * Allocate space for the parameter (ssid or passphrase)
WiredHome 24:5012a535b1d5 385 * and then fix it (change ' ' to '$').
WiredHome 24:5012a535b1d5 386 *
WiredHome 24:5012a535b1d5 387 * @param dst is a reference to the private member pointer.
WiredHome 24:5012a535b1d5 388 * @src is a pointer to a passed in string.
WiredHome 24:5012a535b1d5 389 */
WiredHome 24:5012a535b1d5 390 void FixPhrase(char ** dst, const char * src);
WiredHome 24:5012a535b1d5 391
WiredHome 25:a740eb74a86a 392 /**
WiredHome 25:a740eb74a86a 393 * Gather the Wifly module version information for later queries
WiredHome 25:a740eb74a86a 394 */
WiredHome 25:a740eb74a86a 395 void GatherLogonInfo();
WiredHome 25:a740eb74a86a 396
samux 1:fb4494783863 397 };
samux 1:fb4494783863 398
samux 1:fb4494783863 399 #endif