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:
Fri Mar 29 22:18:33 2019 +0000
Parent:
86:04fc2fcda7ec
Child:
88:7ffa053be662
Commit message:
http/https request and response implemented

Changed in this revision

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/BleManager.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/WiFiManager.h 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
source/common_types.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/source/ATCmdManager.cpp	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/ATCmdManager.cpp	Fri Mar 29 22:18:33 2019 +0000
@@ -10,10 +10,10 @@
                            Queue<wifi_cmd_message_t, 16>      *aT2WiFiCmdQueue, 
                            MemoryPool<at_resp_message_t, 16>  *wiFi2ATmPool, 
                            Queue<at_resp_message_t, 16>       *wiFi2ATCmdQueue, 
-                           MemoryPool<wifi_data_msg_t, 4>     *aT2WiFiDatamPool, 
-                           Queue<wifi_data_msg_t, 4>          *aT2WiFiDataQueue, 
-                           MemoryPool<at_data_msg_t, 4>       *wiFi2ATDatamPool, 
-                           Queue<at_data_msg_t, 4>            *wiFi2ATDataQueue, 
+                           MemoryPool<wifi_data_msg_t, PQDSZ>     *aT2WiFiDatamPool, 
+                           Queue<wifi_data_msg_t, PQDSZ>          *aT2WiFiDataQueue, 
+                           MemoryPool<at_data_msg_t, PQDSZ>       *wiFi2ATDatamPool, 
+                           Queue<at_data_msg_t, PQDSZ>            *wiFi2ATDataQueue, 
                            bool debug)
     :
     _serial(tx, rx, DEFAULT_BAUD_RATE),
@@ -68,12 +68,14 @@
     printf("\n --- ATCmdManager constructor completed ---\n");
     at_resp = AT_RESP_NONE;
     dataMode = AT_CMD_DATA_MODE;
