Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
Diff: source/WiFiManager.cpp
- Branch:
- PassingRegression
- Revision:
- 124:eae4512b131b
- Parent:
- 123:a49e9ffbaca6
- Child:
- 125:d2830421006c
--- a/source/WiFiManager.cpp Fri Jun 14 21:13:46 2019 +0000 +++ b/source/WiFiManager.cpp Sat Jun 15 15:52:26 2019 +0000 @@ -58,6 +58,9 @@ WiFiManager::~WiFiManager() { delete network; + wifiWatchdogTimer.stop(); + socket->close(); + delete socket; } //#define DISABLE_WATCHDOG @@ -262,6 +265,11 @@ } case WIFI_CMD_CONNECT: { + if(is_connected) // already connected + { + wifiCmd = WIFI_CMD_NONE; + break; + } wifiBusy = 1; error = connect(); int secCount = 0; @@ -287,12 +295,42 @@ break; } case WIFI_CMD_DISCONNECT: + { + if(!is_connected) // already disconnected + { + wifiCmd = WIFI_CMD_NONE; + break; + } wifiBusy = 1; error = disconnect(); wifiCmd = WIFI_CMD_NONE; - queueATresponse(AT_DISCONNECT_RESP); + if(error >= 0) + { + int secCount = 0; + while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS && is_connected==true){ + wait(1); // wait 1 sec + } + if(!is_connected) + { + sendATresponseString(AT_DISCONNECT_RESP); + } + else + { + dbg_printf(LOG, "[WIFI MAN] +++ WIFI DISCONNECTION TIMEOUT +++ \r\n"); + //queueATresponse(AT_COMMAND_FAILED); + responseString = (char *) malloc(100); + sprintf(responseString, "\r\n+UUTIMEOUT\r\n"); + sendATresponseString(AT_COMMAND_FAILED); + } + // attempt reconnection if always connected scheme is set + if(internet_config->connectionScheme == ALWAYS_CONNECTED) + { + setNextCommand(WIFI_CMD_CONNECT); + } + } wifiBusy = 0; break; + } case WIFI_CMD_CONFIG: wifiBusy = 1; set_WIFI_CONFIG(); @@ -815,10 +853,14 @@ void WiFiManager::getWiFiMACaddress() { + char * mp = new char[20]; + sscanf(network->get_mac_address(),"%02s:%2s:%2s:%2s:%2s:%2s",&mp[0],&mp[2],&mp[4],&mp[6],&mp[8],&mp[10]); responseString = (char *) malloc(100); - sprintf(responseString, "\r\n%s%d,%s\r\n", LOCAL_ADDRESS_RESP, - WIFI_IF_ID, - network->get_mac_address()); + + sprintf(responseString, "\r\n%s%d,%sOK\r\n", LOCAL_ADDRESS_RESP, + WIFI_IF_ID, + mp); + delete mp; } @@ -898,22 +940,21 @@ network->get_mac_address(), DEFAULT_WIFI_CHANNEL); + wifiBusy = 0; is_connected = true; - wifiBusy = 0; } break; case NSAPI_STATUS_DISCONNECTED: dbg_printf(LOG, "No connection to network!\r\n"); dbg_printf(LOG, "\n [WIFI-MAN] No connection to network!\n"); - is_connected = false; - // attempt reconnection if always connected scheme is set - if(internet_config->connectionScheme == ALWAYS_CONNECTED) + if(outputBuffersAvailable()) { - wifiBusy = 1; - nsapi_error_t error; - error = connect(); - queueATresponse(WIFI_RECONNECT_INFO); + responseString = (char *) malloc(100); + sprintf(responseString, "\r\n%s%d,5\r\n", WIFI_LINK_DISABLED, WIFI_CHANNEL); + //sendATresponseString(AT_EVENT); } + wifiBusy = 0; + is_connected = false; break; case NSAPI_STATUS_CONNECTING: dbg_printf(LOG, "Connecting to network!\r\n"); @@ -1043,6 +1084,12 @@ { nsapi_error_t error; error = network->disconnect(); + if(error < 0) + { + responseString = (char *) malloc(100); + sprintf(responseString, "%s", UDDRP_ERROR); + sendATresponseString(AT_EVENT); + } return error; }