Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WiflyInterface by
Revision 10:9fc0bb21c723, committed 2016-12-16
- Comitter:
- kingkingyyk
- Date:
- Fri Dec 16 02:55:12 2016 +0000
- Parent:
- 9:c77799a03294
- Commit message:
- - Auto reconnect; - Added is_associated
Changed in this revision
--- a/Socket/TCPSocketServer.cpp Tue Jan 28 11:00:48 2014 +0200 +++ b/Socket/TCPSocketServer.cpp Fri Dec 16 02:55:12 2016 +0000 @@ -87,4 +87,34 @@ } } } +} + +int TCPSocketServer::acceptWithTimeout(TCPSocketConnection& connection, int timeout) { + int nb_available = 0, pos = 0; + char c; + string str; + bool o_find = false; + time_t currTime = time(NULL); + while (1) { + while(!wifi->readable() && time(NULL)-currTime<=timeout); + if (time(NULL)-currTime>timeout) { + wifi->flush(); + return -1; + } + nb_available = wifi->readable(); + for (int i = 0; i < nb_available; i++) { + c = wifi->getc(); + if (c == '*') { + o_find = true; + } + if (o_find && c != '\r' && c != '\n') { + str += c; + pos = str.find("*OPEN*"); + if (pos != string::npos) { + wifi->flush(); + return 0; + } + } + } + } } \ No newline at end of file
--- a/Socket/TCPSocketServer.h Tue Jan 28 11:00:48 2014 +0200 +++ b/Socket/TCPSocketServer.h Fri Dec 16 02:55:12 2016 +0000 @@ -47,6 +47,12 @@ \return 0 on success, -1 on failure. */ int accept(TCPSocketConnection& connection); + + /** Accept a new connection. + \param connection A TCPSocketConnection instance that will handle the incoming connection. + \return 0 on success, -1 on failure. + */ + int acceptWithTimeout(TCPSocketConnection& connection, int timeout); }; #endif
--- a/Wifly/Wifly.cpp Tue Jan 28 11:00:48 2014 +0200 +++ b/Wifly/Wifly.cpp Fri Dec 16 02:55:12 2016 +0000 @@ -71,8 +71,8 @@ for (int i= 0; i < MAX_TRY_JOIN; i++) { - // no auto join - if (!sendCommand("set w j 0\r", "AOK")) + // force auto join + if (!sendCommand("set w j 1\r", "AOK")) continue; //no echo @@ -84,7 +84,7 @@ continue; // set size - if (!sendCommand("set c s 1024\r", "AOK")) + if (!sendCommand("set c s 1420\r", "AOK")) continue; // red led on when tcp connection active @@ -122,6 +122,11 @@ if (!sendCommand(cmd, "AOK")) continue; + //tcp + sprintf(cmd, "set comm idle 5%d\r", state.sec); + if (!sendCommand(cmd, "AOK")) + continue; + // if no dhcp, set ip, netmask and gateway if (!state.dhcp) { DBG("not dhcp\r"); @@ -342,6 +347,13 @@ } +bool Wifly::is_associated() +{ + bool flag=sendCommand("show c\r", "8630", NULL, 1000); + exit(); + return flag; +} + bool Wifly::is_connected() { return (tcp_status.read() == 1) ? true : false;
--- a/Wifly/Wifly.h Tue Jan 28 11:00:48 2014 +0200 +++ b/Wifly/Wifly.h Fri Dec 16 02:55:12 2016 +0000 @@ -77,7 +77,7 @@ * @return true if successful */ bool disconnect(); - + bool is_associated(); /** * Open a tcp connection with the specified host on the specified port *
--- a/WiflyInterface.cpp Tue Jan 28 11:00:48 2014 +0200 +++ b/WiflyInterface.cpp Fri Dec 16 02:55:12 2016 +0000 @@ -32,6 +32,11 @@ return join(); } +bool WiflyInterface::is_associated() +{ + return Wifly::is_associated(); +} + int WiflyInterface::disconnect() { return Wifly::disconnect();
--- a/WiflyInterface.h Tue Jan 28 11:00:48 2014 +0200 +++ b/WiflyInterface.h Fri Dec 16 02:55:12 2016 +0000 @@ -74,6 +74,8 @@ */ char* getIPAddress(); + bool is_associated(); + private: char ip_string[20]; bool ip_set;