A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: wifi/Wifi.cpp
- Revision:
- 114:cd34b1d64360
- Parent:
- 113:7238f9b8db17
- Child:
- 117:e59a616ffe16
--- a/wifi/Wifi.cpp Tue Dec 31 19:57:21 2013 +0000 +++ b/wifi/Wifi.cpp Tue Dec 31 21:35:49 2013 +0000 @@ -289,11 +289,30 @@ bool Wifi::isOpen() { + if(!socketOpened) { + return false; + } + if(!setCmdMode(true)) { + printf("[ERROR] Failed to properly check if TCP connection is open.\r\n"); + return socketOpened; + } + std::string response = sendCommand("show connection", 2000, "\n"); + int start = response.find("f"); + if(start != string::npos && response.size() >= (start + 3)) { + if(response[start + 3] == '1') { + socketOpened = true; + } else { + socketOpened = false; + } + } else { + printf("[WARNING] Trouble checking TCP Connection status.\n\r"); + } return socketOpened; } bool Wifi::close() { + wait(1); if(io == NULL) { printf("[ERROR] MTSBufferedIO not set\r\n"); return false; @@ -309,18 +328,18 @@ return false; } - std::string response = sendCommand("close", 10000, "CLOS"); - //printf("Close Response: %s\n\r", response.c_str()); - if(response.find("CLOS") == string::npos) { - printf("[ERROR] Failed to successfully close socket\r\n"); - return false; + if(isOpen()) { + std::string response = sendCommand("close", 3000, "CLOS"); + printf("Close Response: %s\n\r", response.c_str()); + if(response.find("CLOS") == string::npos) { + printf("[WARNING] Failed to successfully close socket...\r\n"); + return false; + } } - socketOpened = false; - io->rxClear(); io->txClear(); - + return true; }