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:
Thu May 09 13:21:12 2019 +0000
Branch:
PassingRegression
Parent:
109:c274780ff609
Child:
111:3ab1d9644835
Commit message:
added fix for case where no response is received to HTTPS request.

Changed in this revision

source/ATCmdManager.cpp 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/common_config.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/ATCmdManager.cpp	Wed May 08 19:38:35 2019 +0000
+++ b/source/ATCmdManager.cpp	Thu May 09 13:21:12 2019 +0000
@@ -110,8 +110,6 @@
         dequeueWiFidataResponse();
         updateWiFiMgrStatus();
         char * respStr;
-        //if(at_resp > AT_COMMAND_FAILED)
-        //return;
         switch(at_resp){
             case AT_RESP_NONE:
                 // IDLE response state
@@ -129,9 +127,6 @@
             case AT_DETAILED_SCAN_RESP:
                 // AT_DETAILED_SCAN_RESP response state
                 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n");
-                //_smutex.lock();
-                //sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
-                //_smutex.unlock();
                 respStr = (char *) resp_data->buffer;
                 sendAtConfirmationFreeMpool(respStr);
                 at_resp = AT_RESP_NONE;
@@ -364,6 +359,7 @@
 }
 bool ATCmdManager::createHttpRequest()
 {
+#ifdef USE_WIFI_STATE_CONTROL
     static int wifiBusyTimeOut = 0;
     if(wifiStateControl != AT_RESP_NONE && wifiBusyTimeOut < 10) // wifi busy!
     {
@@ -371,6 +367,7 @@
         return false;
     }
     wifiBusyTimeOut = 0;
+#endif
     http_request_t *http_req; // = new http_request_t;
     wifi_data_msg_t data_msg;
     http_req = (http_request_t *)data_msg.buffer;
@@ -502,6 +499,7 @@
     if(queueWiFiDataRequest(data_msg) == true)
     {
         wifiStateControl = AT_HTTPS_RESP_DOWNLOAD;
+        return true;
     }
     return true;
 }
@@ -552,9 +550,6 @@
                 {
                     //_parser.process_oob();
                     while (_parser.process_oob() && all) {
-                        if(debug_flag>0){
-                            dbg_printf(LOG, "finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n");
-                        }
                     }
                     break;
                 }
@@ -648,11 +643,7 @@
 #endif
         {
         while (_parser.process_oob() && all) {
-                        dbg_printf(LOG, "inbound message found... msgCnt = %d \r\n", ++msgCnt);
-                        if(debug_flag>0){
-                            dbg_printf(LOG, "finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n");
-                        }
-        }
+         }
         }
     }        
     set_timeout();
@@ -1199,7 +1190,7 @@
     if(wifiCmd == NULL){
         dbg_printf(LOG, "[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);
+        //_event_queue.call_in(10, &print_heap_and_isr_stack_info);
         //print_memory_info();
         //print_heap_and_isr_stack_info();
         return false;
@@ -1214,10 +1205,6 @@
 }
 
 bool  ATCmdManager::dequeueATresponse(){
-    if(debug_flag>0){
-        debug_flag--;
-        dbg_printf(LOG, "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){
@@ -1267,17 +1254,13 @@
 }
 
 bool  ATCmdManager::dequeueWiFidataResponse(){
-    if(debug_flag>0){
-        debug_flag--;
-        dbg_printf(LOG, "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);
         dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp);
-        _event_queue.call_in(10, &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;
@@ -1400,6 +1383,6 @@
     _wiFi2ATDatamPool->free(resp_data);
     resp_data = NULL;
     //print_memory_info();
-    _event_queue.call_in(10, &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/WiFiManager.cpp	Wed May 08 19:38:35 2019 +0000
+++ b/source/WiFiManager.cpp	Thu May 09 13:21:12 2019 +0000
@@ -309,12 +309,12 @@
     do
     {
         if(!queueResult){
-            wait_count++;
+            wait_count+=10;
             dbg_printf(LOG, "ATCMD Queue full waiting %d ms so far...\n", wait_count*10);
             wait_ms(10);
         }
         queueResult = queueWiFiDataResponse(*at_data_resp);
-    }while(queueResult == false);
+    }while(queueResult == false && wait_count<QUEUE_WAIT_TIMEOUT_MS);
     delete at_data_resp;
     at_data_resp = NULL;
 }                                            
@@ -335,12 +335,12 @@
     do
     {
         if(!queueResult){
-            wait_count++;
+            wait_count+=10;
             wait_ms(10);
             dbg_printf(LOG, "ATCMD Queue full waited %d ms so far...\n", wait_count*10);
         }
         queueResult = queueWiFiDataResponse(*at_data_resp);
-    }while(queueResult == false);
+    }while(queueResult == false && wait_count<QUEUE_WAIT_TIMEOUT_MS);
     delete at_data_resp;
     at_data_resp = NULL;
     dbg_printf(LOG, "[WIFI-MAN] sendATresponseBytes completed successfully\r\n");
@@ -985,9 +985,6 @@
     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);
@@ -1060,11 +1057,7 @@
     int stoptime;
     // reset chunk #;
     chunkNum = 0;
-#ifdef MIX_HDR_AND_BODY
     http_response_hdr_sent = false;
-#else
-    http_response_hdr_sent = true;
-#endif    
     dbg_printf(LOG, "\n[WIFI MAN] Http Request received:\n");
     http_req_cfg = (http_request_t *) data_msg->buffer;
 #ifdef FULL_DEBUG_ENABLED
@@ -1210,7 +1203,7 @@
             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);
+            http_response = https_request->send(http_req_cfg->body, bodyLen);
             responseString = (char *) malloc(100);
             sprintf(responseString, "\r\nRETURNED FROM SENDING HTTP REQUEST\r\n");
             sendDebugMessage();
@@ -1241,6 +1234,18 @@
         }
         https_connection_active = true; // set true whenever connection succeeds
         dbg_printf(LOG, "\n----- HTTPS POST response -----\r\n");
+    } 
+    if(http_response_hdr_sent == false)
+    {
+        socket->close();
+        delete socket;
+        https_connection_active = false; 
+#ifdef SEND_DEBUG_MESSAGES
+        responseString = (char *) malloc(100);
+        sprintf(responseString, "\r\n[WIFI-MAN] NO RESPONSE RECEIVED:: CLOSING CURRENT TLS CONNECTION.\r\n");
+        sendDebugMessage();
+#endif
+        //return_response(http_response);
     }
     free_DataMsg();
     delete https_request; // free the request & response memory
--- a/source/common_config.h	Wed May 08 19:38:35 2019 +0000
+++ b/source/common_config.h	Thu May 09 13:21:12 2019 +0000
@@ -41,6 +41,7 @@
 #define HTTP_HEADER_START_LINE    "HTTP/1.1 "
 #define HTTP_HEADER_CONTENT_TYPE  "Content-Type:"
 #define HTTP_HEADER_CONTENT_LEN   "Content-Length:"
+#define QUEUE_WAIT_TIMEOUT_MS     1000
 //#define ENABLE_MEMORY_CHECKS
 #define SEND_DEBUG_MESSAGES
 typedef enum