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

Dependencies:   mbed-http

Files at this revision

API Documentation at this revision

Comitter:
ocomeni
Date:
Sun Apr 21 13:06:41 2019 +0000
Parent:
97:0aa46e5ef15d
Child:
99:05398b3184f8
Commit message:
now working with to stage of 3 tries of hello msg

Changed in this revision

mbed-http.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
source/ATCmdManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/ATCmdManager.h Show annotated file Show diff for this revision Revisions of this file
source/WiFiManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/WiFiManager.h Show annotated file Show diff for this revision Revisions of this file
source/main-https.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/mbed-http.lib	Fri Apr 19 10:26:58 2019 +0000
+++ b/mbed-http.lib	Sun Apr 21 13:06:41 2019 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/sandbox/code/mbed-http/#fa4d71265625
+https://developer.mbed.org/teams/sandbox/code/mbed-http/#6daf67a96a91
--- a/mbed-os.lib	Fri Apr 19 10:26:58 2019 +0000
+++ b/mbed-os.lib	Sun Apr 21 13:06:41 2019 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#bf6f2c3c6434a6de9eb9511feffa5948b3d1f20f
+https://github.com/ARMmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48
--- a/mbed_app.json	Fri Apr 19 10:26:58 2019 +0000
+++ b/mbed_app.json	Sun Apr 21 13:06:41 2019 +0000
@@ -45,7 +45,6 @@
             "platform.stdio-convert-newlines": true,
             "mbed-trace.enable": 1,
             "mbed-http.http-buffer-size": 1024,
-            "tls-socket.debug-level": 1,
             "nsapi.default-wifi-security": "WPA_WPA2",
             "nsapi.default-wifi-ssid": "\"VM9109107_5GEXT\"",
             "nsapi.default-wifi-password": "\"Bonga01shop02\""
--- a/source/ATCmdManager.cpp	Fri Apr 19 10:26:58 2019 +0000
+++ b/source/ATCmdManager.cpp	Sun Apr 21 13:06:41 2019 +0000
@@ -54,7 +54,7 @@
     _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot));
     _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver));
     _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks));
-    _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigurationAction));
+    _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigAction));
     //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork));
     _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection));
     _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID));
@@ -68,8 +68,10 @@
     printf("\n --- ATCmdManager constructor completed ---\n");
     at_resp = AT_RESP_NONE;
     dataMode = AT_CMD_DATA_MODE;
-    print_heap_and_isr_stack_info();
-    event_queue.call_every(3600000,&print_memory_info);
+    debug_flag = 0;
+    _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+    //print_heap_and_isr_stack_info();
+    _event_queue.call_every(3600000,&print_memory_info);
 }
 
 
@@ -86,9 +88,19 @@
 void ATCmdManager::processResponses(){
         dequeueATresponse();
         dequeueWiFidataResponse();
+        if(debug_flag>0){
+            //debug_flag--;
+            printf(" back to ProcessResponses in Main loop... at_resp = %d\r\n", at_resp);
+        }
         char * respStr;
+        //if(at_resp > AT_COMMAND_FAILED)
+        //return;
         switch(at_resp){
             case AT_RESP_NONE:
+                if(debug_flag>0){
+                    debug_flag--;
+                    printf(" In IDLE state \r\n");
+                }
                 // IDLE response state
                 break;
             case AT_SCAN_RESP:
@@ -204,23 +216,25 @@
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_COMMAND_FAILED:  
+            {
                 // AT_HTTP_RESP response state 
                 printf("\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n");
                 //_smutex.lock();
                 //_parser.send("\r\nNACK\r\n");
                 //_smutex.unlock();
-                char * respStr = (char *) resp_data->buffer;
+                respStr = (char *) resp_data->buffer;
                 sendAtConfirmationFreeMpool(respStr);
-                AT_RESP_NONE;
+                at_resp = AT_RESP_NONE;
                 break;
-            default:
+            }
+            //default:
                 // UNKNOWN response state
                 //_smutex.lock();
-                printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
-                sendAtConfirmationFreeMpool(ERROR_RESP);   //_parser.send(OK_RESP);
+                //printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
+                //sendAtConfirmationFreeMpool(ERROR_RESP);   //_parser.send(OK_RESP);
                 //_smutex.unlock();
-                at_resp = AT_RESP_NONE;
-                break;
+                //at_resp = AT_RESP_NONE;
+                //break;
         }
 }
 
