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

Dependencies:   mbed-http

Revision:
103:7b566b522427
Parent:
102:9748f290a1a5
Child:
104:11e9605093c9
--- a/source/WiFiManager.cpp	Wed Apr 24 17:34:17 2019 +0000
+++ b/source/WiFiManager.cpp	Thu May 02 21:50:17 2019 +0000
@@ -1,5 +1,7 @@
+#include "debug.h"
 #include "WiFiManager.h"
 #include "common_config.h"
+#define FILE_CODE       "wifi"
 
 
 WiFiManager::WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, 
@@ -63,7 +65,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);
+    dbg_printf(LOG, "[WIFI MAN] queued data size = %d : at_resp = %d\n", at_resp.dataLen, at_resp.at_resp);
     return true;
 }
 
@@ -72,7 +74,7 @@
 void WiFiManager::runMain(){
     nsapi_error_t error;
     bool result;
-    printf("\r\n [WIFI MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
+    dbg_printf(LOG, "\r\n [WIFI MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
     while(true){
         dequeueWiFiCommands();
         dequeueATdataResponse();
@@ -102,7 +104,7 @@
                 }
                 wifiCmd = WIFI_CMD_NONE;
                 if(is_connected==false){
-                    printf("[WIFI MAN] +++ WIFI CONNECTION TIMEOUT +++ \r\n");
+                    dbg_printf(LOG, "[WIFI MAN] +++ WIFI CONNECTION TIMEOUT +++ \r\n");
                     //queueATresponse(AT_COMMAND_FAILED);
                     responseString = (char *) malloc(100);
                     sprintf(responseString, "\r\n+UUTIMEOUT\r\n");
@@ -139,14 +141,14 @@
                 wifiCmd = WIFI_CMD_NONE;
                 break;
             case WIFI_CMD_SEND_HTTPS_REQ:
-                printf("before call to send http request \n");
+                dbg_printf(LOG, "before call to send http request \n");
                 print_memory_info();
                 result = createHttpsRequest();
                 if(result == false)
                 {
                     sendATresponseString(AT_COMMAND_FAILED);
                 }
-                printf("after call to send http request \n");
+                dbg_printf(LOG, "after call to send http request \n");
                 print_memory_info();
                 wifiCmd = WIFI_CMD_NONE;
                 break;
@@ -178,7 +180,7 @@
     {
         if(!queueResult){
             wait_count++;
-            printf("ATCMD Queue full waiting %d ms so far...\n", 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);
@@ -205,13 +207,13 @@
         if(!queueResult){
             wait_count++;
             wait_ms(10);
-            printf("ATCMD Queue full waited %d ms so far...\n", wait_count*10);
+            dbg_printf(LOG, "ATCMD Queue full waited %d ms so far...\n", wait_count*10);
         }
         queueResult = queueWiFiDataResponse(*at_data_resp);
     }while(queueResult == false);
     delete at_data_resp;
     at_data_resp = NULL;
-    printf("[WIFI-MAN] sendATresponseBytes completed successfully\r\n");
+    dbg_printf(LOG, "[WIFI-MAN] sendATresponseBytes completed successfully\r\n");
 }                                            
 
 
@@ -248,12 +250,12 @@
 
 bool WiFiManager::setNextCommand(wifi_cmd_t cmd)
 {
-    printf("\n [WIFI-MAN] About to set next WiFi manager command to %d\n", cmd);
+    dbg_printf(LOG, "\n [WIFI-MAN] About to set next WiFi manager command to %d\n", cmd);
     if(wifiCmd == WIFI_CMD_NONE){
         wifiCmd = cmd;
         return true; // success
     }
-    printf("\n [WIFI-MAN] Busy : current state = %d \n", wifiCmd);
+    dbg_printf(LOG, "\n [WIFI-MAN] Busy : current state = %d \n", wifiCmd);
     return false; // wiFiManager busy
 }
 
@@ -280,9 +282,9 @@
 nsapi_size_or_error_t WiFiManager::scanNetworks()
 {
     nsapi_error_t error;
-    printf("\n [WIFI-MAN] About to start scan for WiFi networks\n");
+    dbg_printf(LOG, "\n [WIFI-MAN] About to start scan for WiFi networks\n");
     lastScanCount = network->scan(NULL, 0);
-    printf("\n [WIFI-MAN] Scan for WiFi networks completed - \n");
+    dbg_printf(LOG, "\n [WIFI-MAN] Scan for WiFi networks completed - \n");
     return lastScanCount;
 }
 
@@ -297,7 +299,7 @@
     //count = wiFiManager->scanNetworks();
     if (count <= 0) {
         //_smutex.lock();
-        printf("[WIFI-MAN] scan() failed with return value: %d\n", count);
+        dbg_printf(LOG, "[WIFI-MAN] scan() failed with return value: %d\n", count);
         //_smutex.unlock();
         return 0;
     }
@@ -306,16 +308,16 @@
     ap = new WiFiAccessPoint[count];
     count = network->scan(ap, count);
     if (count <= 0) {
-        printf("[WIFI-MAN] scan() failed with return value: %d\n", count);
+        dbg_printf(LOG, "[WIFI-MAN] scan() failed with return value: %d\n", count);
         return 0;
     }
 
     for (int i = 0; i < count; i++) {
-        printf("[WIFI-MAN]: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
+        dbg_printf(LOG, "[WIFI-MAN]: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
                sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
                ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
     }
-    printf("[WIFI-MAN]  %d networks available.\n", count);
+    dbg_printf(LOG, "[WIFI-MAN]  %d networks available.\n", count);
 
     delete[] ap;
     return count;
@@ -334,7 +336,7 @@
 void WiFiManager::set_WIFI_SSID(char * wifi_ssid)
 {
     strcpy(wifi_config.ssid, wifi_ssid);
-    printf("[WIFI-MAN]  wifi_ssid set to %s\n", wifi_config.ssid);
+    dbg_printf(LOG, "[WIFI-MAN]  wifi_ssid set to %s\n", wifi_config.ssid);
     https_connection_active = false; // reset whenever any of the security credentials change
     delete socket;
 }
@@ -343,7 +345,7 @@
 void WiFiManager::set_WIFI_PASSWORD(char * wifi_pass)
 {
     strcpy(wifi_config.pass, wifi_pass);
-    printf("[WIFI-MAN]  wifi_pass set to %s\n", "****************");
+    dbg_printf(LOG, "[WIFI-MAN]  wifi_pass set to %s\n", "****************");
     https_connection_active = false; // reset whenever any of the security credentials change
     delete socket;
 }
@@ -352,7 +354,7 @@
 void WiFiManager::set_WIFI_SECURITY(nsapi_security_t wifi_security)
 {
     wifi_config.security = wifi_security;
-    printf("[WIFI-MAN]  wifi_security set to %s\n", sec2str(wifi_config.security));
+    dbg_printf(LOG, "[WIFI-MAN]  wifi_security set to %s\n", sec2str(wifi_config.security));
     https_connection_active = false; // reset whenever any of the security credentials change
     delete socket;
 }
@@ -365,7 +367,7 @@
                                          NSAPI_UNSPEC);
     if(value_or_error >= NSAPI_ERROR_OK) // success
     {
-        printf("[WIFI-MAN] hostname translation successful value_or_error = %d\r\n", value_or_error);
+        dbg_printf(LOG, "[WIFI-MAN] hostname translation successful value_or_error = %d\r\n", value_or_error);
         //strcpy(responseString, UDDRP_WRITE_OK);
         //printBufferInHex(responseBytes, HOSTNAME_RESPONSE_LEN);
         //sendATresponseBytes(CONNECT_EVENT, HOSTNAME_RESPONSE_LEN);
@@ -373,7 +375,7 @@
     else // -ve number means error
     {
         responseString = (char *) malloc(20);
-        printf("[WIFI-MAN] hostname translation failed\r\n");
+        dbg_printf(LOG, "[WIFI-MAN] hostname translation failed\r\n");
         strcpy(responseString, UDDRP_ERROR);
         sendATresponseString(AT_COMMAND_FAILED);
     }
@@ -387,8 +389,8 @@
     strncpy(internet_config.url,internet_cfg->url, strlen(internet_cfg->url)+1);
     internet_config.connectionScheme = internet_cfg->connectionScheme;
     free_DataMsg();
-    printf("[WIFI MAN] Internet configuration setup completed\n"); 
-    printf("peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, 
+    dbg_printf(LOG, "[WIFI MAN] Internet configuration setup completed\n"); 
+    dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, 
                                                       internet_config.url, 
                                                       internet_config.connectionScheme);
     if(https_connection_active)
@@ -468,8 +470,9 @@
                 sprintf(nextStrPtr, "\r\n%s,::\r\n", NETWORK_STATUS);
                 break;
         }
-        nextStrPtr += strlen(nextStrPtr) +1; // progress to end of current string
+        nextStrPtr += strlen(nextStrPtr) ; // progress to end of current string
     }
+    sprintf(nextStrPtr, "%s", UDDRP_WRITE_OK);
 }
 
 
@@ -511,8 +514,9 @@
                 sprintf(nextStrPtr, "\r\n%s,::\r\n", WIFI_NETWORK_STATUS);
                 break;
         }
-        nextStrPtr += strlen(nextStrPtr) +1; // progress to end of current string
+        nextStrPtr += strlen(nextStrPtr) ; // progress to end of current string
     }
+    sprintf(nextStrPtr, "%s", UDDRP_WRITE_OK);
 }
 
 
