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:
Sun Aug 04 21:30:51 2013 +0000
Revision:
29:49876a8c445b
Parent:
28:b7c1182aed28
Child:
30:f500260463b7
Changes focused on connection reliability. A number of small changes to debug macros, while discovering that something kicks wifly out of command mode. So, the cmdMode() API forces a check. This seems to be a huge improvement.

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
samux 1:fb4494783863 19 #include "mbed.h"
samux 1:fb4494783863 20 #include "Wifly.h"
samux 1:fb4494783863 21 #include <string>
samux 1:fb4494783863 22 #include <algorithm>
samux 1:fb4494783863 23
WiredHome 25:a740eb74a86a 24 // Defined to disable remote configuration via telnet which increases security of this device.
WiredHome 25:a740eb74a86a 25 #define INCREASE_SECURITY
WiredHome 25:a740eb74a86a 26
WiredHome 26:78a1a09afdc9 27 //#define DEBUG //Debug is disabled by default
WiredHome 20:906b0f951bc3 28
WiredHome 20:906b0f951bc3 29 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 20:906b0f951bc3 30 #define DBG(x, ...) std::printf("[DBG Wifly%4d] "x"\r\n", __LINE__, ##__VA_ARGS__);
WiredHome 20:906b0f951bc3 31 #define WARN(x, ...) std::printf("[WRN Wifly%4d] "x"\r\n", __LINE__, ##__VA_ARGS__);
WiredHome 20:906b0f951bc3 32 #define ERR(x, ...) std::printf("[ERR Wifly%4d] "x"\r\n", __LINE__, ##__VA_ARGS__);
WiredHome 20:906b0f951bc3 33 #define INFO(x, ...) std::printf("[INF Wifly%4d] "x"\r\n", __LINE__, ##__VA_ARGS__);
samux 1:fb4494783863 34 #else
samux 1:fb4494783863 35 #define DBG(x, ...)
samux 1:fb4494783863 36 #define WARN(x, ...)
samux 1:fb4494783863 37 #define ERR(x, ...)
WiredHome 20:906b0f951bc3 38 #define INFO(x, ...)
samux 1:fb4494783863 39 #endif
samux 1:fb4494783863 40
samux 1:fb4494783863 41 #define MAX_TRY_JOIN 3
samux 1:fb4494783863 42
samux 1:fb4494783863 43 Wifly * Wifly::inst;
samux 1:fb4494783863 44
samux 1:fb4494783863 45 Wifly::Wifly( PinName tx, PinName rx, PinName _reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec):
WiredHome 20:906b0f951bc3 46 wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), baudrate(9600), buf_wifly(256)
samux 1:fb4494783863 47 {
samux 1:fb4494783863 48 memset(&state, 0, sizeof(state));
samux 1:fb4494783863 49 state.sec = sec;
samux 1:fb4494783863 50
WiredHome 24:5012a535b1d5 51 FixPhrase(&this->ssid, ssid);
WiredHome 24:5012a535b1d5 52 FixPhrase(&this->phrase, phrase);
samux 1:fb4494783863 53
samux 1:fb4494783863 54 inst = this;
samux 1:fb4494783863 55 attach_rx(false);
samux 1:fb4494783863 56 state.cmd_mode = false;
WiredHome 25:a740eb74a86a 57 wiflyVersionString = NULL;
samux 1:fb4494783863 58 }
samux 1:fb4494783863 59
WiredHome 25:a740eb74a86a 60
WiredHome 25:a740eb74a86a 61 Wifly::~Wifly()
WiredHome 25:a740eb74a86a 62 {
WiredHome 25:a740eb74a86a 63 if (ssid) {
WiredHome 25:a740eb74a86a 64 free(ssid);
WiredHome 25:a740eb74a86a 65 ssid = NULL;
WiredHome 25:a740eb74a86a 66 }
WiredHome 25:a740eb74a86a 67 if (phrase) {
WiredHome 25:a740eb74a86a 68 free(phrase);
WiredHome 25:a740eb74a86a 69 phrase = NULL;
WiredHome 25:a740eb74a86a 70 }
WiredHome 25:a740eb74a86a 71 if (wiflyVersionString) {
WiredHome 25:a740eb74a86a 72 free(wiflyVersionString);
WiredHome 25:a740eb74a86a 73 wiflyVersionString = NULL;
WiredHome 25:a740eb74a86a 74 }
WiredHome 25:a740eb74a86a 75 }
WiredHome 25:a740eb74a86a 76
WiredHome 25:a740eb74a86a 77
samux 1:fb4494783863 78 bool Wifly::join()
samux 1:fb4494783863 79 {
samux 1:fb4494783863 80 char cmd[20];
samux 1:fb4494783863 81
samux 1:fb4494783863 82 for (int i= 0; i < MAX_TRY_JOIN; i++) {
samux 2:8e54830d0df7 83
samux 2:8e54830d0df7 84 // no auto join
samux 2:8e54830d0df7 85 if (!sendCommand("set w j 0\r", "AOK"))
samux 2:8e54830d0df7 86 continue;
samux 2:8e54830d0df7 87
WiredHome 27:8509ec4a0a0a 88 // no echo
samux 2:8e54830d0df7 89 if (!sendCommand("set u m 1\r", "AOK"))
samux 2:8e54830d0df7 90 continue;
samux 2:8e54830d0df7 91
WiredHome 27:8509ec4a0a0a 92 // set comm time to flush (ms)
samux 4:0bcec6272784 93 if (!sendCommand("set c t 30\r", "AOK"))
samux 1:fb4494783863 94 continue;
samux 1:fb4494783863 95
WiredHome 27:8509ec4a0a0a 96 // set comm size to auto-send
WiredHome 27:8509ec4a0a0a 97 if (!sendCommand("set c s 1420\r", "AOK"))
samux 1:fb4494783863 98 continue;
samux 1:fb4494783863 99
WiredHome 29:49876a8c445b 100 // set comm idle time to auto-close (sec)
WiredHome 29:49876a8c445b 101 //if (!sendCommand("set c i 5\r", "AOK"))
WiredHome 29:49876a8c445b 102 // continue;
WiredHome 29:49876a8c445b 103
samux 1:fb4494783863 104 // red led on when tcp connection active
samux 1:fb4494783863 105 if (!sendCommand("set s i 0x40\r", "AOK"))
samux 1:fb4494783863 106 continue;
samux 1:fb4494783863 107
WiredHome 27:8509ec4a0a0a 108 // no hello string sent to the tcp client
samux 1:fb4494783863 109 if (!sendCommand("set c r 0\r", "AOK"))
samux 1:fb4494783863 110 continue;
samux 1:fb4494783863 111
samux 1:fb4494783863 112 // tcp protocol
samux 1:fb4494783863 113 if (!sendCommand("set i p 2\r", "AOK"))
samux 1:fb4494783863 114 continue;
samux 1:fb4494783863 115
WiredHome 27:8509ec4a0a0a 116 // tcp retry (retry enabled, Nagle alg, retain link)
samux 1:fb4494783863 117 if (!sendCommand("set i f 0x7\r", "AOK"))
samux 1:fb4494783863 118 continue;
WiredHome 20:906b0f951bc3 119
WiredHome 25:a740eb74a86a 120 #ifdef INCREASE_SECURITY
WiredHome 25:a740eb74a86a 121 // tcp-mode 0x10 = disable remote configuration
WiredHome 25:a740eb74a86a 122 // only in SW 2.27 and higher (see 2.3.39)
WiredHome 25:a740eb74a86a 123 if ((swVersion >= 2.27) && (!sendCommand("set i t 0x10\r", "AOK")))
WiredHome 25:a740eb74a86a 124 continue;
WiredHome 25:a740eb74a86a 125 #endif
WiredHome 25:a740eb74a86a 126
samux 2:8e54830d0df7 127 // set dns server
samux 2:8e54830d0df7 128 if (!sendCommand("set d n rn.microchip.com\r", "AOK"))
samux 1:fb4494783863 129 continue;
samux 1:fb4494783863 130
samux 1:fb4494783863 131 //dhcp
samux 1:fb4494783863 132 sprintf(cmd, "set i d %d\r", (state.dhcp) ? 1 : 0);
samux 1:fb4494783863 133 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 134 continue;
samux 1:fb4494783863 135
samux 1:fb4494783863 136 // ssid
samux 1:fb4494783863 137 sprintf(cmd, "set w s %s\r", ssid);
samux 1:fb4494783863 138 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 139 continue;
samux 1:fb4494783863 140
samux 1:fb4494783863 141 //auth
samux 1:fb4494783863 142 sprintf(cmd, "set w a %d\r", state.sec);
samux 1:fb4494783863 143 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 144 continue;
samux 1:fb4494783863 145
samux 1:fb4494783863 146 // if no dhcp, set ip, netmask and gateway
samux 1:fb4494783863 147 if (!state.dhcp) {
WiredHome 20:906b0f951bc3 148 DBG("not dhcp");
samux 1:fb4494783863 149
samux 1:fb4494783863 150 sprintf(cmd, "set i a %s\r\n", ip);
samux 1:fb4494783863 151 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 152 continue;
samux 1:fb4494783863 153
samux 1:fb4494783863 154 sprintf(cmd, "set i n %s\r", netmask);
samux 1:fb4494783863 155 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 156 continue;
samux 1:fb4494783863 157
samux 1:fb4494783863 158 sprintf(cmd, "set i g %s\r", gateway);
samux 1:fb4494783863 159 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 160 continue;
samux 1:fb4494783863 161 }
samux 1:fb4494783863 162
samux 1:fb4494783863 163 //key step
samux 1:fb4494783863 164 if (state.sec != NONE) {
samux 1:fb4494783863 165 if (state.sec == WPA)
samux 1:fb4494783863 166 sprintf(cmd, "set w p %s\r", phrase);
samux 1:fb4494783863 167 else if (state.sec == WEP_128)
samux 1:fb4494783863 168 sprintf(cmd, "set w k %s\r", phrase);
samux 1:fb4494783863 169
samux 1:fb4494783863 170 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 171 continue;
samux 1:fb4494783863 172 }
samux 1:fb4494783863 173
samux 2:8e54830d0df7 174 //join the network (10s timeout)
samux 1:fb4494783863 175 if (state.dhcp) {
samux 2:8e54830d0df7 176 if (!sendCommand("join\r", "DHCP=ON", NULL, 10000))
samux 2:8e54830d0df7 177 continue;
samux 2:8e54830d0df7 178 } else {
samux 2:8e54830d0df7 179 if (!sendCommand("join\r", "Associated", NULL, 10000))
samux 1:fb4494783863 180 continue;
samux 1:fb4494783863 181 }
samux 1:fb4494783863 182
samux 2:8e54830d0df7 183 if (!sendCommand("save\r", "Stor"))
samux 2:8e54830d0df7 184 continue;
samux 2:8e54830d0df7 185
samux 1:fb4494783863 186 exit();
samux 1:fb4494783863 187
samux 1:fb4494783863 188 state.associated = true;
samux 1:fb4494783863 189 INFO("\r\nssid: %s\r\nphrase: %s\r\nsecurity: %s\r\n\r\n", this->ssid, this->phrase, getStringSecurity());
samux 1:fb4494783863 190 return true;
samux 1:fb4494783863 191 }
samux 1:fb4494783863 192 return false;
samux 1:fb4494783863 193 }
samux 1:fb4494783863 194
samux 1:fb4494783863 195
samux 1:fb4494783863 196 bool Wifly::setProtocol(Protocol p)
samux 1:fb4494783863 197 {
samux 1:fb4494783863 198 // use udp auto pairing
samux 1:fb4494783863 199 char cmd[20];
samux 1:fb4494783863 200 sprintf(cmd, "set i p %d\r", p);
samux 1:fb4494783863 201 if (!sendCommand(cmd, "AOK"))
samux 1:fb4494783863 202 return false;
samux 1:fb4494783863 203
samux 1:fb4494783863 204 switch(p) {
samux 1:fb4494783863 205 case TCP:
samux 1:fb4494783863 206 // set ip flags: tcp retry enabled
samux 1:fb4494783863 207 if (!sendCommand("set i f 0x07\r", "AOK"))
samux 1:fb4494783863 208 return false;
samux 1:fb4494783863 209 break;
samux 1:fb4494783863 210 case UDP:
samux 1:fb4494783863 211 // set ip flags: udp auto pairing enabled
samux 1:fb4494783863 212 if (!sendCommand("set i h 0.0.0.0\r", "AOK"))
samux 1:fb4494783863 213 return false;
samux 4:0bcec6272784 214 if (!sendCommand("set i f 0x40\r", "AOK"))
samux 1:fb4494783863 215 return false;
samux 1:fb4494783863 216 break;
samux 1:fb4494783863 217 }
samux 1:fb4494783863 218 state.proto = p;
samux 1:fb4494783863 219 return true;
samux 1:fb4494783863 220 }
samux 1:fb4494783863 221
WiredHome 25:a740eb74a86a 222
samux 1:fb4494783863 223 char * Wifly::getStringSecurity()
samux 1:fb4494783863 224 {
samux 1:fb4494783863 225 switch(state.sec) {
samux 1:fb4494783863 226 case NONE:
samux 1:fb4494783863 227 return "NONE";
samux 1:fb4494783863 228 case WEP_128:
samux 1:fb4494783863 229 return "WEP_128";
samux 1:fb4494783863 230 case WPA:
samux 1:fb4494783863 231 return "WPA";
samux 1:fb4494783863 232 }
samux 1:fb4494783863 233 return "UNKNOWN";
samux 1:fb4494783863 234 }
samux 1:fb4494783863 235
WiredHome 25:a740eb74a86a 236
samux 1:fb4494783863 237 bool Wifly::connect(const char * host, int port)
samux 1:fb4494783863 238 {
samux 1:fb4494783863 239 char rcv[20];
samux 1:fb4494783863 240 char cmd[20];
samux 1:fb4494783863 241
samux 2:8e54830d0df7 242 // try to open
samux 2:8e54830d0df7 243 sprintf(cmd, "open %s %d\r", host, port);
samux 2:8e54830d0df7 244 if (sendCommand(cmd, "OPEN", NULL, 10000)) {
samux 2:8e54830d0df7 245 state.tcp = true;
WiredHome 25:a740eb74a86a 246 exit();
samux 2:8e54830d0df7 247 return true;
samux 1:fb4494783863 248 }
samux 1:fb4494783863 249
samux 2:8e54830d0df7 250 // if failed, retry and parse the response
samux 2:8e54830d0df7 251 if (sendCommand(cmd, NULL, rcv, 5000)) {
samux 1:fb4494783863 252 if (strstr(rcv, "OPEN") == NULL) {
samux 1:fb4494783863 253 if (strstr(rcv, "Connected") != NULL) {
samux 1:fb4494783863 254 if (!sendCommand("close\r", "CLOS"))
samux 1:fb4494783863 255 return false;
samux 2:8e54830d0df7 256 if (!sendCommand(cmd, "OPEN", NULL, 10000))
samux 1:fb4494783863 257 return false;
samux 1:fb4494783863 258 } else {
samux 1:fb4494783863 259 return false;
samux 1:fb4494783863 260 }
samux 1:fb4494783863 261 }
samux 1:fb4494783863 262 } else {
samux 1:fb4494783863 263 return false;
samux 1:fb4494783863 264 }
samux 2:8e54830d0df7 265
samux 1:fb4494783863 266 state.tcp = true;
WiredHome 25:a740eb74a86a 267 exit();
samux 1:fb4494783863 268 return true;
samux 1:fb4494783863 269 }
samux 1:fb4494783863 270
samux 1:fb4494783863 271
samux 1:fb4494783863 272 bool Wifly::gethostbyname(const char * host, char * ip)
samux 1:fb4494783863 273 {
samux 1:fb4494783863 274 string h = host;
samux 1:fb4494783863 275 char cmd[30], rcv[100];
samux 1:fb4494783863 276 int l = 0;
samux 1:fb4494783863 277 char * point;
samux 1:fb4494783863 278 int nb_digits = 0;
samux 1:fb4494783863 279
samux 1:fb4494783863 280 // no dns needed
samux 1:fb4494783863 281 int pos = h.find(".");
samux 1:fb4494783863 282 if (pos != string::npos) {
samux 1:fb4494783863 283 string sub = h.substr(0, h.find("."));
samux 1:fb4494783863 284 nb_digits = atoi(sub.c_str());
samux 1:fb4494783863 285 }
samux 1:fb4494783863 286 //printf("substrL %s\r\n", sub.c_str());
samux 1:fb4494783863 287 if (count(h.begin(), h.end(), '.') == 3 && nb_digits > 0) {
samux 1:fb4494783863 288 strcpy(ip, host);
samux 1:fb4494783863 289 }
samux 1:fb4494783863 290 // dns needed
samux 1:fb4494783863 291 else {
samux 1:fb4494783863 292 nb_digits = 0;
samux 1:fb4494783863 293 sprintf(cmd, "lookup %s\r", host);
samux 1:fb4494783863 294 if (!sendCommand(cmd, NULL, rcv))
samux 1:fb4494783863 295 return false;
samux 1:fb4494783863 296
samux 1:fb4494783863 297 // look for the ip address
samux 1:fb4494783863 298 char * begin = strstr(rcv, "=") + 1;
samux 1:fb4494783863 299 for (int i = 0; i < 3; i++) {
samux 1:fb4494783863 300 point = strstr(begin + l, ".");
WiredHome 29:49876a8c445b 301 INFO("str: %s", begin + l);
samux 1:fb4494783863 302 l += point - (begin + l) + 1;
samux 1:fb4494783863 303 }
WiredHome 29:49876a8c445b 304 INFO("str: %s", begin + l);
samux 1:fb4494783863 305 while(*(begin + l + nb_digits) >= '0' && *(begin + l + nb_digits) <= '9') {
WiredHome 29:49876a8c445b 306 INFO("digit: %c", *(begin + l + nb_digits));
samux 1:fb4494783863 307 nb_digits++;
samux 1:fb4494783863 308 }
samux 1:fb4494783863 309 memcpy(ip, begin, l + nb_digits);
samux 1:fb4494783863 310 ip[l+nb_digits] = 0;
WiredHome 29:49876a8c445b 311 INFO("ip from dns: %s", ip);
samux 1:fb4494783863 312 }
samux 1:fb4494783863 313 return true;
samux 1:fb4494783863 314 }
samux 1:fb4494783863 315
samux 1:fb4494783863 316
samux 1:fb4494783863 317 void Wifly::flush()
samux 1:fb4494783863 318 {
WiredHome 29:49876a8c445b 319 #ifdef DEBUG
WiredHome 29:49876a8c445b 320 char chatter[500];
WiredHome 29:49876a8c445b 321 int count = 0;
WiredHome 29:49876a8c445b 322 char c;
WiredHome 29:49876a8c445b 323
WiredHome 29:49876a8c445b 324 while (buf_wifly.available()) {
WiredHome 29:49876a8c445b 325 buf_wifly.dequeue(&c);
WiredHome 29:49876a8c445b 326 chatter[count++] = c;
WiredHome 29:49876a8c445b 327 }
WiredHome 29:49876a8c445b 328 chatter[count] = '\0';
WiredHome 29:49876a8c445b 329 if (count)
WiredHome 29:49876a8c445b 330 DBG("Wifly::flush {%s}", chatter);
WiredHome 29:49876a8c445b 331 #endif
samux 1:fb4494783863 332 buf_wifly.flush();
samux 1:fb4494783863 333 }
samux 1:fb4494783863 334
WiredHome 25:a740eb74a86a 335
samux 1:fb4494783863 336 bool Wifly::sendCommand(const char * cmd, const char * ack, char * res, int timeout)
samux 1:fb4494783863 337 {
WiredHome 20:906b0f951bc3 338 int tries = 1;
WiredHome 29:49876a8c445b 339
WiredHome 20:906b0f951bc3 340 while (tries <= 2) {
WiredHome 29:49876a8c445b 341 cmdMode(); // some influences to the wifi module sometimes kick it out
WiredHome 20:906b0f951bc3 342 if (send(cmd, strlen(cmd), ack, res, timeout) >= 0) {
WiredHome 20:906b0f951bc3 343 return true;
WiredHome 20:906b0f951bc3 344 }
WiredHome 29:49876a8c445b 345 state.cmd_mode = false; // must not really be in cmd mode
WiredHome 29:49876a8c445b 346 ERR("sendCommand: failure %d when sending: %s", tries, cmd);
WiredHome 20:906b0f951bc3 347 tries++;
samux 1:fb4494783863 348 }
WiredHome 17:213844a1864f 349 return false;
samux 1:fb4494783863 350 }
samux 1:fb4494783863 351
WiredHome 25:a740eb74a86a 352
samux 1:fb4494783863 353 bool Wifly::cmdMode()
samux 1:fb4494783863 354 {
samux 1:fb4494783863 355 // if already in cmd mode, return
WiredHome 29:49876a8c445b 356 if (state.cmd_mode) {
WiredHome 29:49876a8c445b 357 // Quick verify to ensure we really are in cmd mode
WiredHome 29:49876a8c445b 358 flushIn(0);
WiredHome 29:49876a8c445b 359 if (send("\r", 1, ">") == 1) {
WiredHome 29:49876a8c445b 360 INFO(" cmdMode = true\r\n");
WiredHome 29:49876a8c445b 361 return true;
WiredHome 29:49876a8c445b 362 } else
WiredHome 29:49876a8c445b 363 state.cmd_mode = false;
WiredHome 29:49876a8c445b 364 }
WiredHome 29:49876a8c445b 365 wait_ms(260); // manual 1.2.1 (250 msec before and after)
samux 1:fb4494783863 366 if (send("$$$", 3, "CMD") == -1) {
samux 1:fb4494783863 367 ERR("cannot enter in cmd mode\r\n");
samux 1:fb4494783863 368 return false;
samux 1:fb4494783863 369 }
samux 1:fb4494783863 370 state.cmd_mode = true;
WiredHome 29:49876a8c445b 371 INFO(" cmdMode set to true\r\n");
samux 1:fb4494783863 372 return true;
samux 1:fb4494783863 373 }
samux 1:fb4494783863 374
WiredHome 25:a740eb74a86a 375
samux 1:fb4494783863 376 bool Wifly::disconnect()
samux 1:fb4494783863 377 {
samux 1:fb4494783863 378 // if already disconnected, return
samux 1:fb4494783863 379 if (!state.associated)
samux 1:fb4494783863 380 return true;
samux 2:8e54830d0df7 381
samux 1:fb4494783863 382 if (!sendCommand("leave\r", "DeAuth"))
samux 1:fb4494783863 383 return false;
samux 1:fb4494783863 384 exit();
samux 2:8e54830d0df7 385
samux 1:fb4494783863 386 state.associated = false;
samux 1:fb4494783863 387 return true;
samux 1:fb4494783863 388 }
samux 1:fb4494783863 389
WiredHome 25:a740eb74a86a 390
samux 1:fb4494783863 391 bool Wifly::is_connected()
samux 1:fb4494783863 392 {
samux 1:fb4494783863 393 return (tcp_status.read() == 1) ? true : false;
samux 1:fb4494783863 394 }
samux 1:fb4494783863 395
samux 1:fb4494783863 396
samux 1:fb4494783863 397 void Wifly::reset()
samux 1:fb4494783863 398 {
samux 1:fb4494783863 399 reset_pin = 0;
WiredHome 25:a740eb74a86a 400 wifi.baud(9600);
WiredHome 25:a740eb74a86a 401 wait_ms(200);
samux 1:fb4494783863 402 reset_pin = 1;
WiredHome 25:a740eb74a86a 403 GatherLogonInfo();
samux 1:fb4494783863 404 }
samux 1:fb4494783863 405
WiredHome 25:a740eb74a86a 406
samux 3:9aa05e19c62e 407 bool Wifly::reboot()
samux 3:9aa05e19c62e 408 {
WiredHome 26:78a1a09afdc9 409 if (sendCommand("reboot\r", "Reboot")) {
WiredHome 26:78a1a09afdc9 410 state.cmd_mode = false;
WiredHome 26:78a1a09afdc9 411 wait_ms(500);
WiredHome 26:78a1a09afdc9 412 wifi.baud(9600);
WiredHome 26:78a1a09afdc9 413 baud(baudrate);
WiredHome 26:78a1a09afdc9 414 exit();
WiredHome 26:78a1a09afdc9 415 return true;
WiredHome 26:78a1a09afdc9 416 } else {
samux 3:9aa05e19c62e 417 return false;
WiredHome 26:78a1a09afdc9 418 }
samux 3:9aa05e19c62e 419 }
samux 3:9aa05e19c62e 420
WiredHome 25:a740eb74a86a 421
samux 1:fb4494783863 422 bool Wifly::close()
samux 1:fb4494783863 423 {
WiredHome 29:49876a8c445b 424 //wait_ms(100); // we don't know how long to wait, but not waiting long enough truncates outbound data
samux 1:fb4494783863 425 if (!state.tcp)
samux 1:fb4494783863 426 return true;
WiredHome 29:49876a8c445b 427 if (!sendCommand("close\r", "*CLOS*", NULL, 1000))
samux 1:fb4494783863 428 return false;
WiredHome 29:49876a8c445b 429 //exit();
samux 1:fb4494783863 430 state.tcp = false;
samux 1:fb4494783863 431 return true;
samux 1:fb4494783863 432 }
samux 1:fb4494783863 433
samux 1:fb4494783863 434
samux 1:fb4494783863 435 int Wifly::putc(char c)
samux 1:fb4494783863 436 {
WiredHome 25:a740eb74a86a 437 while (!wifi.writeable())
WiredHome 25:a740eb74a86a 438 ;
samux 1:fb4494783863 439 return wifi.putc(c);
samux 1:fb4494783863 440 }
samux 1:fb4494783863 441
samux 1:fb4494783863 442
samux 1:fb4494783863 443 bool Wifly::exit()
samux 1:fb4494783863 444 {
samux 1:fb4494783863 445 if (!sendCommand("exit\r", "EXIT"))
samux 1:fb4494783863 446 return false;
samux 1:fb4494783863 447 state.cmd_mode = false;
WiredHome 29:49876a8c445b 448 DBG("exit()\r\n");
samux 1:fb4494783863 449 return true;
samux 1:fb4494783863 450 }
samux 1:fb4494783863 451
samux 1:fb4494783863 452
samux 1:fb4494783863 453 int Wifly::readable()
samux 1:fb4494783863 454 {
samux 1:fb4494783863 455 return buf_wifly.available();
samux 1:fb4494783863 456 }
samux 1:fb4494783863 457
WiredHome 25:a740eb74a86a 458
samux 1:fb4494783863 459 int Wifly::writeable()
samux 1:fb4494783863 460 {
samux 1:fb4494783863 461 return wifi.writeable();
samux 1:fb4494783863 462 }
samux 1:fb4494783863 463
WiredHome 25:a740eb74a86a 464
samux 1:fb4494783863 465 char Wifly::getc()
samux 1:fb4494783863 466 {
samux 1:fb4494783863 467 char c;
WiredHome 25:a740eb74a86a 468 while (!buf_wifly.available())
WiredHome 25:a740eb74a86a 469 ;
samux 1:fb4494783863 470 buf_wifly.dequeue(&c);
samux 1:fb4494783863 471 return c;
samux 1:fb4494783863 472 }
samux 1:fb4494783863 473
WiredHome 25:a740eb74a86a 474
samux 1:fb4494783863 475 void Wifly::handler_rx(void)
samux 1:fb4494783863 476 {
samux 1:fb4494783863 477 //read characters
samux 1:fb4494783863 478 while (wifi.readable())
samux 1:fb4494783863 479 buf_wifly.queue(wifi.getc());
samux 1:fb4494783863 480 }
samux 1:fb4494783863 481
WiredHome 25:a740eb74a86a 482
samux 1:fb4494783863 483 void Wifly::attach_rx(bool callback)
samux 1:fb4494783863 484 {
samux 1:fb4494783863 485 if (!callback)
samux 1:fb4494783863 486 wifi.attach(NULL);
samux 1:fb4494783863 487 else
samux 1:fb4494783863 488 wifi.attach(this, &Wifly::handler_rx);
samux 1:fb4494783863 489 }
samux 1:fb4494783863 490
samux 1:fb4494783863 491
samux 1:fb4494783863 492 int Wifly::send(const char * str, int len, const char * ACK, char * res, int timeout)
samux 1:fb4494783863 493 {
samux 1:fb4494783863 494 char read;
samux 1:fb4494783863 495 size_t found = string::npos;
samux 1:fb4494783863 496 string checking;
samux 1:fb4494783863 497 Timer tmr;
samux 1:fb4494783863 498 int result = 0;
samux 1:fb4494783863 499
WiredHome 29:49876a8c445b 500 //DBG("send w/timeout %d ms this: %s", timeout, str);
samux 1:fb4494783863 501 attach_rx(false);
WiredHome 29:49876a8c445b 502 flushIn(0);
WiredHome 20:906b0f951bc3 503 tmr.start();
samux 1:fb4494783863 504 if (!ACK || !strcmp(ACK, "NO")) {
samux 1:fb4494783863 505 for (int i = 0; i < len; i++)
samux 1:fb4494783863 506 result = (putc(str[i]) == str[i]) ? result + 1 : result;
samux 1:fb4494783863 507 } else {
samux 1:fb4494783863 508 for (int i = 0; i < len; i++)
samux 1:fb4494783863 509 result = (putc(str[i]) == str[i]) ? result + 1 : result;
samux 1:fb4494783863 510
samux 1:fb4494783863 511 while (1) {
samux 1:fb4494783863 512 if (tmr.read_ms() > timeout) {
WiredHome 18:18ab3993d00d 513 flushIn();
WiredHome 29:49876a8c445b 514 WARN("Can't find [%s] in [%s]", ACK, checking.c_str());
samux 1:fb4494783863 515 attach_rx(true);
samux 1:fb4494783863 516 return -1;
samux 1:fb4494783863 517 } else if (wifi.readable()) {
samux 1:fb4494783863 518 read = wifi.getc();
samux 1:fb4494783863 519 if ( read != '\r' && read != '\n') {
samux 1:fb4494783863 520 checking += read;
samux 1:fb4494783863 521 found = checking.find(ACK);
samux 1:fb4494783863 522 if (found != string::npos) {
WiredHome 29:49876a8c445b 523 flushIn(5);
samux 1:fb4494783863 524 break;
samux 1:fb4494783863 525 }
samux 1:fb4494783863 526 }
samux 1:fb4494783863 527 }
samux 1:fb4494783863 528 }
WiredHome 29:49876a8c445b 529 DBG(" found: {%s}", checking.c_str());
samux 1:fb4494783863 530 attach_rx(true);
samux 1:fb4494783863 531 return result;
samux 1:fb4494783863 532 }
samux 1:fb4494783863 533
samux 1:fb4494783863 534 //the user wants the result from the command (ACK == NULL, res != NULL)
samux 1:fb4494783863 535 if ( res != NULL) {
samux 1:fb4494783863 536 int i = 0;
samux 1:fb4494783863 537 while (1) {
WiredHome 19:b0c2488222a3 538 if (tmr.read_ms() > timeout) {
WiredHome 19:b0c2488222a3 539 res[i] = '\0';
samux 1:fb4494783863 540 if (i == 0) {
samux 1:fb4494783863 541 res = NULL;
samux 1:fb4494783863 542 }
WiredHome 29:49876a8c445b 543 ERR("timeout w/o response to %s", str);
samux 1:fb4494783863 544 break;
samux 1:fb4494783863 545 } else {
samux 1:fb4494783863 546 if (wifi.readable()) {
samux 1:fb4494783863 547 read = wifi.getc();
WiredHome 25:a740eb74a86a 548 // we drop \r and \n, but should we since it is for user code...
samux 1:fb4494783863 549 if ( read != '\r' && read != '\n') {
samux 1:fb4494783863 550 res[i++] = read;
samux 1:fb4494783863 551 }
samux 1:fb4494783863 552 }
samux 1:fb4494783863 553 }
samux 1:fb4494783863 554 }
WiredHome 26:78a1a09afdc9 555 DBG("user str: {%s}", res);
samux 1:fb4494783863 556 }
samux 1:fb4494783863 557
WiredHome 18:18ab3993d00d 558 flushIn();
samux 1:fb4494783863 559 attach_rx(true);
samux 1:fb4494783863 560 return result;
WiredHome 18:18ab3993d00d 561 }
WiredHome 18:18ab3993d00d 562
WiredHome 19:b0c2488222a3 563
WiredHome 18:18ab3993d00d 564 void Wifly::flushIn(int timeout_ms)
WiredHome 18:18ab3993d00d 565 {
WiredHome 18:18ab3993d00d 566 Timer tmr;
WiredHome 18:18ab3993d00d 567 #ifdef DEBUG
WiredHome 18:18ab3993d00d 568 char chatter[500];
WiredHome 18:18ab3993d00d 569 int count = 0;
WiredHome 18:18ab3993d00d 570 int c;
WiredHome 18:18ab3993d00d 571 #endif
WiredHome 18:18ab3993d00d 572
WiredHome 29:49876a8c445b 573 if (timeout_ms < 0) {
WiredHome 25:a740eb74a86a 574 timeout_ms = 2 * 10000 / baudrate; // compute minimal timeout
WiredHome 29:49876a8c445b 575 if (timeout_ms < 5)
WiredHome 29:49876a8c445b 576 timeout_ms = 5;
WiredHome 18:18ab3993d00d 577 }
WiredHome 18:18ab3993d00d 578 tmr.start();
WiredHome 18:18ab3993d00d 579 while (wifi.readable() || (tmr.read_ms() < timeout_ms)) {
WiredHome 18:18ab3993d00d 580 if (wifi.readable()) {
WiredHome 29:49876a8c445b 581 #ifdef DEBUG
WiredHome 29:49876a8c445b 582 c = wifi.getc();
WiredHome 29:49876a8c445b 583 chatter[count++] = c;
WiredHome 18:18ab3993d00d 584 #else
WiredHome 29:49876a8c445b 585 wifi.getc();
WiredHome 18:18ab3993d00d 586 #endif
WiredHome 18:18ab3993d00d 587 tmr.reset();
WiredHome 18:18ab3993d00d 588 tmr.start(); // start should not be necessary
WiredHome 18:18ab3993d00d 589 }
WiredHome 18:18ab3993d00d 590 }
WiredHome 18:18ab3993d00d 591 #ifdef DEBUG
WiredHome 18:18ab3993d00d 592 chatter[count] = '\0';
WiredHome 29:49876a8c445b 593 if (count)
WiredHome 29:49876a8c445b 594 DBG("Wifly::flushIn(%d) {%s}", timeout_ms, chatter);
WiredHome 18:18ab3993d00d 595 #endif
WiredHome 18:18ab3993d00d 596 }
WiredHome 20:906b0f951bc3 597
WiredHome 20:906b0f951bc3 598
WiredHome 20:906b0f951bc3 599 // The ARM uart and the Wifly uart have to be in sync or we get
WiredHome 20:906b0f951bc3 600 // no meaningful response, so then have to try the possibilities.
WiredHome 20:906b0f951bc3 601 //
WiredHome 20:906b0f951bc3 602 // First try is at the currently configured ARM uart baud, if
WiredHome 20:906b0f951bc3 603 // that fails then it shifts the ARM uart baud through the probable
WiredHome 20:906b0f951bc3 604 // speeds, trying to establish contact with the Wifly module.
WiredHome 20:906b0f951bc3 605 // Once contact is demonstrated (response to the 'ver' command),
WiredHome 20:906b0f951bc3 606 // then it sets the Wifly module and then the ARM uart.
WiredHome 20:906b0f951bc3 607 bool Wifly::baud(int _targetBaud)
WiredHome 20:906b0f951bc3 608 {
WiredHome 20:906b0f951bc3 609 // in testing, 460800 and 921600 may change the Wifly module where you can't
WiredHome 20:906b0f951bc3 610 // change it back w/o a reset. So, we won't even permit those speeds.
WiredHome 20:906b0f951bc3 611 const int baudrates[] = {2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400}; //, 460800, 921600};
WiredHome 20:906b0f951bc3 612 #define BRCOUNT (sizeof(baudrates)/sizeof(baudrates[0]))
WiredHome 20:906b0f951bc3 613 char cmd[20]; // sized for "set u i 460800\r" [15+1], plus margin [4]
WiredHome 20:906b0f951bc3 614 int tryIndex = 0;
WiredHome 20:906b0f951bc3 615 bool res = false;
WiredHome 20:906b0f951bc3 616 int userIndex;
WiredHome 20:906b0f951bc3 617
WiredHome 20:906b0f951bc3 618 sprintf(cmd, "set u i %d\r", _targetBaud);
WiredHome 20:906b0f951bc3 619 // set u i # should cause it to exit command mode (manual 2.3.64),
WiredHome 20:906b0f951bc3 620 // but testing indicates that it does not.
WiredHome 20:906b0f951bc3 621 for (userIndex=0; userIndex < BRCOUNT; userIndex++) {
WiredHome 20:906b0f951bc3 622 if (_targetBaud == baudrates[userIndex]) {
WiredHome 20:906b0f951bc3 623 while (tryIndex <= BRCOUNT) {
WiredHome 26:78a1a09afdc9 624 DBG("baud() try: %d", tryIndex);
WiredHome 20:906b0f951bc3 625 sendCommand(cmd); // shift Wifly to desired speed [it may not respond (see 2.3.64)]
WiredHome 20:906b0f951bc3 626 // state.cmd_mode = false; // see note above why this is disabled
WiredHome 20:906b0f951bc3 627 wifi.baud(_targetBaud); // shift the ARM uart to match
WiredHome 20:906b0f951bc3 628 if (sendCommand("ver\r", "wifly", NULL, timeToRespond(4))) { // use this to verify communications
WiredHome 20:906b0f951bc3 629 baudrate = _targetBaud;
WiredHome 20:906b0f951bc3 630 res = true;
WiredHome 20:906b0f951bc3 631 break; // success
WiredHome 20:906b0f951bc3 632 }
WiredHome 20:906b0f951bc3 633 // keep trying baudrates between ARM and WiFly
WiredHome 20:906b0f951bc3 634 if (tryIndex < BRCOUNT) {
WiredHome 29:49876a8c445b 635 WARN(" baud() set to %d", baudrates[tryIndex]);
WiredHome 20:906b0f951bc3 636 wifi.baud(baudrates[tryIndex]);
WiredHome 20:906b0f951bc3 637 }
WiredHome 20:906b0f951bc3 638 tryIndex++;
WiredHome 20:906b0f951bc3 639 }
WiredHome 20:906b0f951bc3 640 break; // if they selected a legitimate baud, try no others
WiredHome 20:906b0f951bc3 641 }
WiredHome 20:906b0f951bc3 642 }
WiredHome 26:78a1a09afdc9 643 DBG(" baud() result: %d", res);
WiredHome 20:906b0f951bc3 644 return res;
WiredHome 20:906b0f951bc3 645 }
WiredHome 20:906b0f951bc3 646
WiredHome 25:a740eb74a86a 647
WiredHome 29:49876a8c445b 648 int Wifly::timeToRespond(int stringLen)
WiredHome 20:906b0f951bc3 649 {
WiredHome 20:906b0f951bc3 650 return 150 + (1 | 10000/baudrate) * stringLen;
WiredHome 21:97294686b4a1 651 }
WiredHome 23:6e77c65ced00 652
WiredHome 24:5012a535b1d5 653
WiredHome 24:5012a535b1d5 654 void Wifly::FixPhrase(char ** dst, const char * src)
WiredHome 24:5012a535b1d5 655 {
WiredHome 24:5012a535b1d5 656 // change all ' ' in '$' in the ssid and the passphrase
WiredHome 24:5012a535b1d5 657 *dst = (char *)malloc(strlen(src)+1);
WiredHome 24:5012a535b1d5 658 if (*dst) {
WiredHome 24:5012a535b1d5 659 strcpy(*dst, src);
WiredHome 24:5012a535b1d5 660 for (int i = 0; i < strlen(*dst); i++) {
WiredHome 24:5012a535b1d5 661 if ((*dst)[i] == ' ')
WiredHome 24:5012a535b1d5 662 (*dst)[i] = '$';
WiredHome 24:5012a535b1d5 663 }
WiredHome 24:5012a535b1d5 664 } else {
WiredHome 24:5012a535b1d5 665 *dst = NULL;
WiredHome 24:5012a535b1d5 666 }
WiredHome 24:5012a535b1d5 667 }
WiredHome 25:a740eb74a86a 668
WiredHome 25:a740eb74a86a 669
WiredHome 25:a740eb74a86a 670 void Wifly::GatherLogonInfo()
WiredHome 25:a740eb74a86a 671 {
WiredHome 25:a740eb74a86a 672 Timer timer;
WiredHome 25:a740eb74a86a 673 char logonText[200];
WiredHome 25:a740eb74a86a 674 int i = 0;
WiredHome 25:a740eb74a86a 675 char *p;
WiredHome 25:a740eb74a86a 676
WiredHome 25:a740eb74a86a 677 timer.start();
WiredHome 25:a740eb74a86a 678 if (wiflyVersionString) {
WiredHome 25:a740eb74a86a 679 free(wiflyVersionString);
WiredHome 25:a740eb74a86a 680 wiflyVersionString = NULL;
WiredHome 25:a740eb74a86a 681 }
WiredHome 25:a740eb74a86a 682 logonText[i] = '\0';
WiredHome 25:a740eb74a86a 683 while (timer.read_ms() < 500) {
WiredHome 25:a740eb74a86a 684 while (wifi.readable()) {
WiredHome 25:a740eb74a86a 685 logonText[i++] = wifi.getc();
WiredHome 25:a740eb74a86a 686 }
WiredHome 25:a740eb74a86a 687 }
WiredHome 25:a740eb74a86a 688 logonText[i] = '\0';
WiredHome 25:a740eb74a86a 689 p = strchr(logonText, '\r');
WiredHome 25:a740eb74a86a 690 if (p)
WiredHome 25:a740eb74a86a 691 *p = '\0';
WiredHome 25:a740eb74a86a 692 wiflyVersionString = (char *)malloc(strlen(logonText)+1);
WiredHome 25:a740eb74a86a 693 if (wiflyVersionString)
WiredHome 25:a740eb74a86a 694 strcpy(wiflyVersionString, logonText);
WiredHome 25:a740eb74a86a 695 p = strstr(logonText, "Ver ");
WiredHome 25:a740eb74a86a 696 if (p) {
WiredHome 25:a740eb74a86a 697 p += 4;
WiredHome 25:a740eb74a86a 698 swVersion = atof(p);
WiredHome 25:a740eb74a86a 699 }
WiredHome 29:49876a8c445b 700 INFO("swVersion: %3.2f, versionString: {%s}", swVersion, wiflyVersionString);
WiredHome 25:a740eb74a86a 701 }
WiredHome 25:a740eb74a86a 702
WiredHome 25:a740eb74a86a 703
WiredHome 25:a740eb74a86a 704 float Wifly::getWiflyVersion()
WiredHome 25:a740eb74a86a 705 {
WiredHome 25:a740eb74a86a 706 return swVersion;
WiredHome 25:a740eb74a86a 707 }
WiredHome 25:a740eb74a86a 708
WiredHome 25:a740eb74a86a 709
WiredHome 25:a740eb74a86a 710 char * Wifly::getWiflyVersionString()
WiredHome 25:a740eb74a86a 711 {
WiredHome 25:a740eb74a86a 712 return wiflyVersionString;
WiredHome 25:a740eb74a86a 713 }
WiredHome 25:a740eb74a86a 714
WiredHome 26:78a1a09afdc9 715
WiredHome 26:78a1a09afdc9 716 void Wifly::setConnectionState(bool value)
WiredHome 26:78a1a09afdc9 717 {
WiredHome 26:78a1a09afdc9 718 state.tcp = value;
WiredHome 26:78a1a09afdc9 719 }
WiredHome 26:78a1a09afdc9 720