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
- Revision:
- 93:06e755a80187
- Parent:
- 92:ec9550034276
- Child:
- 94:fb4414aff957
--- a/source/WiFiManager.cpp Sat Apr 13 14:17:29 2019 +0000 +++ b/source/WiFiManager.cpp Sun Apr 14 14:38:51 2019 +0000 @@ -89,8 +89,18 @@ break; case WIFI_CMD_CONNECT: error = connect(); + int secCount = 0; + while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS || is_connected==false){ + wait(1); // wait 1 sec + } wifiCmd = WIFI_CMD_NONE; - queueATresponse(AT_CONNECT_RESP); + if(is_connected==false){ + printf("[WIFI MAN] +++ WIFI CONNECTION TIMEOUT +++ \r\n"); + queueATresponse(AT_COMMAND_FAILED); + } + else { + queueATresponse(AT_CONNECT_RESP); + } break; case WIFI_CMD_DISCONNECT: error = disconnect(); @@ -372,7 +382,10 @@ printf("\n [WIFI-MAN] Could not set non-blocking mode for Wifi -- aborting!! - \n"); return error; } - printf("[WIFI-MAN] Connecting to network %s\n", wifi_config.ssid); + printf("[WIFI-MAN] Connecting to network ssid = %s passwd = %s security = %s \r\n", + wifi_config.ssid, + wifi_config.pass, + sec2str(wifi_config.security)); error = network->connect(wifi_config.ssid, wifi_config.pass, wifi_config.security); @@ -506,7 +519,9 @@ bool WiFiManager::createTLSconnection(const char * hostName) { - //mbed_trace_init(); +#ifdef ENABLE_MBED_TRACE + mbed_trace_init(); +#endif socket = new TLSSocket(); nsapi_error_t r; @@ -528,7 +543,10 @@ r = socket->connect(hostName, 443); if(r != NSAPI_ERROR_OK) { - printf("TLS connect failed for hostname %s!!\n", hostName); + char errstr[100]; + mbedtls_strerror(r, errstr, 100); + printf("TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr); + socket->close(); return false; } printf("TLS connection successful for https site : %s\n", hostName); @@ -560,7 +578,7 @@ printf("contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen); if(bodyLen > 10){ - printf("\n Message Body:\n"); + printf("\n [WIFI MAN] Message Body:\n"); printBufferInHex(http_req_cfg->body, bodyLen); } if(strstr(internet_config.url, "http:")!=NULL) // http request @@ -601,6 +619,9 @@ if(https_connection_active == false){ bool tlsResult; tlsResult = createTLSconnection(host); +#ifdef ENABLE_MBED_TRACE + mbed_trace_free(); // free trace memory +#endif if(tlsResult == false){ delete socket; free_DataMsg();