+    event_queue.call_every(120000,&print_memory_info);
     //AT+UMRS=230400,2,8,1,1,1
     // AT+UBTLE
 }
 
 
 void ATCmdManager::runMain(){
+    printf("\r\n [ATCMD MAN]  Thread Id = %d\r\n", Thread::gettid());
     while(true){
         _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true);
         wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time 
@@ -84,6 +86,7 @@
 
 void ATCmdManager::processResponses(){
         dequeueATresponse();
+        dequeueWiFidataResponse();
         switch(at_resp){
             case AT_RESP_NONE:
                 // IDLE response state
@@ -140,6 +143,7 @@
                 // AT_HTTP_RESP response state 
                 //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n");
+                return_response();
                 _parser.send("OK\n");
                 //////_smutex.unlock();
                 at_resp = AT_RESP_NONE;
@@ -198,6 +202,8 @@
 bool ATCmdManager::createHttpRequest()
 {
     http_request_t http_req;
+    printf("\nsizeof(http_req) on creation = %d\n", sizeof(http_req));
+
     char s1[32];
     char s2[32];
     char s3[32];
@@ -254,6 +260,8 @@
     // package and send on wifi data queue
     wifi_data_msg_t data_msg;
     data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ;
+    printf("\nsizeof(http_req) on population = %d\n", sizeof(http_req));
+/*
     data_msg.dataLen = sizeof(http_req.method) + 
                        sizeof(http_req.body) + 
                        http_req.request_URI.capacity() +
@@ -262,6 +270,15 @@
                        http_req.AcceptVal.capacity() +
                        http_req.contentType.capacity() +
                        http_req.contentLen.capacity();
+*/
+    data_msg.dataLen = sizeof(http_req.method) + 
+                       sizeof(http_req.body) + 
+                       http_req.request_URI.size() +
+                       http_req.http_version.size() + 
+                       http_req.hostName.size() +
+                       http_req.AcceptVal.size() +
+                       http_req.contentType.size() +
+                       http_req.contentLen.size();
     memcpy(data_msg.buffer,&http_req, data_msg.dataLen);
     // queue next data request
     queueWiFiDataRequest(data_msg);
@@ -275,7 +292,7 @@
     if(dataMode == AT_EXT_DATA_MODE)
     {
         int n;
-        if(cnt++ % 10 == 0)printf("In EDM mode\n");
+        //if(cnt++ % 10 == 0)printf("In EDM mode\n");
         uint8_t edm[EDM_HDR_LEN];
         
         // Poll for edm packets
@@ -308,7 +325,7 @@
                     printf("%d bytes read - expected %d!\n", n, pLen);
                     for(int i =0;i<pLen;i++){
                         if(i%8==0) printf("\n[%3d]",i/8);
-                        printf("%2x ", rx_buf_ptr[i]);
+                        printf("%02x ", rx_buf_ptr[i]);
                     }
                     printf("\n");
                     printf("rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]);
@@ -782,7 +799,7 @@
     return true;
 }
 
-bool  ATCmdManager::dequeueATdataResponse(){
+bool  ATCmdManager::dequeueWiFidataResponse(){
     if(at_resp != AT_RESP_NONE) return false; // busy
     osEvent evt = _wiFi2ATDataQueue->get(0);
     if(evt.status == osEventMessage){
@@ -794,4 +811,10 @@
 }
 
 
-
+void ATCmdManager::return_response() {
+    char * resp = (char *) resp_data->buffer;
+    printf("\n[ATCMD MAN] received response:\n");
+    printf("%s\r\n", (char *)resp);
+    _wiFi2ATDatamPool->free(resp_data);
+    
+}
--- a/source/ATCmdManager.h	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/ATCmdManager.h	Fri Mar 29 22:18:33 2019 +0000
@@ -22,10 +22,10 @@
                  Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 
                  MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 
                  Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, 
-                 MemoryPool<wifi_data_msg_t, 4> *aT2WiFiDatamPool, 
-                 Queue<wifi_data_msg_t, 4> *aT2WiFiDataQueue, 
-                 MemoryPool<at_data_msg_t, 4> *wiFi2ATDatamPool, 
-                 Queue<at_data_msg_t, 4> *wiFi2ATDataQueue, 
+                 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, 
+                 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, 
+                 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, 
+                 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue, 
                  bool debug = false);
 public:
     void runMain();
@@ -54,13 +54,13 @@
     Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
     
     /*  Queue and memory pool for AT to WiFi data */
-    MemoryPool<wifi_data_msg_t, 4> *_aT2WiFiDatamPool;
-    Queue<wifi_data_msg_t, 4> *_aT2WiFiDataQueue;
+    MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
+    Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
     
     
     /*  Queue and memory pool for WiFi to AT data */
-    MemoryPool<at_data_msg_t, 4> *_wiFi2ATDatamPool;
-    Queue<at_data_msg_t, 4> *_wiFi2ATDataQueue;
+    MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
+    Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
     
     //pointer to response data - should be deleted after processing
     at_data_msg_t *resp_data;
@@ -95,17 +95,18 @@
     void _oob_sendHttpMessage();
     wifi_config_t init_wifi_config();
     const char * sec2str(nsapi_security_t sec);
-    bool  queueWiFiCommand(wifi_cmd_t cmd);
-    bool  dequeueATresponse();
-    bool  queueWiFiDataRequest(wifi_data_msg_t cmd);
-    bool  dequeueATdataResponse();
-    void  processResponses();
-    bool  setNextResponse(at_cmd_resp_t resp);    
-    int   ReadBytes(uint8_t *buf, int maxBytes);
-    int   readStringBytes(uint8_t *buf, int maxBytes);
-    bool  validate(edm_header_t edm_header);
-    bool  createHttpRequest();
+    bool        queueWiFiCommand(wifi_cmd_t cmd);
+    bool        dequeueATresponse();
+    bool        queueWiFiDataRequest(wifi_data_msg_t cmd);
+    bool        dequeueWiFidataResponse();
+    void        processResponses();
+    bool        setNextResponse(at_cmd_resp_t resp);    
+    int         ReadBytes(uint8_t *buf, int maxBytes);
+    int         readStringBytes(uint8_t *buf, int maxBytes);
+    bool        validate(edm_header_t edm_header);
+    bool        createHttpRequest();
     http_method str2HttpMethod(const char * methodStr);
+    void        return_response(); 
 
     
     /**
--- a/source/BleManager.cpp	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/BleManager.cpp	Fri Mar 29 22:18:33 2019 +0000
@@ -78,6 +78,8 @@
 /** Start BLE interface initialisation */
 void SMDevice::run()
 {
+    printf("\r\n [BTLE MAN]  Thread Id = %d\r\n", Thread::gettid());
+
     ble_error_t error;
 
     /* to show we're running we'll blink every 500ms */
--- a/source/WiFiManager.cpp	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/WiFiManager.cpp	Fri Mar 29 22:18:33 2019 +0000
@@ -7,10 +7,10 @@
                          Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 
                          MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 
                          Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, 
-                         MemoryPool<wifi_data_msg_t, 4> *aT2WiFiDatamPool, 
-                         Queue<wifi_data_msg_t, 4> *aT2WiFiDataQueue, 
-                         MemoryPool<at_data_msg_t, 4> *wiFi2ATDatamPool, 
-                         Queue<at_data_msg_t, 4> *wiFi2ATDataQueue) 
+                         MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, 
+                         Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, 
+                         MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, 
+                         Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue) 
 :
      wifi_config(wifi_config),
      network(wifi),
@@ -52,6 +52,7 @@
     atData->dataLen        = at_resp.dataLen;
     memcpy(atData->buffer, at_resp.buffer, at_resp.dataLen);
     _wiFi2ATDataQueue->put(atData);
+    printf("[WIFI MAN] queued data size = %d : at_resp = %d\n", at_resp.dataLen, at_resp.at_resp);
     return true;
 }
 
@@ -59,6 +60,7 @@
 
 void WiFiManager::runMain(){
     nsapi_error_t error;
+    printf("\r\n [WIFI MAN]  Thread Id = %d\r\n", Thread::gettid());
     while(true){
         dequeueWiFiCommands();
         dequeueATdataResponse();
@@ -323,29 +325,6 @@
                      wifi_config.pass,
                      wifi_config.security);
     return error;
-    /*
-    if(error)
-    {
-        printf("\n [WIFI-MAN] Could not connect to Wifi -- aborting!! - \n");
-        return error;
-    }
-    nsapi_connection_status_t conn_status = NSAPI_STATUS_CONNECTING;
-    int loopCount = 0;
-    while(conn_status == NSAPI_STATUS_CONNECTING){
-        loopCount++;
-        conn_status = network->get_connection_status();
-        printf("\n [WIFI-MAN] Waiting for WiFi network connect to complete asynchronously [status = %d] - %d\n", conn_status, loopCount);
-        wait(0.1);
-    }
-    if(conn_status < 0)
-    {
-        printf("\n [WIFI-MAN] Error connecting to Wifi -- %d!! - \n", conn_status);
-        return conn_status;
-    }
-    printf("[WIFI-MAN] Connected to the network %s\n", wifi_config.ssid);
-    printf("[WIFI-MAN] IP address: %s\n", network->get_ip_address());
-    return conn_status;
-    */
 }
 
 
@@ -357,49 +336,46 @@
 }
 
 
-/*
 
-        HttpsRequest(NetworkInterface* network,
-                 const char* ssl_ca_pem,
-                 http_method method,
-                 const char* url,
-                 Callback<void(const char *at, uint32_t length)> body_callback = 0)
-       HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://os.mbed.com/media/uploads/mbed_official/hello.txt", &dump_chunked_response);
-    HttpRequest(NetworkInterface* network, http_method method, const char* url, Callback<void(const char *at, uint32_t length)> bodyCallback = 0)
-        post_req->set_header("Content-Type", "application/json");
-        HttpResponse* get_res = get_req->send();
-
-        const char body[] = "{\"hello\":\"world\"}";
-
-        HttpResponse* post_res = post_req->send(body, strlen(body));
-
-
-*/
 void WiFiManager::return_response(HttpResponse* res) {
     
     //queueWiFiDataResponse(at_data_msg_t at_data_resp);
-    printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
-    printf("Headers:\n");
+    
     at_data_msg_t at_data_resp; 
+    int numChars = 0;
+    // create message pointer for response header generation
+    char * msgPtr = (char *)at_data_resp.buffer;
+    // do status line
+    numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", res->get_status_code(), res->get_status_message().c_str());
+    msgPtr += numChars;
     //at_data_resp = &at_data;
-    at_data_resp.dataLen = sizeof(res); // start with minimum size of response
+    at_data_resp.dataLen = sizeof(*res); // start with minimum size of response
     for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
-        printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
-        at_data_resp.dataLen+= res->get_headers_fields()[ix]->size();
-        at_data_resp.dataLen+= res->get_headers_values()[ix]->size();
+        numChars = sprintf(msgPtr, "%s: %s\r\n", 
+                           res->get_headers_fields()[ix]->c_str(), 
+                           res->get_headers_values()[ix]->c_str());
+        msgPtr += numChars;
     }
-    at_data_resp.dataLen+= res->get_body_length();
-    printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+    numChars = sprintf(msgPtr, "\r\n\r\n");
+    msgPtr += numChars;
+    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();
     //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);
+    //memcpy(at_data_resp.buffer, res, at_data_resp.dataLen);
     queueWiFiDataResponse(at_data_resp);
+    
+    delete res;
 
 }
-
+#define TRY_PRINTF
 
 void WiFiManager::body_callback(const char *at, uint32_t length) {
     
@@ -420,47 +396,89 @@
         if((ix % 32) == 0 and ix)
         printf("\n");
     }
+#ifdef TRY_PRINTF
+    printf("%s\n", at);
+#endif    
+
     printf("\n\n");
     chunkNum++;
-    //device->printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
 }
 
 void WiFiManager::createHttpsRequest()
 {
-    
-    //http_method method,
-    //Callback<void(const char *at, uint32_t length)> body_callback = 0
+    // reset chunk #;
+    chunkNum = 0;
     printf("\n[WIFI MAN] Http Request received:");
     http_req_cfg = (http_request_t *) data_msg->buffer;
     printf("\n[WIFI MAN] uri = %s", http_req_cfg->request_URI.c_str());
-    strncat(internet_config.url, http_req_cfg->request_URI.c_str(), http_req_cfg->request_URI.size());
-    printf("\n[WIFI MAN] server url = %s\n", internet_config.url);
+    printf("\n[WIFI MAN] internet cfg url = %s", internet_config.url);
+    char full_url[100];
+    strncpy(full_url,internet_config.url, strlen(internet_config.url)+1);
+    printf("\n[WIFI MAN] server url = %s\n", full_url);
+    //strncat(internet_config.url, http_req_cfg->request_URI.c_str(), http_req_cfg->request_URI.size());
+    strncat(full_url, http_req_cfg->request_URI.c_str(), http_req_cfg->request_URI.size());
+    //printf("\n[WIFI MAN] server url = %s\n", internet_config.url);
+    printf("\n[WIFI MAN] server url+uri = %s\n", full_url);
+    printf("\n[WIFI MAN] Host = %s\n", http_req_cfg->hostName.c_str());
+    printf("\n[WIFI MAN] Accept = %s\n", http_req_cfg->AcceptVal.c_str());
+    printf("\n[WIFI MAN] Content-Type = %s\n", http_req_cfg->contentType.c_str());
     printf("\n[WIFI MAN] contentLenstr = %s\n", http_req_cfg->contentLen.c_str());
     //printf("\n[WIFI MAN] server url = %s\n", internet_config.url.c_str());
     //const char* url = internet_config.url;
                                            
+    print_memory_info();
     //    http_request = new HttpRequest(network, 
-    //https_request = new HttpsRequest(network, 
-    http_request = new HttpRequest(network, 
-                                     //SSL_CA_PEM, 
-                                     http_req_cfg->method, 
-                                     internet_config.url,
-                                     callback(this, &WiFiManager::body_callback));
-    setHttpHeader("Host", http_req_cfg->hostName);
-    setHttpHeader("Accept", http_req_cfg->AcceptVal);
-    setHttpHeader("Content-Type", http_req_cfg->contentType);
-    setHttpHeader("Content-Length", http_req_cfg->contentLen);
+    //   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);
-    http_response = https_request->send(http_req_cfg->body, bodyLen);
-    free_DataMsg();
-    if (!http_response) {
-        printf("HttpRequest failed (error code %d)\n", https_request->get_error());
-        return;
+    if(strstr(internet_config.url, "http:")!=NULL) // http request
+    {
+        http_request = new HttpRequest(network,  
+                                         //SSL_CA_PEM, 
+                                         http_req_cfg->method, 
+                                         internet_config.url,
+                                         callback(this, &WiFiManager::body_callback));
+        setHttpHeader("Host", http_req_cfg->hostName);
+        setHttpHeader("Accept", http_req_cfg->AcceptVal);
+        setHttpHeader("Content-Type", http_req_cfg->contentType);
+        setHttpHeader("Content-Length", http_req_cfg->contentLen);
+        http_response = http_request->send(http_req_cfg->body, bodyLen);
+        free_DataMsg();
+        if (!http_response) {
+            char buf[100];
+            mbedtls_strerror(http_request->get_error(), buf, 100);
+            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;
+        }
+        printf("\n----- HTTP POST response -----\n");
     }
-
-    printf("\n----- HTTPS POST response -----\n");
+    else
+    {
+        https_request = new HttpsRequest(network, 
+                                         SSL_CA_PEM, 
+                                         http_req_cfg->method, 
+                                         internet_config.url,
+                                         callback(this, &WiFiManager::body_callback));
+        
+        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);
+        http_response = https_request->send(http_req_cfg->body, bodyLen);
+        free_DataMsg();
+        if (!http_response) {
+            char buf[100];
+            mbedtls_strerror(https_request->get_error(), buf, 100);
+            printf("HttpRequest failed (error code %s)\n", buf);
+            //printf("HttpsRequest failed (error code %d)\n", https_request->get_error());
+            delete https_request; // free the memory
+            return;
+        }
+        printf("\n----- HTTPS POST response -----\r\n");
+   }
     return_response(http_response);
 }
 
--- a/source/WiFiManager.h	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/WiFiManager.h	Fri Mar 29 22:18:33 2019 +0000
@@ -16,7 +16,7 @@
 #include "https_certificates.h"
 #include "common_types.h"
 
-
+extern void print_memory_info();
 class WiFiManager {
 public:
     WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, 
@@ -24,10 +24,10 @@
                 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 
                 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 
                 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, 
-                MemoryPool<wifi_data_msg_t, 4> *aT2WiFiDatamPool, 
-                Queue<wifi_data_msg_t, 4> *aT2WiFiDataQueue, 
-                MemoryPool<at_data_msg_t, 4> *wiFi2ATDatamPool, 
-                Queue<at_data_msg_t, 4> *wiFi2ATDataQueue); 
+                MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, 
+                Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, 
+                MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, 
+                Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue); 
     ~WiFiManager();
     void                  runMain();
     void                  status_callback(nsapi_event_t status, intptr_t param);
