this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Revision:
89:45f6db09a76d
Parent:
88:7ffa053be662
Child:
90:ed0267eca7b5
--- a/source/WiFiManager.cpp	Sun Mar 31 22:09:45 2019 +0000
+++ b/source/WiFiManager.cpp	Mon Apr 01 08:00:41 2019 +0000
@@ -386,19 +386,29 @@
     }
     numChars = sprintf(msgPtr, "\r\n\r\n");
     msgPtr += numChars;
-    strncpy(msgPtr, res->get_body_as_string().c_str(), res->get_body_length()+1);
+    //strncpy(msgPtr, res->get_body_as_string().c_str(), res->get_body_length()+1);
     // print out generated header
     printf("generated response:\n");
     printf("%s\r\n", (char *)at_data_resp->buffer);
     //printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
-    at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer) + res->get_body_length();
+    at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
     //printf("WIFI MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
     // package and send on wifi data queue
     
     at_data_resp->at_resp = AT_HTTPS_RESP;
     //at_data_resp.at_data_resp = sizeof(wifi_config_t);
     //memcpy(at_data_resp.buffer, res, at_data_resp.dataLen);
-    queueWiFiDataResponse(*at_data_resp);
+    bool queueResult = true;
+    int wait_count = 0;
+    do
+    {
+        if(!queueResult){
+            wait_count++;
+            printf("ATCMD Queue full waiting %d ms so far...\n", wait_count*10);
+            wait_ms(10);
+        }
+        queueResult = queueWiFiDataResponse(*at_data_resp);
+    }while(queueResult == false);
     delete at_data_resp;
 }
 //#define TRY_PRINTF
@@ -430,14 +440,12 @@
 
     printf("\n\n");
     chunkNum++;
-    sendResponseDownloadData(AT_HTTPS_RESP, (uint8_t *)at, length);
+    sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
 
 
 bool WiFiManager::createTLSconnection(const char * hostName)
 {
-    printf("\n\nbefore TLS socket creation\n");
-    print_memory_info();
     socket = new TLSSocket();
     printf("\n\nafter TLS socket creation\n");
     print_memory_info();
@@ -448,11 +456,9 @@
     r = socket->open(network);
     if(r != NSAPI_ERROR_OK)
     { 
-        //printf("TLS open failed!!");
+        printf("TLS open failed!!\n");
         return false;
     }
-    printf("\n\nafter TLS socket opened\n");
-    print_memory_info();
     printf("TLS open passed!!\n");
     r = socket->set_root_ca_cert(SSL_CA_PEM);
     if(r != NSAPI_ERROR_OK)
@@ -460,8 +466,6 @@
         printf("TLS set_root_ca_cert failed!!\n");
         return false;
     }
-    printf("\n\nbefore set root passed\n");
-    print_memory_info();
     printf("TLS set_root_ca_cert passed!!\n");
     r = socket->connect(hostName, 443);
     if(r != NSAPI_ERROR_OK)
@@ -469,23 +473,18 @@
         printf("TLS connect failed for hostname %s!!\n", hostName);
         return false;
     }
-
-    printf("\n\nafter connection passed\n");
-    print_memory_info();
     printf("TLS connection successful for https site :  %s\n", hostName);
     return true;
 }
 #define TESTING_HTTPS
 void WiFiManager::createHttpsRequest()
 {
-    //printf("start of https request \n");
-    //print_memory_info();
     // reset chunk #;
     chunkNum = 0;
-    printf("\n[WIFI MAN] Http Request received:");
+    printf("\n[WIFI MAN] Http Request received:\n");
     http_req_cfg = (http_request_t *) data_msg->buffer;
-    printf("\n[WIFI MAN] uri = %s", http_req_cfg->request_URI.c_str());
-    printf("\n[WIFI MAN] internet cfg url = %s", internet_config.url);
+    printf("\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI.c_str());
+    printf("\n[WIFI MAN] internet cfg url = %s\n", internet_config.url);
     char full_url[100];
     char host[60] ;
     strncpy(full_url,internet_config.url, strlen(internet_config.url)+1);
@@ -502,10 +501,6 @@
     //printf("\n[WIFI MAN] server url = %s\n", internet_config.url.c_str());
     //const char* url = internet_config.url;
                                            
-    //printf("after http config processing\n");
-    //print_memory_info();
-    //    http_request = new HttpRequest(network, 
-    //   http_request = new HttpRequest(network, 
     int bodyLen;
     sscanf(http_req_cfg->contentLen.c_str(), "%d", &bodyLen);
     printf("contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen.c_str(), bodyLen);
@@ -518,7 +513,7 @@
                                          callback(this, &WiFiManager::body_callback));
         setHttpHeader("Host", http_req_cfg->hostName);
         setHttpHeader("Accept", http_req_cfg->AcceptVal);
-        printf("http_req_cfg->method = %d\n");
+        printf("http_req_cfg->method = %d\n", http_req_cfg->method);
         if(http_req_cfg->method == HTTP_GET){
             printf("HTTP_GET -- ignoring body\n");
             //setHttpHeader("Content-Type", http_req_cfg->contentType);
@@ -562,47 +557,43 @@
                                          full_url,
                                          callback(this, &WiFiManager::body_callback));
         
-        setHttpsHeader("Host", http_req_cfg->hostName);
-        setHttpsHeader("Accept", http_req_cfg->AcceptVal);
 #ifdef TESTING_HTTPS
         printf("http_req_cfg->method = %d\n");
         if(http_req_cfg->method == HTTP_GET){
             printf("HTTP_GET -- ignoring body\n");
+            setHttpsHeader("Host", http_req_cfg->hostName);
+            setHttpsHeader("Accept", http_req_cfg->AcceptVal);
             //setHttpHeader("Content-Type", http_req_cfg->contentType);
             //setHttpHeader("Content-Length", http_req_cfg->contentLen);
             http_response = https_request->send(NULL, 0);
         }
         else{
+            setHttpsHeader("Host", http_req_cfg->hostName);
+            setHttpsHeader("Accept", http_req_cfg->AcceptVal);
             setHttpHeader("Content-Type", http_req_cfg->contentType);
             setHttpHeader("Content-Length", http_req_cfg->contentLen);
             http_response = https_request->send(http_req_cfg->body, bodyLen);
         }
 #else
+        setHttpsHeader("Host", http_req_cfg->hostName);
+        setHttpsHeader("Accept", http_req_cfg->AcceptVal);
         setHttpHeader("Content-Type", http_req_cfg->contentType);
         setHttpHeader("Content-Length", http_req_cfg->contentLen);
         http_response = https_request->send(http_req_cfg->body, bodyLen);
 #endif        
         
         //_wmutex.unlock();
-        printf("after https request creation\n");
-        print_memory_info();
         free_DataMsg();
-        //printf("after https response and freeData alloc\n");
-        //print_memory_info();
         if (!http_response) {
             char buf[100];
             mbedtls_strerror(https_request->get_error(), buf, 100);
             printf("HttpsRequest failed (error code %s)\n", buf);
-            //printf("HttpsRequest failed (error code %d)\n", https_request->get_error());
             delete https_request; // free the memory
             https_connection_active = false; // reset true whenever connection fails
             delete socket;
             return;
         }
         https_connection_active = true; // set true whenever connection succeeds
-        //delete https_request; // free the memory
-        //printf("after https request deletion\n");
-        //print_memory_info();
         printf("\n----- HTTPS POST response -----\r\n");
    }
     return_response(http_response);