this is using the mbed os version 5-13-1
Diff: source/WiFiManager.cpp
- Branch:
- PassingRegression
- Revision:
- 105:e5ce023eee93
- Parent:
- 104:11e9605093c9
- Child:
- 106:e1f04c3d0647
--- a/source/WiFiManager.cpp Sun May 05 08:24:46 2019 +0000
+++ b/source/WiFiManager.cpp Mon May 06 09:06:36 2019 +0000
@@ -48,9 +48,12 @@
WiFiManager::~WiFiManager()
{
}
-
+//#define DISABLE_WATCHDOG
void WiFiManager::callWifiWatchDog()
{
+#ifdef DISABLE_WATCHDOG
+ return;
+#else
static int inactivity_monitor = 0;
watchdogCnt++;
if(watchdogCnt >= 6 && responseString==NULL) // every minute
@@ -74,7 +77,7 @@
inactivity_monitor = 0;
}
}
-
+#endif
}
bool WiFiManager::queueATresponse(at_cmd_resp_t resp){
@@ -199,6 +202,7 @@
dbg_printf(LOG, "before call to send http request \n");
dbg_printf(LOG, "\r\n[WIFI-MAN] Received HTTPS request...\r\n");
print_memory_info();
+ //network->attach(NULL);
result = createHttpsRequest();
if(result == false)
{
@@ -217,13 +221,14 @@
print_memory_info();
wifiCmd = WIFI_CMD_NONE;
wifiBusy = 0;
+ //network->attach(callback(this, &WiFiManager::status_callback));
break;
case WIFI_CMD_SEND_HTTP_REQ:
break;
default:
break;
}
- wait_ms(100); //
+ wait_ms(WIFI_MAIN_LOOP_WAIT_TIME_MS); //
}
}
@@ -597,7 +602,7 @@
void WiFiManager::status_callback(nsapi_event_t status, intptr_t param)
{
- dbg_printf(LOG, "[WIFI-MAN] about to call callback... \r\n");
+ dbg_printf(LOG, "[WIFI-MAN] about to call status_callback_event... \r\n");
_event_queue.call_in(50, this, &WiFiManager::status_callback_event, status, param);
//status_callback_event(status, param);
}
@@ -886,6 +891,7 @@
void WiFiManager::body_callback(const char *at, uint32_t length) {
dbg_printf(LOG, "\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
chunkNum++;
+ dbg_printf(LOG, "This is the start when response is excluded\r\n%s\r\nend of packet \r\n", at);
if(http_response == NULL)
{
dbg_printf(LOG, "[WIFI-MAN] response pointer NULL!!\r\n");
@@ -904,14 +910,16 @@
sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
}
-
+//#define ENABLE_MBED_TRACE
bool WiFiManager::createTLSconnection(const char * hostName)
{
#ifdef ENABLE_MBED_TRACE
mbed_trace_init();
#endif
socket = new TLSSocket();
-
+ // set a 5 second timeout
+ //socket->set_timeout(5000);
+ //socket->set_blocking(false);
nsapi_error_t r;
// make sure to check the return values for the calls below (should return NSAPI_ERROR_OK)
r = socket->open(network);
@@ -935,7 +943,8 @@
{
char errstr[100];
mbedtls_strerror(r, errstr, 100);
- dbg_printf(LOG, "TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr);
+ dbg_printf(LOG, "TLS connect failed (err = %d) for hostname '%s' -- ERROR = %s !!\n", r, hostName, errstr);
+ //printf("TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr);
socket->close();
return false;
}
@@ -964,6 +973,12 @@
delete address;
}
+
+void WiFiManager::sendDebugMessage()
+{
+ sendATresponseString(AT_EVENT);
+ wait_ms(100);
+}
#define TESTING_HTTPS
//#define DONT_USE_TLS_SOCKET
@@ -978,27 +993,32 @@
#endif
dbg_printf(LOG, "\n[WIFI MAN] Http Request received:\n");
http_req_cfg = (http_request_t *) data_msg->buffer;
+#ifdef FULL_DEBUG_ENABLED
dbg_printf(LOG, "\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI);
dbg_printf(LOG, "\n[WIFI MAN] internet cfg url = %s\n", internet_config.url);
+#endif
char full_url[100];
char host[60] ;
strncpy(full_url,internet_config.url, strlen(internet_config.url)+1);
strncpy(host,http_req_cfg->hostName, strlen(http_req_cfg->hostName)+1);
strncat(full_url, http_req_cfg->request_URI, strlen(http_req_cfg->request_URI)+1);
+#ifdef FULL_DEBUG_ENABLED
dbg_printf(LOG, "\n[WIFI MAN] server url+uri = %s\n", full_url);
dbg_printf(LOG, "\n[WIFI MAN] Host = %s\n", http_req_cfg->hostName);
dbg_printf(LOG, "\n[WIFI MAN] Accept = %s\n", http_req_cfg->AcceptVal);
dbg_printf(LOG, "\n[WIFI MAN] Content-Type = %s\n", http_req_cfg->contentType);
dbg_printf(LOG, "\n[WIFI MAN] contentLenstr = %s\n", http_req_cfg->contentLen);
+#endif
int bodyLen;
sscanf(http_req_cfg->contentLen, "%d", &bodyLen);
+#ifdef FULL_DEBUG_ENABLED
dbg_printf(LOG, "contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen);
-
if(bodyLen > 10){
dbg_printf(LOG, "\n [WIFI MAN] Message Body:\n");
printBufferInHex(http_req_cfg->body, bodyLen);
}
+#endif
if(strstr(internet_config.url, "http:")!=NULL) // http request
{
http_request = new HttpRequest(network,
@@ -1007,7 +1027,7 @@
callback(this, &WiFiManager::body_callback));
setHttpHeader("Host", http_req_cfg->hostName);
setHttpHeader("Accept", http_req_cfg->AcceptVal);
- dbg_printf(LOG, "http_req_cfg->method = %d\n", http_req_cfg->method);
+ //dbg_printf(LOG, "http_req_cfg->method = %d\n", http_req_cfg->method);
if(http_req_cfg->method == HTTP_GET){
dbg_printf(LOG, "HTTP_GET -- ignoring body\n");
//setHttpHeader("Content-Type", http_req_cfg->contentType);
@@ -1033,6 +1053,9 @@
}
else
{
+ mbed_stats_heap_t heap_stats;
+ mbed_stats_heap_get(&heap_stats);
+ dbg_printf(LOG, "Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
#ifndef DONT_USE_TLS_SOCKET
if(https_connection_active == false){
bool tlsResult;
@@ -1067,6 +1090,9 @@
http_req_cfg->method,
full_url,
callback(this, &WiFiManager::body_callback));
+ responseString = (char *) malloc(100);
+ sprintf(responseString, "\r\nHTTP REQUEST OBJECT CREATED\r\n");
+ sendDebugMessage();
#else
https_request = new HttpsRequest(network,
SSL_CA_PEM,
@@ -1085,13 +1111,26 @@
http_response = https_request->send(NULL, 0);
}
else{
- dbg_printf(LOG, "about to setup https headers\r\n");
+ //dbg_printf(LOG, "about to setup https headers\r\n");
setHttpsHeader("Host", http_req_cfg->hostName);
setHttpsHeader("Accept", http_req_cfg->AcceptVal);
setHttpsHeader("Content-Type", http_req_cfg->contentType);
setHttpsHeader("Content-Length", http_req_cfg->contentLen);
dbg_printf(LOG, "https headers setup - about to send request\r\n");
- http_response = https_request->send(http_req_cfg->body, bodyLen);
+ // Grab the heap statistics
+ //mbed_stats_heap_t heap_stats;
+ //mbed_stats_heap_get(&heap_stats);
+ dbg_printf(LOG, "Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
+ responseString = (char *) malloc(200);
+ sprintf(responseString, "\r\nABOUT TO SEND HTTP REQUEST\r\n");
+ sendDebugMessage();
+ responseString = (char *) malloc(200);
+ sprintf(responseString, "Heap size= %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
+ sendDebugMessage();
+ https_request->send(http_req_cfg->body, bodyLen);
+ responseString = (char *) malloc(100);
+ sprintf(responseString, "\r\nRETURNED FROM SENDING HTTP REQUEST\r\n");
+ sendDebugMessage();
}
#else
setHttpsHeader("Host", http_req_cfg->hostName);
@@ -1100,14 +1139,12 @@
setHttpsHeader("Content-Length", http_req_cfg->contentLen);
http_response = https_request->send(http_req_cfg->body, bodyLen);
#endif
-
- //_wmutex.unlock();
- //free_DataMsg();
- if (!http_response) {
+ nsapi_error_t error = https_request->get_error();
+ if(error < 0)
+ {
char buf[100];
- mbedtls_strerror(https_request->get_error(), buf, 100);
- dbg_printf(LOG, "HttpsRequest failed (error code %s)\n", buf);
- http_result = HTTP_REQUEST_FAILED;
+ mbedtls_strerror(error, buf, 100);
+ printf("HttpsRequest failed (error code %s)\n", buf);
delete https_request; // free the memory
https_request = NULL;
https_connection_active = false; // reset true whenever connection fails
@@ -1115,29 +1152,16 @@
delete socket;
socket = NULL;
free_DataMsg();
+ http_result = HTTP_REQUEST_FAILED;
return false;
}
https_connection_active = true; // set true whenever connection succeeds
dbg_printf(LOG, "\n----- HTTPS POST response -----\r\n");
}
- if(http_response != NULL){
-
-#ifndef MIX_HDR_AND_BODY
- return_response(http_response);
-#else
- if(http_response_hdr_sent == false){ // if it failed to add to first chunk send separately
- return_response(http_response);
- }
-#endif
- //delete http_response; // free the response memory
- //http_response = NULL;
- //dbg_printf(LOG, "deleted http_response\r\n");
- }
free_DataMsg();
delete https_request; // free the request & response memory
dbg_printf(LOG, "deleted https_request\r\n");
https_request = NULL;
- http_response = NULL;
http_result = RESPONSE_OK;
return true;
}