@@ -55,13 +55,13 @@
     Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
     
     /*  Queue and memory pool for AT to WiFi data */
-    MemoryPool<wifi_data_msg_t, 4> *_aT2WiFiDatamPool;
-    Queue<wifi_data_msg_t, 4> *_aT2WiFiDataQueue;
+    MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
+    Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
     wifi_data_msg_t *data_msg;
     
     /*  Queue and memory pool for WiFi to AT data */
-    MemoryPool<at_data_msg_t, 4> *_wiFi2ATDatamPool;
-    Queue<at_data_msg_t, 4> *_wiFi2ATDataQueue;
+    MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
+    Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
 
     bool is_connected;
     
--- a/source/common_config.h	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/common_config.h	Fri Mar 29 22:18:33 2019 +0000
@@ -12,6 +12,7 @@
 #define UBLOX_ODIN_W2_RECV_TIMEOUT    100
 #endif
 
+#define PQDSZ   2  // size of Pool/Queue data structures
 const uint8_t hello_msg[] = {0xaa,0x00,0x96,0x00,0x36,0x00,0x50,0x4f
                             ,0x53,0x54,0x20,0x2f,0x6e,0x75,0x64,0x67
                             ,0x65,0x62,0x6f,0x78,0x2f,0x76,0x31,0x20
--- a/source/common_types.h	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/common_types.h	Fri Mar 29 22:18:33 2019 +0000
@@ -120,12 +120,12 @@
 
 typedef struct {
     http_method   method;       /* POST/GET etc... */
-    string        request_URI;  /* request URI/path */
-    string        http_version; /* http verstion HTTP/1.1 */
-    string        hostName;     /* host name */
-    string        AcceptVal;    /* types accepted */
-    string        contentType;  /* content type */
-    string        contentLen;   /* content length as string   */
+    std::string   request_URI;  /* request URI/path */
+    std::string   http_version; /* http verstion HTTP/1.1 */
+    std::string   hostName;     /* host name */
+    std::string   AcceptVal;    /* types accepted */
+    std::string   contentType;  /* content type */
+    std::string   contentLen;   /* content length as string   */
     uint8_t       body[900];    /* body     */
 } http_request_t;
 
--- a/source/main-https.cpp	Thu Mar 28 23:41:10 2019 +0000
+++ b/source/main-https.cpp	Fri Mar 29 22:18:33 2019 +0000
@@ -45,29 +45,31 @@
 const static char     DEVICE_NAME_MAIN[] = "UBLOX-BLE";
 static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID};
 char buffer[BUFFER_LEN];