@@ -424,6 +438,9 @@
                 {
                     //_parser.process_oob();
                     while (_parser.process_oob() && all) {
+                        if(debug_flag>0){
+                            printf("finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n");
+                        }
                     }
                     break;
                 }
@@ -457,6 +474,7 @@
                             printf("DATA_EVENT received!\n");
                             break;
                         case DATA_COMMAND:
+                        {
                             printf("DATA_COMMAND received!\n");
                             sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
                             if(createHttpRequest() == true){
@@ -474,6 +492,7 @@
                             int stop = Kernel::get_ms_count();
                             printf("\n Time Elapsed = %d\n", stop-start);
                             break;
+                        }
                         case AT_REQUEST:
                             printf("AT_REQUEST received!\n");
                             break;
@@ -499,7 +518,12 @@
     else
     {
         // Poll for inbound packets
+        static int msgCnt = 0;
         while (_parser.process_oob() && all) {
+                        printf("inbound message found... msgCnt = %d \r\n", ++msgCnt);
+                        if(debug_flag>0){
+                            printf("finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n");
+                        }
         }
     }        
     set_timeout();
@@ -603,7 +627,8 @@
             case 2:
                 printf("\nATCmdParser: Extended data Mode request received\n");
                 dataMode = AT_EXT_DATA_MODE;
-                print_heap_and_isr_stack_info();
+                _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+                //print_heap_and_isr_stack_info();
                 break;
             default:
                 printf("\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n");
@@ -703,16 +728,17 @@
 
 
 
-void ATCmdManager::_oob_WiFiStationConfigurationAction()
+void ATCmdManager::_oob_WiFiStationConfigAction()
 {
-    uint8_t if_id; // interface id for request
-    action_id_t action_id; // interface id for request
-    _parser.scanf("%d,%d", &if_id, &action_id);
+    int if_id; // interface id for request
+    int aId; // interface id for request
+    _parser.recv("%d,%d", &if_id, &aId);
     //_smutex.lock();
-    printf("\n Received WiFi Configuration Action command!!\r\n");
+    printf("\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId);
     sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
-    if(if_id == WIFI_CONFIG_ID && (uint8_t)action_id <5){
+    if(if_id == WIFI_CONFIG_ID && aId <5){
         wifi_cmd_t cmd;
+        action_id_t action_id = (action_id_t) aId;
         switch(action_id){
             case WIFI_CONFIG_RESET:
                 break;
@@ -738,6 +764,9 @@
                 break;
         }
     }
+    if(debug_flag>0){
+        printf("finished queuing WIFI CONNECT CMD \r\n");
+    }
     return;
 }
 
@@ -989,19 +1018,27 @@
 #else
     wifi_cmd_message_t *wifiCmd = (wifi_cmd_message_t *) malloc(sizeof(wifi_cmd_message_t));
     if(wifiCmd == NULL){
-        printf("[ATCMD MAN] tr malloc() : queued memory allocation failed\n");
-        print_memory_info();
-        print_heap_and_isr_stack_info();
+        printf("[ATCMD MAN] try malloc() : queued memory allocation failed\n");
+        //_event_queue.call_in(10, &print_memory_info);
+        _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+        //print_memory_info();
+        //print_heap_and_isr_stack_info();
         return false;
     }
 #endif
     wifiCmd->wifi_cmd            = cmd;
     _aT2WiFiCmdQueue->put(wifiCmd);
     printf("[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd);
+    if((int)cmd == 5)
+    debug_flag = 3;
     return true;
 }
 
 bool  ATCmdManager::dequeueATresponse(){
+    if(debug_flag>0){
+        debug_flag--;
+        printf("Called dequeueATresponse after WIFI CONNECT CMD \r\n");
+    }
     if(at_resp != AT_RESP_NONE) return false; // busy
     osEvent evt = _wiFi2ATCmdQueue->get(0);
     if(evt.status == osEventMessage){
@@ -1020,7 +1057,8 @@
 
 bool  ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){
     //print_memory_info();
-    print_heap_and_isr_stack_info();
+    _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+    //print_heap_and_isr_stack_info();
     wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc();
     wifiData->wifi_cmd        = data_req.wifi_cmd;
     wifiData->dataLen        = data_req.dataLen;
@@ -1032,12 +1070,17 @@
 }
 
 bool  ATCmdManager::dequeueWiFidataResponse(){
+    if(debug_flag>0){
+        debug_flag--;
+        printf("Called dequeueWiFidataResponse after WIFI CONNECT CMD \r\n");
+    }
     if(at_resp != AT_RESP_NONE) return false; // busy
     osEvent evt = _wiFi2ATDataQueue->get(0);
     if(evt.status == osEventMessage){
         resp_data = (at_data_msg_t*)evt.value.p;
         setNextResponse(resp_data->at_resp);
-        print_heap_and_isr_stack_info();
+        _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+        //print_heap_and_isr_stack_info();
     }
     return true;
 }
@@ -1048,17 +1091,19 @@
     _smutex.lock();
     switch(dataMode){
         case AT_CMD_DATA_MODE:
-            _parser.send(buf);
+            _parser.send("%s", buf);
             break;
         case AT_STD_DATA_MODE:
-            _parser.send(buf);
+            _parser.send("%s", buf);
             break;
         case AT_EXT_DATA_MODE:
+        {
             int len =  strlen(buf);
             outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
             break;
+        }
         default:
-            _parser.send(buf);
+            _parser.send("%s", buf);
             break;
     }
     //wait_ms(1);
@@ -1078,9 +1123,9 @@
             int len =  strlen(buf);
             outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
             break;
-        default:
-            _parser.send(buf);
-            break;
+        //default:
+            //_parser.send(buf);
+            //break;
     }
     _smutex.unlock();
 }
@@ -1108,14 +1153,14 @@
     _parser.write((const char *)buf, pLen);
     // send EDM Message stop byte
     _parser.putc(EDM_STOP_BYTE);
+    _smutex.unlock();
     int msWait = (pLen + 5+20)/20;
     wait_ms(msWait);
-    _smutex.unlock();
 }
 
 void ATCmdManager::return_response(bool download) {
     char * resp = (char *) resp_data->buffer;
-    _smutex.lock();
+    //_smutex.lock();
     printf("\n[ATCMD MAN] received response:\n");
     if(download == false) // not download must be ascii header
     {
@@ -1128,9 +1173,10 @@
     //_parser.write(resp, resp_data->dataLen);
     outputEDMdata((const uint8_t *)resp, resp_data->dataLen, DATA_MSG_ID, 
                   EVENT_MSG_TYPE, WIFI_CHANNEL);
-    _smutex.unlock();
+    //_smutex.unlock();
     _wiFi2ATDatamPool->free(resp_data);
     resp_data = NULL;
     //print_memory_info();
-    print_heap_and_isr_stack_info();   
+    _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+    //print_heap_and_isr_stack_info();   
 }
--- a/source/ATCmdManager.h	Fri Apr 19 10:26:58 2019 +0000
+++ b/source/ATCmdManager.h	Sun Apr 21 13:06:41 2019 +0000
@@ -68,6 +68,7 @@
     at_data_msg_t *resp_data;
     edm_header_t   edm_hdr;
     uint8_t        *rx_buf_ptr;
+    int            debug_flag;
     
     // OOB processing
     void _process_oob(uint32_t timeout, bool all);
@@ -88,7 +89,7 @@
     void _oob_reboot();
     void _oob_get_fw_ver();
     void _oob_scanWiFiNetworks();
-    void _oob_WiFiStationConfigurationAction();
+    void _oob_WiFiStationConfigAction();
     void _oob_disconnectWiFiNetwork();
     void _oob_setupInternetConnection();
     void _oob_setWiFiSSID();
--- a/source/WiFiManager.cpp	Fri Apr 19 10:26:58 2019 +0000
+++ b/source/WiFiManager.cpp	Sun Apr 21 13:06:41 2019 +0000
@@ -3,6 +3,7 @@
 
 
 WiFiManager::WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, 
+                         events::EventQueue &event_queue, 
                          MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, 
                          Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 
                          MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 
@@ -14,6 +15,7 @@
 :
      wifi_config(wifi_config),
      network(wifi),
+    _event_queue(event_queue),
     _aT2WiFimPool(aT2WiFimPool),
     _aT2WiFiCmdQueue(aT2WiFiCmdQueue),
     
@@ -68,6 +70,7 @@
 
 void WiFiManager::runMain(){
     nsapi_error_t error;
+    bool httpReqResult;
     printf("\r\n [WIFI MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
     while(true){
         dequeueWiFiCommands();
@@ -82,12 +85,15 @@
                 queueATresponse(AT_SCAN_RESP);
                 break;
             case WIFI_CMD_DETAILED_SCAN:
+            {
                 nsapi_size_or_error_t cnt_err;
                 cnt_err = getAvailableAPs(lastScanCount);
                 wifiCmd = WIFI_CMD_NONE;
                 queueATresponse(AT_DETAILED_SCAN_RESP);
                 break;
+            }
             case WIFI_CMD_CONNECT:
+            {
                 error = connect();
                 int secCount = 0;
                 while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS || is_connected==false){
@@ -105,6 +111,7 @@
                     sendATresponseString(AT_CONNECT_RESP);
                 }
                 break;
+            }
             case WIFI_CMD_DISCONNECT:
                 error = disconnect();
                 wifiCmd = WIFI_CMD_NONE;
@@ -133,7 +140,11 @@
             case WIFI_CMD_SEND_HTTPS_REQ:
                 printf("before call to send http request \n");
                 print_memory_info();
-                createHttpsRequest();
+                httpReqResult = createHttpsRequest();
+                if(httpReqResult == false)
+                {
+                    sendATresponseString(AT_COMMAND_FAILED);
+                }
                 printf("after call to send http request \n");
                 print_memory_info();
                 wifiCmd = WIFI_CMD_NONE;
@@ -258,7 +269,7 @@
         //_smutex.lock();
         printf("[WIFI-MAN] scan() failed with return value: %d\n", count);
         //_smutex.unlock();
-        return;
+        return 0;
     }
     /* Limit number of network arbitrary to 15 */
     count = count < 15 ? count : 15;
@@ -266,7 +277,7 @@
     count = network->scan(ap, count);
     if (count <= 0) {
         printf("[WIFI-MAN] scan() failed with return value: %d\n", count);
-        return;
+        return 0;
     }
 
     for (int i = 0; i < count; i++) {
@@ -459,6 +470,12 @@
 
 void WiFiManager::status_callback(nsapi_event_t status, intptr_t param)
 {
+    printf("[WIFI-MAN] about call callback... \r\n");
+    _event_queue.call_in(50, this, &WiFiManager::status_callback_event, status, param);
+    //status_callback_event(status, param);
+}
+void WiFiManager::status_callback_event(nsapi_event_t status, intptr_t param)
+{
     //if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
     //}
     switch(param) {
@@ -526,6 +543,7 @@
     error = network->connect(wifi_config.ssid,
                      wifi_config.pass,
                      wifi_config.security);
+    printf("[WIFI-MAN] network->connect called. error = %d\r\n", error);
     return error;
 }
 
@@ -537,14 +555,15 @@
     return error;
 }
 
+#define MIX_HDR_AND_BODY
 void WiFiManager::sendResponseDownloadData(at_cmd_resp_t at_cmd, const uint8_t * buf, int bufLen)
 {    
 
-    printf("before call to new at_data_msg_t \n");
-    print_memory_info();
+    //printf("before call to new at_data_msg_t \n");
+    //print_memory_info();
     at_data_resp = new at_data_msg_t;
-    printf("after call to new at_data_msg_t \n");
-    print_memory_info();
+    //printf("after call to new at_data_msg_t \n");
+    //print_memory_info();
     at_data_resp->at_resp = at_cmd;
     size_t bufSize = sizeof(at_data_resp->buffer);
     int pos = 0;
@@ -559,11 +578,16 @@
             wait_ms(10);
         }
         else {            
-            if(http_response_hdr_sent == false){
-                copyResponseHdr2Queue();  
-                printf("[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
-                hdrLen =  at_data_resp->dataLen;
-                http_response_hdr_sent = true;        
+            if(http_response_hdr_sent == false && chunkNum==1){ // only do this for first chunk
+                bool status = copyResponseHdr2Queue();  
+                if(status == true){
+                    printf("[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
+                    hdrLen =  at_data_resp->dataLen;
+                    http_response_hdr_sent = true;  
+                } 
+                else {     
+                    printf("[WIFI-MAN] Http Response header copy failed\r\n");
+                }
             }
             int cpyLen = (bufLen - pos) > bufSize? bufSize : (bufLen - pos) ;
             printf("[WIFI-MAN] Http Response body [bytes = %d] \r\n",cpyLen);
@@ -582,48 +606,37 @@
     delete at_data_resp;
 }
 
-void WiFiManager::copyResponseHdr2Queue()
+bool WiFiManager::copyResponseHdr2Queue()
 {
     int numChars = 0;
     // create message pointer for response header generation
     char * msgPtr = (char *)at_data_resp->buffer;
     // do status line
+    printf("before getting HTTP status line\n");
     numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", http_response->get_status_code(), 
                                                      http_response->get_status_message().c_str());
-    printf("after getting HTTP status line \n");
-    print_memory_info();
     msgPtr += numChars;
-    //vector<string*> hdrFields(http_response->get_headers_fields());
-    //hdrFields.reserve(http_response->get_headers_length());
-    //printf("after defining HTTP header fields vector \r\n");
-    //hdrFields = http_response->get_headers_fields();
-    //printf("after getting HTTP header fields \n");
-    //print_memory_info();
-    //vector<string*> hdrValues(http_response->get_headers_values());
-    //printf("after getting HTTP header values \n");
-    //print_memory_info();
+    printf("before getting HTTP headers length\n");
+
     int hdrsLen = http_response->get_headers_length();
     printf("after getting HTTP headers length = %d\n", hdrsLen);
-    print_memory_info();
+    //print_memory_info();
+    if(hdrsLen <= 1)
+    {
+        printf("copy failed: Header Line = [%s]", msgPtr);
+        return false;
+    }
+    char * hdrField;
+    char * hdrValue;
     for (size_t ix = 0; ix < hdrsLen; ix++) {
         int sLen = http_response->get_headers_fields()[ix]->size()+1;
-        printf("before creating allocation HTTP headers field [size = %d] \n", sLen);
-        char * hdrField = (char *) malloc(sLen);
-        printf("after creating allocation HTTP headers field \n");
-        print_memory_info();
+        hdrField = new char [sLen];
         std::strcpy (hdrField, http_response->get_headers_fields()[ix]->c_str());
-        printf("after getting HTTP headers field copy \n");
-        print_memory_info();
-        char * hdrValue = new char [http_response->get_headers_values()[ix]->size()+1];
+        hdrValue = new char [sLen];
         std::strcpy (hdrValue, http_response->get_headers_values()[ix]->c_str());
         numChars = sprintf(msgPtr, "%s: %s\r\n", hdrField, hdrValue);
-        //numChars = sprintf(msgPtr, "%s: %s\r\n", 
-        //                   http_response->get_headers_fields()[ix]->c_str(), 
-        //                   http_response->get_headers_values()[ix]->c_str());
-        printf("after call #%d to get http header field:values \r\n", ix);
-        print_memory_info();
-        free(hdrField);
         delete hdrField;
+        delete hdrValue;
         msgPtr += numChars;
     }
     numChars = sprintf(msgPtr, "\r\n");
@@ -633,6 +646,7 @@
     printf("%s\r\n", (char *)at_data_resp->buffer);
     // calculate header length 
     at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
+    return true;
 }
 
 void WiFiManager::return_response(HttpResponse* res) {
@@ -712,6 +726,7 @@
     r = socket->set_root_ca_cert(SSL_CA_PEM);
     if(r != NSAPI_ERROR_OK)
     { 
+        socket->close();
         printf("TLS set_root_ca_cert failed!!\n");
         return false;
     }
@@ -729,8 +744,9 @@
     return true;
 }
 #define TESTING_HTTPS
+
 //#define DONT_USE_TLS_SOCKET
-void WiFiManager::createHttpsRequest()
+bool WiFiManager::createHttpsRequest()
 {
     // reset chunk #;
     chunkNum = 0;
@@ -789,7 +805,7 @@
             printf("HttpRequest failed (error code %s)\n", buf);
             //printf("HttpsRequest failed (error code %d)\n", https_request->get_error());
             delete http_request; // free the memory
-            return;
+            return false;
         }
         delete http_request; // free the memory
         printf("\n----- HTTP POST response -----\n");
@@ -805,12 +821,14 @@
 #endif
             if(tlsResult == false){
                  delete socket;
+                 printf("TLS Socket connection failed - deleting data msg\r\n");
                  free_DataMsg();
-                 return;
+                 printf("data msg deleted \r\n");
+                 return false;
             }
             //printf("[create https] TLS connection successful for https site :  %s\n", host);
-            printf("after call to createTLSconnection \n");
-            print_memory_info();
+            //printf("after call to createTLSconnection \n");
+            //print_memory_info();
         }        
         // Pass in `socket`, instead of `network` as first argument, and omit the `SSL_CA_PEM` argument
         //HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418");
@@ -843,6 +861,18 @@
             setHttpsHeader("Content-Type", http_req_cfg->contentType);
             setHttpsHeader("Content-Length", http_req_cfg->contentLen);
             printf("https headers setup - about to send request\r\n");
+            mbedtls_ssl_context* tlsContext ;
+            tlsContext = socket->get_ssl_context();
+            mbedtls_ssl_config * tlsConfig;
+            tlsConfig = socket->get_ssl_config();
+            if(tlsContext != NULL)
+            {
+                printf("current TLS tlsContext is not null [%d] \r\n", tlsContext->state);
+            }
+            else
+            {
+                printf("TLS Context is NULL \r\n");
+            }
             //_wmutex.lock();
             http_response = https_request->send(http_req_cfg->body, bodyLen);
             //_wmutex.unlock();
@@ -864,10 +894,11 @@
             delete https_request; // free the memory
             https_request = NULL;
             https_connection_active = false; // reset true whenever connection fails
+            socket->close();
             delete socket;
             socket = NULL;
             free_DataMsg();
-            return;
+            return false;
         }
         https_connection_active = true; // set true whenever connection succeeds
         printf("\n----- HTTPS POST response -----\r\n");
@@ -876,6 +907,10 @@
 
 #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;
@@ -885,6 +920,7 @@
     delete https_request; // free the request & response memory
     printf("deleted https_request\r\n");
     https_request = NULL;
+    return true;
 }
 
 void WiFiManager::createHttpRequest(http_method method,
--- a/source/WiFiManager.h	Fri Apr 19 10:26:58 2019 +0000
+++ b/source/WiFiManager.h	Sun Apr 21 13:06:41 2019 +0000
@@ -20,6 +20,7 @@
 class WiFiManager {
 public:
     WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, 
+                events::EventQueue &event_queue, 
                 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, 
                 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 
                 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 
@@ -31,13 +32,14 @@
     ~WiFiManager();
     void                  runMain();
     void                  status_callback(nsapi_event_t status, intptr_t param);
-    
 
 
 private:
     Mutex _wmutex; // Protect wifi thread
     wifi_config_t     wifi_config;
     internet_config_t internet_config;
+    // define event queue
+    events::EventQueue &_event_queue;
     WiFiInterface *network;
     HttpsRequest* https_request;
     HttpRequest* http_request;
@@ -80,7 +82,7 @@
     void                  set_internet_config();
     nsapi_error_t         connect();
     nsapi_error_t         disconnect();
-    void                  createHttpsRequest();
+    bool                  createHttpsRequest();
     void                  createHttpRequest(http_method method,
                                           const char* url,
                                           Callback<void(const char *at, uint32_t length)> body_callback = 0
@@ -103,10 +105,11 @@
                                                                 int bufLen);
     bool                  createTLSconnection(const char *hostName);
     void                  printBufferInHex(uint8_t *buf, int pLen);
-    void                  copyResponseHdr2Queue();
+    bool                  copyResponseHdr2Queue();
     void                  sendATresponseString(at_cmd_resp_t);
     void                  getNetworkStatus();
     void                  getWiFiStatus();
+    void                  status_callback_event(nsapi_event_t status, intptr_t param);    
 
 
     /**
--- a/source/main-https.cpp	Fri Apr 19 10:26:58 2019 +0000
+++ b/source/main-https.cpp	Sun Apr 21 13:06:41 2019 +0000
@@ -446,6 +446,7 @@
         printf("ERROR: No WiFiInterface found.\n");
     }
     wiFiManager = new WiFiManager(wifi_config, network, 
+                                  eventQueue,
                                   &aT2WiFimPool, &aT2WiFiCmdQueue,
                                   &wiFi2ATmPool, &wiFi2ATCmdQueue,
                                   &aT2WiFiDatamPool, &aT2WiFiDataQueue,
@@ -538,6 +539,8 @@
     printf("\r\n after starting wifi thread \r\n");
     print_memory_info();
     // dispatch event queue on event thread
+    printf("\r\n [MAIN THREAD]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
+    printf("\r\n [EVENT THREAD]  Thread Id = %X\r\n", (uint32_t)evt_thread.get_id());
     evt_thread.start(callback(&eventQueue, &EventQueue::dispatch_forever));
     device->printf("\r\n++++++ Starting ATCmdmanager ++++++ \r\n");
     ATCmdManager *aTCmdManager = new ATCmdManager(USBTX, USBRX, peripheral,