@@ -527,7 +531,7 @@
 
 void WiFiManager::status_callback(nsapi_event_t status, intptr_t param)
 {
-    printf("[WIFI-MAN] about call callback... \r\n");
+    dbg_printf(LOG, "[WIFI-MAN] about call callback... \r\n");
     _event_queue.call_in(50, this, &WiFiManager::status_callback_event, status, param);
     //status_callback_event(status, param);
 }
@@ -537,13 +541,13 @@
     //}
     switch(param) {
         case NSAPI_STATUS_LOCAL_UP:
-            printf("[WIFI-MAN] Local IP address set!\r\n");
-            printf("[WIFI-MAN] IP address: %s\n", network->get_ip_address());
+            dbg_printf(LOG, "[WIFI-MAN] Local IP address set!\r\n");
+            dbg_printf(LOG, "[WIFI-MAN] IP address: %s\n", network->get_ip_address());
             break;
         case NSAPI_STATUS_GLOBAL_UP:
-            printf("Global IP address set!\r\n");
-            printf("[WIFI-MAN] IP address: %s\n", network->get_ip_address());
-            printf("[WIFI-MAN] Connected to the network %s\n", wifi_config.ssid);
+            dbg_printf(LOG, "Global IP address set!\r\n");
+            dbg_printf(LOG, "[WIFI-MAN] IP address: %s\n", network->get_ip_address());
+            dbg_printf(LOG, "[WIFI-MAN] Connected to the network %s\n", wifi_config.ssid);
             responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN); 
             sprintf(responseString, "\r\n%s%d,%s,%d\r\n", WIFI_LINK_ENABLED, 
                                                           WIFI_CHANNEL,
@@ -553,8 +557,8 @@
             is_connected = true;
             break;
         case NSAPI_STATUS_DISCONNECTED:
-            printf("No connection to network!\r\n");
-            printf("\n [WIFI-MAN] No connection to network!\n");
+            dbg_printf(LOG, "No connection to network!\r\n");
+            dbg_printf(LOG, "\n [WIFI-MAN] No connection to network!\n");
             is_connected = false;
             //queueATresponse(AT_DISCONNECT_RESP);
             // attempt reconnection if always connected scheme is set
@@ -566,10 +570,10 @@
             }
             break;
         case NSAPI_STATUS_CONNECTING:
-            printf("Connecting to network!\r\n");
+            dbg_printf(LOG, "Connecting to network!\r\n");
             break;
         default:
-            printf("Not supported");
+            dbg_printf(LOG, "Not supported");
             break;
     }
 }
@@ -585,29 +589,29 @@
 nsapi_error_t WiFiManager::connect()
 {
     nsapi_error_t error;
-    printf("\n [WIFI-MAN] About to connect to WiFi network\n");
+    dbg_printf(LOG, "\n [WIFI-MAN] About to connect to WiFi network\n");
     network->attach(callback(this, &WiFiManager::status_callback));
     error = network->set_blocking(false);
     if(error)
     {
-        printf("\n [WIFI-MAN] Could not set non-blocking mode for Wifi -- aborting!! - \n");
+        dbg_printf(LOG, "\n [WIFI-MAN] Could not set non-blocking mode for Wifi -- aborting!! - \n");
         return error;
     }
-    printf("[WIFI-MAN] Connecting to network ssid = %s passwd = %s  security = %s \r\n", 
+    dbg_printf(LOG, "[WIFI-MAN] Connecting to network ssid = %s passwd = %s  security = %s \r\n", 
                                                     wifi_config.ssid, 
                                                     "****************", 
                                                     sec2str(wifi_config.security));
     error = network->connect(wifi_config.ssid,
                      wifi_config.pass,
                      wifi_config.security);
-    printf("[WIFI-MAN] network->connect called. error = %d\r\n", error);
+    dbg_printf(LOG, "[WIFI-MAN] network->connect called. error = %d\r\n", error);
     return error;
 }
 
 
 void WiFiManager::gethostbyname_callback(nsapi_error_t result, SocketAddress *address)
 {
-    printf("gethostbyname_callback called... result = %d \r\n", result);
+    dbg_printf(LOG, "gethostbyname_callback called... result = %d \r\n", result);
     responseBytes = (uint8_t *) malloc(HOSTNAME_RESPONSE_LEN);
     int i = 0;
     responseBytes[i++] = IPv4_CONNECTION; // connect type IPv4
@@ -671,10 +675,10 @@
 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");
+    //dbg_printf(LOG, "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");
+    //dbg_printf(LOG, "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);
@@ -686,26 +690,26 @@
     do {
         if(!queueResult){
             wait_count++;
-            printf("[WIFI-MAN] ATCMD Queue full waiting %d ms so far...\n", wait_count*10);
+            dbg_printf(LOG, "[WIFI-MAN] ATCMD Queue full waiting %d ms so far...\n", wait_count*10);
             wait_ms(10);
         }
         else {            
             if(http_response_hdr_sent == false && chunkNum==1){ // only do this for first chunk
                 bool status = copyResponseHdr2Queue(buf);  
                 if(status == true){
-                    printf("[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
+                    dbg_printf(LOG, "[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");
+                    dbg_printf(LOG, "[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);
+            dbg_printf(LOG, "[WIFI-MAN] Http Response body [bytes = %d] \r\n",cpyLen);
             at_data_resp->dataLen += cpyLen;
             memcpy(&at_data_resp->buffer[hdrLen], &buf[pos], cpyLen);
-            printf("[WIFI-MAN] Http Response header and body copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
+            dbg_printf(LOG, "[WIFI-MAN] Http Response header and body copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
         }
         queueResult = queueWiFiDataResponse(*at_data_resp);
         if(queueResult){ 
@@ -714,7 +718,7 @@
             hdrLen = 0; 
         }
     }while(queueResult ==  false || pos < bufLen);
-    printf("[WIFI-MAN] response data queued - deleting data memory\r\n");
+    dbg_printf(LOG, "[WIFI-MAN] response data queued - deleting data memory\r\n");
     delete at_data_resp;
     at_data_resp = NULL;
 }
@@ -746,10 +750,10 @@
     int hdrLen = (const char*) buf -hdrPtr;
     // copy header 
     memcpy(at_data_resp->buffer, (const uint8_t *) hdrPtr, hdrLen);
-    printf("[i = %d] This is the header\r\n%s\r\n", i, hdrPtr);
+    dbg_printf(LOG, "[i = %d] This is the header\r\n%s\r\n", i, hdrPtr);
     if(hdrFound == false)
     {
-        printf("[WIFI-MAN] copy failed: HTTP header not found!!\r\n");
+        dbg_printf(LOG, "[WIFI-MAN] copy failed: HTTP header not found!!\r\n");
         return false;
     }
     at_data_resp->dataLen = hdrLen;
@@ -774,8 +778,8 @@
     numChars = sprintf(msgPtr, "\r\n\r\n");
     msgPtr += numChars;
     // print out generated header
-    printf("[WiFi MAN] generated response header:\n");
-    printf("%s\r\n", (char *)at_data_resp->buffer);
+    dbg_printf(LOG, "[WiFi MAN] generated response header:\n");
+    dbg_printf(LOG, "%s\r\n", (char *)at_data_resp->buffer);
     // calculate header length 
     at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
     
@@ -787,7 +791,7 @@
     {
         if(!queueResult){
             wait_count++;
-            printf("ATCMD Queue full waiting %d ms so far...\n", 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);
@@ -800,24 +804,24 @@
 void WiFiManager::printBufferInHex(uint8_t *buf, int pLen)
 {
     for(int i =0;i<pLen;i++){
-        if(i%8==0) printf("\n[%3d]",i);
-        printf("%02x ", buf[i]);
+        if(i%8==0) dbg_printf(LOG, "\n[%3d]",i);
+        dbg_printf(LOG, "%02x ", buf[i]);
     }
-    printf("\n");
+    dbg_printf(LOG, "\n");
 }
 
 //#define TRY_PRINTF
 
 void WiFiManager::body_callback(const char *at, uint32_t length) {    
-    printf("\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
+    dbg_printf(LOG, "\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
     chunkNum++;
     if(http_response == NULL)
     {
-        printf("[WIFI-MAN] response pointer NULL!!\r\n");
+        dbg_printf(LOG, "[WIFI-MAN] response pointer NULL!!\r\n");
     }
     else
     {
-        printf("[WIFI-MAN] response pointer NULL not!!\r\n");
+        dbg_printf(LOG, "[WIFI-MAN] response pointer NULL not!!\r\n");
     }
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
@@ -835,36 +839,36 @@
     r = socket->open(network);
     if(r != NSAPI_ERROR_OK)
     { 
-        printf("TLS open failed!!\n");
+        dbg_printf(LOG, "TLS open failed!!\n");
         return false;
     }
-    printf("TLS open passed!!\n");
+    dbg_printf(LOG, "TLS open passed!!\n");
     r = socket->set_root_ca_cert(SSL_CA_PEM);
     if(r != NSAPI_ERROR_OK)
     { 
-        printf("TLS set_root_ca_cert failed!!\n");
+        dbg_printf(LOG, "TLS set_root_ca_cert failed!!\n");
         socket->close();
-        printf("closing TLS socket!!\n");
+        dbg_printf(LOG, "closing TLS socket!!\n");
         return false;
     }
-    printf("TLS set_root_ca_cert passed!!\n");
+    dbg_printf(LOG, "TLS set_root_ca_cert passed!!\n");
     r = socket->connect(hostName, 443);
     if(r != NSAPI_ERROR_OK)
     { 
         char errstr[100];
         mbedtls_strerror(r, errstr, 100);
-        printf("TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr);
+        dbg_printf(LOG, "TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr);
         socket->close();
         return false;
     }
-    printf("TLS connection successful for https site :  %s\n", hostName);
+    dbg_printf(LOG, "TLS connection successful for https site :  %s\n", hostName);
     return true;
 }
 
 
 void WiFiManager::updateRemotePeerDetails()
 {
-    printf("Updating internet_config... \r\n");
+    dbg_printf(LOG, "Updating internet_config... \r\n");
     nsapi_error_t error;
     SocketAddress * address = new SocketAddress;
     error = socket->getpeername(address);   
@@ -886,27 +890,27 @@
 #else
     http_response_hdr_sent = true;
 #endif    
-    printf("\n[WIFI MAN] Http Request received:\n");
+    dbg_printf(LOG, "\n[WIFI MAN] Http Request received:\n");
     http_req_cfg = (http_request_t *) data_msg->buffer;
-    printf("\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI);
-    printf("\n[WIFI MAN] internet cfg url = %s\n", internet_config.url);
+    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);
     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);
-    printf("\n[WIFI MAN] server url+uri = %s\n", full_url);
-    printf("\n[WIFI MAN] Host = %s\n", http_req_cfg->hostName);
-    printf("\n[WIFI MAN] Accept = %s\n", http_req_cfg->AcceptVal);
-    printf("\n[WIFI MAN] Content-Type = %s\n", http_req_cfg->contentType);
-    printf("\n[WIFI MAN] contentLenstr = %s\n", http_req_cfg->contentLen);
+    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);
                                            
     int bodyLen;
     sscanf(http_req_cfg->contentLen, "%d", &bodyLen);
-    printf("contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen);
+    dbg_printf(LOG, "contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen);
     
     if(bodyLen > 10){
-        printf("\n [WIFI MAN] Message Body:\n");
+        dbg_printf(LOG, "\n [WIFI MAN] Message Body:\n");
         printBufferInHex(http_req_cfg->body, bodyLen);
     }
     if(strstr(internet_config.url, "http:")!=NULL) // http request
@@ -917,9 +921,9 @@
                                        callback(this, &WiFiManager::body_callback));
         setHttpHeader("Host", http_req_cfg->hostName);
         setHttpHeader("Accept", http_req_cfg->AcceptVal);
-        printf("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){
-            printf("HTTP_GET -- ignoring body\n");
+            dbg_printf(LOG, "HTTP_GET -- ignoring body\n");
             //setHttpHeader("Content-Type", http_req_cfg->contentType);
             //setHttpHeader("Content-Length", http_req_cfg->contentLen);
             http_response = http_request->send(NULL, 0);
@@ -933,13 +937,13 @@
         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());
+            dbg_printf(LOG, "HttpRequest failed (error code %s)\n", buf);
+            //dbg_printf(LOG, "HttpsRequest failed (error code %d)\n", https_request->get_error());
             delete http_request; // free the memory
             return false;
         }
         delete http_request; // free the memory
-        printf("\n----- HTTP POST response -----\n");
+        dbg_printf(LOG, "\n----- HTTP POST response -----\n");
     }
     else
     {
@@ -952,9 +956,9 @@
 #endif
             if(tlsResult == false){
                  delete socket;
-                 printf("TLS Socket connection failed - deleting data msg\r\n");
+                 dbg_printf(LOG, "TLS Socket connection failed - deleting data msg\r\n");
                  free_DataMsg();
-                 printf("data msg deleted \r\n");
+                 dbg_printf(LOG, "data msg deleted \r\n");
                  return false;
             }
             // update remote peer details after socket connection
@@ -962,8 +966,9 @@
             // send socket connection event before proceeding to send https request
             // give about 2 ms
             _event_queue.call_in(2, this, &WiFiManager::sendSocketConnectionEvent);
-            //printf("[create https] TLS connection successful for https site :  %s\n", host);
-            //printf("after call to createTLSconnection \n");
+            return true;
+            //dbg_printf(LOG, "[create https] TLS connection successful for https site :  %s\n", host);
+            //dbg_printf(LOG, "after call to createTLSconnection \n");
             //print_memory_info();
         }        
         // Pass in `socket`, instead of `network` as first argument, and omit the `SSL_CA_PEM` argument
@@ -981,9 +986,9 @@
                                          callback(this, &WiFiManager::body_callback));
 #endif        
 #ifdef TESTING_HTTPS
-        printf("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){
-            printf("HTTP_GET -- ignoring body\n");
+            dbg_printf(LOG, "HTTP_GET -- ignoring body\n");
             setHttpsHeader("Host", http_req_cfg->hostName);
             setHttpsHeader("Accept", http_req_cfg->AcceptVal);
             //setHttpHeader("Content-Type", http_req_cfg->contentType);
@@ -991,23 +996,23 @@
             http_response = https_request->send(NULL, 0);
         }
         else{
-            printf("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);
-            printf("https headers setup - about to send request\r\n");
+            dbg_printf(LOG, "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);
+                dbg_printf(LOG, "current TLS tlsContext is not null [%d] \r\n", tlsContext->state);
             }
             else
             {
-                printf("TLS Context is NULL \r\n");
+                dbg_printf(LOG, "TLS Context is NULL \r\n");
             }
             //_wmutex.lock();
             http_response = https_request->send(http_req_cfg->body, bodyLen);
@@ -1027,7 +1032,7 @@
         if (!http_response) {
             char buf[100];
             mbedtls_strerror(https_request->get_error(), buf, 100);
-            printf("HttpsRequest failed (error code %s)\n", buf);
+            dbg_printf(LOG, "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
@@ -1038,7 +1043,7 @@
             return false;
         }
         https_connection_active = true; // set true whenever connection succeeds
-        printf("\n----- HTTPS POST response -----\r\n");
+        dbg_printf(LOG, "\n----- HTTPS POST response -----\r\n");
     }
     if(http_response != NULL){
 
@@ -1051,11 +1056,11 @@
 #endif    
         //delete http_response; // free the response memory
         //http_response = NULL;
-        //printf("deleted http_response\r\n");
+        //dbg_printf(LOG, "deleted http_response\r\n");
     }
     free_DataMsg();
     delete https_request; // free the request & response memory
-    printf("deleted https_request\r\n");
+    dbg_printf(LOG, "deleted https_request\r\n");
     https_request = NULL;
     http_response = NULL;
     return true;