+#ifdef ENABLE_UART_BACKGRND_DEMO
 uint8_t TxBuffer[TX_BUFFER_LEN];
 uint8_t RxBuffer[RX_BUFFER_LEN];
+#endif
 static EventQueue eventQueue(/* event count */ 20 * EVENTS_EVENT_SIZE);
 //static EventQueue eventQueue2(/* event count */ 10 * EVENTS_EVENT_SIZE);
 
 LEDService *ledServicePtr;
 
 /*  Queue and memory pool for AT to Wifi commands */
-static MemoryPool<wifi_cmd_message_t, 16> aT2WiFimPool;
-static Queue<wifi_cmd_message_t, 16> aT2WiFiCmdQueue;
+MemoryPool<wifi_cmd_message_t, 16> aT2WiFimPool;
+Queue<wifi_cmd_message_t, 16> aT2WiFiCmdQueue;
 
 /*  Queue and memory pool for WiFi to AT commands */
-static MemoryPool<at_resp_message_t, 16> wiFi2ATmPool;
-static Queue<at_resp_message_t, 16> wiFi2ATCmdQueue;
+MemoryPool<at_resp_message_t, 16> wiFi2ATmPool;
+Queue<at_resp_message_t, 16> wiFi2ATCmdQueue;
 
 /*  Queue and memory pool for AT to WiFi data */
-static MemoryPool<wifi_data_msg_t, 4> aT2WiFiDatamPool;
-static Queue<wifi_data_msg_t, 4> aT2WiFiDataQueue;
+MemoryPool<wifi_data_msg_t, PQDSZ> aT2WiFiDatamPool;
+Queue<wifi_data_msg_t, PQDSZ> aT2WiFiDataQueue;
 
 
 /*  Queue and memory pool for WiFi to AT data */
-static MemoryPool<at_data_msg_t, 4> wiFi2ATDatamPool;
-static Queue<at_data_msg_t, 4> wiFi2ATDataQueue;
+MemoryPool<at_data_msg_t, PQDSZ> wiFi2ATDatamPool;
+Queue<at_data_msg_t, PQDSZ> wiFi2ATDataQueue;
 
 
 
@@ -92,9 +94,9 @@
 Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 4*1024, &atcmd_stk[0]);
 #else
 // using global heap
-Thread btle_thread(BTLE_THREAD_PRIORITY, 2*1024);
-Thread wifi_thread(WIFI_THREAD_PRIORITY, 8*1024);
-Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 8*1024);
+Thread btle_thread(BTLE_THREAD_PRIORITY, 1024);
+Thread wifi_thread(WIFI_THREAD_PRIORITY, 4*1024);
+Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 4*1024);
 #endif
 
 /* create a semaphore to synchronize the threads */
@@ -134,7 +136,7 @@
     _smutex.unlock();
 
 }
-
+#ifdef ENABLE_UART_BACKGRND_DEMO
 static int uartExpectedRcvCount = 0;
 static int uartCharRcvCount = 0;
 static bool UartBusy = false;
@@ -191,7 +193,6 @@
         eventQueue.call(printUartRxResult);
     }
 }
-
 void BackGndUartRead(uint8_t * rxBuffer, size_t bufSize, int rxLen)
 {
     UartBusy = true;
@@ -243,6 +244,8 @@
     }
 
 }
+#endif
+
 uint64_t lastTime = 0;
 uint64_t now = 0;
 uint32_t callCount = 0;
@@ -400,6 +403,7 @@
 #define BLE_STOP_START_ADV_SCAN_DEMO
 #define SKIP_WIFI_CONNECT_DEMO
 #define PAUSE_SECONDS   0
+#define PAUSE_SECONDS_BLE 2
 int main() {
     //print_all_thread_info();
     //print_heap_and_isr_stack_info();
@@ -429,7 +433,7 @@
     peripheral->run();
     btle_thread.start(callback(&queue, &EventQueue::dispatch_forever));
     print_memory_info();
-    printWaitAbortKeyPress(PAUSE_SECONDS);
+    printWaitAbortKeyPress(PAUSE_SECONDS_BLE); // give BLE time to settle
     //peripheral->stopAdvertising();
 
 #ifndef DISABLE_WIFI // comment out wifi part
@@ -541,6 +545,7 @@
                                                 false);
     //aTCmdManager->runMain();
     atcmd_thread.start(callback(aTCmdManager, &ATCmdManager::runMain));
+    //wiFiManager->runMain();
     while(1) wait(0.1);
     //performFreeMemoryCheck();