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 May 05 08:24:46 2019 +0000
Parent:
103:7b566b522427
Child:
105:e5ce023eee93
Commit message:
still having issues with http request not returning

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/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/debug.cpp Show annotated file Show diff for this revision Revisions of this file
source/debug.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/ATCmdManager.cpp	Thu May 02 21:50:17 2019 +0000
+++ b/source/ATCmdManager.cpp	Sun May 05 08:24:46 2019 +0000
@@ -84,6 +84,7 @@
     at_resp = AT_RESP_NONE;
     dataMode = AT_CMD_DATA_MODE;
     debug_flag = 0;
+    wifiStateControl = AT_RESP_NONE;
     _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);
@@ -106,6 +107,7 @@
 void ATCmdManager::processResponses(){
         dequeueATresponse();
         dequeueWiFidataResponse();
+        updateWiFiMgrStatus();
         if(debug_flag>0){
             //debug_flag--;
             dbg_printf(LOG, " back to ProcessResponses in Main loop... at_resp = %d\r\n", at_resp);
@@ -150,7 +152,7 @@
                 respStr = (char *) resp_data->buffer;
                 sendAtConfirmationFreeMpool(respStr);
                 char * urc = new char[20];
-                sprintf(urc, "\r\n%s=%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID);
+                sprintf(urc, "\r\n%s:%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID);
                 sendAtEvent(urc);
                 delete urc;
                 //_smutex.unlock();
@@ -256,6 +258,18 @@
                 at_resp = AT_RESP_NONE;
                 break;
             }
+            case WIFI_WATCH_DOG:  
+            {
+                // AT_HTTP_RESP response state 
+                dbg_printf(LOG, "\n [ATCMD MAN] WIFI Watchdog message!!\r\n");
+                //_smutex.lock();
+                //_parser.send("\r\nNACK\r\n");
+                //_smutex.unlock();
+                respStr = (char *) resp_data->buffer;
+                sendConnectIndicationFreeMpool(respStr);
+                at_resp = AT_RESP_NONE;
+                break;
+            }
             case AT_COMMAND_FAILED:  
             {
                 // AT_HTTP_RESP response state 
@@ -280,6 +294,34 @@
 }
 
 
+void ATCmdManager::updateWiFiMgrStatus()
+{
+    static int wifiBusyMonitor = 0;
+    // if next response is the expected response, 
+    // then last command complete, reset wifi status
+    // pass or fail!!
+    if(at_resp == wifiStateControl || at_resp == AT_COMMAND_FAILED)
+    {
+        wifiStateControl = AT_RESP_NONE;
+    }
+    if(at_resp == WIFI_WATCH_DOG && strstr((char *) resp_data->buffer, "WiFi Main Loop inActive") != NULL)
+    {
+        wifiBusyMonitor++;
+        if(wifiBusyMonitor >= 4)
+        {
+            wifiStateControl = AT_RESP_NONE;
+            wifiBusyMonitor = 0;
+        }
+    }
+}
+void ATCmdManager::sendConnectIndicationFreeMpool(const char *buf)
+{
+    int len =  strlen(buf);
+    outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, INDICATION_MSG_TYPE, NO_CHANNEL);
+    _wiFi2ATDatamPool->free(resp_data);
+    resp_data = NULL;
+}
+
 void ATCmdManager::sendAtConfirmationFreeMpool(const char *buf)
 {
     sendAtConfirmation(buf);
@@ -288,13 +330,14 @@
 }
 
 
-void ATCmdManager::printBufferInHex(uint8_t *buf, int pLen)
+void ATCmdManager::printBufferInHex(const uint8_t *buf, int pLen)
 {
-    for(int i =0;i<pLen;i++){
-        if(i%8==0) dbg_printf(LOG, "\n[%3d]",i);
-        dbg_printf(LOG, "%02x ", buf[i]);
-    }
-    dbg_printf(LOG, "\n");
+    //for(int i =0;i<pLen;i++){
+    //    if(i%8==0) dbg_printf(LOG, "\n[%3d]",i);
+    //    dbg_printf(LOG, "%02x ", buf[i]);
+    //}
+    print_debug_hex(buf, pLen);
+    //dbg_printf(LOG, "\n");
 }
 
 bool ATCmdManager::validate(edm_header_t edm_header)
@@ -333,6 +376,15 @@
 }
 bool ATCmdManager::createHttpRequest()
 {
+    static int busyResponseJitter = 0;
+    if(wifiStateControl != AT_RESP_NONE) // wifi busy!
+    {
+        busyResponseJitter++;
+        if(busyResponseJitter%7==5 || busyResponseJitter%11==6)
+            return false;
+        else
+            return true;
+    }
     http_request_t *http_req; // = new http_request_t;
     wifi_data_msg_t data_msg;
     http_req = (http_request_t *)data_msg.buffer;
@@ -379,8 +431,18 @@
             dbg_printf(LOG, "\nname = %s value = %s",s1, s2);
             if(strstr(s1, "Host")!= NULL){
                 http_req->hostName = outPtr;
+#ifdef BOX_UBLOX_DEMO_TESTING
+                p = strstr(s2, "//");
+                if(p == NULL)
+                 p = s2;
+                else
+                 p+=2;
+                len = strlen(p)+1;                
+                strncpy(outPtr, p, len);
+#else
                 len = strlen(s2)+1;                
                 strncpy(outPtr, s2, len);
+#endif
                 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
                 outPtr += len; // point output buffer ptr to after current string
             }
@@ -429,7 +491,10 @@
     data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t);
     dbg_printf(LOG, "\ndata_msg.dataLen = %d\n", data_msg.dataLen);
     // queue next data request
-    queueWiFiDataRequest(data_msg);
+    if(queueWiFiDataRequest(data_msg) == true)
+    {
+        wifiStateControl = AT_HTTPS_RESP_DOWNLOAD;
+    }
     return true;
 }
 // OOB processing
@@ -524,9 +589,9 @@
                                 //_smutex.unlock();
                             }
                             else{
-                                _smutex.lock();
-                                _parser.send("NACK");
-                                _smutex.unlock();
+                                //_smutex.lock();
+                                sendAtConfirmation(WIFI_BUSY_RESP);
+                                //_smutex.unlock();
                             }
                             free(rx_buf_ptr);
                             rx_buf_ptr = NULL;
@@ -1166,10 +1231,23 @@
 }
 
 bool  ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){
+    static bool memFull = false;
     //print_memory_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();
+    if(wifiData == NULL)
+    {
+        //_parser.send("\r\nQUEUE MEMORY FULL\r\n");
+        sendAtConfirmation("\r\nQUEUE MEMORY FULL\r\n");
+        memFull = true;
+        return false;
+    }
+    if(memFull)
+    {
+        memFull = false;
+        sendAtConfirmation("\r\n[ATCMD-MAN] memory released...\r\n");
+    }
     wifiData->wifi_cmd        = data_req.wifi_cmd;
     wifiData->dataLen        = data_req.dataLen;
     memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen);
--- a/source/ATCmdManager.h	Thu May 02 21:50:17 2019 +0000
+++ b/source/ATCmdManager.h	Sun May 05 08:24:46 2019 +0000
@@ -15,6 +15,7 @@
 
 #define OK_RESP    "\r\nOK\r\n"
 #define ERROR_RESP "\r\nERROR\r\n"
+#define WIFI_BUSY_RESP "\r\nWIFI BUSY\r\n"
 #define BOX_UBLOX_DEMO_TESTING
 extern void print_memory_info();
 class ATCmdManager {
@@ -70,6 +71,7 @@
     edm_header_t   edm_hdr;
     uint8_t        *rx_buf_ptr;
     int            debug_flag;
+    at_cmd_resp_t  wifiStateControl;
 #ifdef BOX_UBLOX_DEMO_TESTING
     bool           check_for_at_cmd;
 #endif
@@ -116,16 +118,18 @@
     bool        createHttpRequest();
     http_method str2HttpMethod(const char * methodStr);
     void        return_response(bool download=false); 
-    void        printBufferInHex(uint8_t *buf, int pLen);
+    void        printBufferInHex(const uint8_t *buf, int pLen);
     void        outputEDMdata(const uint8_t *buf, int pLen, 
                               edm_msg_id_t identifier, edm_msg_type_t type,
                               channel_id_t channel_id);
     
     void        sendAtConfirmation(const char *buf);
     void        sendAtConfirmationFreeMpool(const char *buf);
+    void        sendConnectIndicationFreeMpool(const char *buf);
     void        sendAtEvent(const char *buf);
     void        sendConnectEvent(const uint8_t *buf, int len);
     int         readAtCommandString(char *strbuf, size_t bufLen);
+    void        updateWiFiMgrStatus();
     
     /**
     * Allows timeout to be changed between commands
--- a/source/WiFiManager.cpp	Thu May 02 21:50:17 2019 +0000
+++ b/source/WiFiManager.cpp	Sun May 05 08:24:46 2019 +0000
@@ -31,19 +31,51 @@
     _wiFi2ATDataQueue(wiFi2ATDataQueue)
 
 {
- lastScanCount = 0;
- wifiCmd = WIFI_CMD_NONE;
- internet_config.connectionScheme = ALWAYS_CONNECTED; // set default connection scheme
- is_connected = false;
- http_response = NULL;
- chunkNum = 0;
- socket = NULL;
- https_connection_active = false;
+    lastScanCount = 0;
+    wifiCmd = WIFI_CMD_NONE;
+    internet_config.connectionScheme = ALWAYS_CONNECTED; // set default connection scheme
+    is_connected = false;
+    http_response = NULL;
+    chunkNum = 0;
+    socket = NULL;
+    https_connection_active = false;
+    wifiBusy = 0;
+    wifiWatchdogTimer.start();
+    watchdogCnt = 0;
+    _event_queue.call_every(10000, this, &WiFiManager::callWifiWatchDog);
 }
 
 WiFiManager::~WiFiManager()
 {
 }
+
+void WiFiManager::callWifiWatchDog()
+{
+    static int inactivity_monitor = 0;
+    watchdogCnt++;
+    if(watchdogCnt >= 6 && responseString==NULL) // every minute
+    {
+        responseString = (char *) malloc(100);
+        sprintf(responseString, "\r\n[WiFi-MAN] WiFi Manager Alive\r\n");
+        sendATresponseString(WIFI_WATCH_DOG);
+        watchdogCnt = 0;
+    }
+    else if(wifiWatchdogTimer.read() > 30.0 && responseString==NULL)
+    {
+        if(wifiCmd == WIFI_CMD_NONE)
+            inactivity_monitor++;
+        responseString = (char *) malloc(100);
+        sprintf(responseString, "\r\n[WiFi-MAN] Main Loop InActive : state = %d busy = %d httpsConnActive = %d\r\n", 
+                                 wifiCmd, wifiBusy, https_connection_active);
+        sendATresponseString(WIFI_WATCH_DOG);
+        if(inactivity_monitor >= 3)
+        {
+            free_DataMsg();
+            inactivity_monitor = 0;
+        }
+    }
+    
+}
   
 bool WiFiManager::queueATresponse(at_cmd_resp_t resp){
 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
@@ -78,25 +110,31 @@
     while(true){
         dequeueWiFiCommands();
         dequeueATdataResponse();
+        wifiWatchdogTimer.reset();
         switch(wifiCmd){
             case WIFI_CMD_NONE:
                 // IDLE STATE
                 break;
             case WIFI_CMD_SCAN:
+                wifiBusy = 1;
                 error = scanNetworks();
                 wifiCmd = WIFI_CMD_NONE;
                 queueATresponse(AT_SCAN_RESP);
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_DETAILED_SCAN:
             {
+                wifiBusy = 1;
                 nsapi_size_or_error_t cnt_err;
                 cnt_err = getAvailableAPs(lastScanCount);
                 wifiCmd = WIFI_CMD_NONE;
                 queueATresponse(AT_DETAILED_SCAN_RESP);
+                wifiBusy = 0;
                 break;
             }
             case WIFI_CMD_CONNECT:
             {
+                wifiBusy = 1;
                 error = connect();
                 int secCount = 0;
                 while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS || is_connected==false){
@@ -113,44 +151,72 @@
                 else {
                     sendATresponseString(AT_CONNECT_RESP);
                 }
+                wifiBusy = 0;
                 break;
             }
             case WIFI_CMD_DISCONNECT:
+                wifiBusy = 1;
                 error = disconnect();
                 wifiCmd = WIFI_CMD_NONE;
                 queueATresponse(AT_DISCONNECT_RESP);
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_CONFIG:
+                wifiBusy = 1;
                 set_WIFI_CONFIG();
                 wifiCmd = WIFI_CMD_NONE;
                 queueATresponse(AT_CONFIG_RESP);
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_INTERNET_CONFIG:
+                wifiBusy = 1;
                 set_internet_config();
                 queueATresponse(AT_INTERNET_CONFIG_RESP);
                 wifiCmd = WIFI_CMD_NONE;
                 break;
             case WIFI_CMD_NETWORK_STATUS:
+                wifiBusy = 1;
                 getNetworkStatus();
                 sendATresponseString(AT_NETWORK_STATUS_RESP);
                 wifiCmd = WIFI_CMD_NONE;
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_WIFI_STATUS:
+                wifiBusy = 1;
                 getWiFiStatus();
                 sendATresponseString(AT_WIFI_STATUS_RESP);
                 wifiCmd = WIFI_CMD_NONE;
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_SEND_HTTPS_REQ:
+                wifiBusy = 1;
+                if(responseString == NULL)
+                {
+                    responseString = (char *) malloc(100);
+                    sprintf(responseString, "\r\nHTTP REQUEST RECEIVED\r\n");
+                    sendATresponseString(AT_EVENT);
+                }
                 dbg_printf(LOG, "before call to send http request \n");
+                dbg_printf(LOG, "\r\n[WIFI-MAN] Received HTTPS request...\r\n");
                 print_memory_info();
                 result = createHttpsRequest();
                 if(result == false)
                 {
+                    responseString = (char *) malloc(100);
+                    if(http_result==TLS_CONNECTION_FAILED)
+                    {
+                        sprintf(responseString, "\r\nTLS CONNECTION FAILURE\r\n");
+                    }
+                    else
+                    {
+                        sprintf(responseString, "\r\nHTTP REQUEST FAILED\r\n");
+                    }
                     sendATresponseString(AT_COMMAND_FAILED);
                 }
                 dbg_printf(LOG, "after call to send http request \n");
                 print_memory_info();
                 wifiCmd = WIFI_CMD_NONE;
+                wifiBusy = 0;
                 break;
             case WIFI_CMD_SEND_HTTP_REQ:
                 break;
@@ -219,7 +285,7 @@
 
 
 bool  WiFiManager::dequeueWiFiCommands(){
-    if(wifiCmd != WIFI_CMD_NONE) return false; // busy
+    if(wifiCmd != WIFI_CMD_NONE || wifiBusy!=0) return false; // busy
     osEvent evt = _aT2WiFiCmdQueue->get(0);
     if(evt.status == osEventMessage){
         wifi_cmd_message_t *cmd = (wifi_cmd_message_t*)evt.value.p;
@@ -237,7 +303,7 @@
 
 
 bool WiFiManager::dequeueATdataResponse(){
-    if(wifiCmd != WIFI_CMD_NONE) return false; // busy
+    if(wifiCmd != WIFI_CMD_NONE || wifiBusy!=0) return false; // busy
     osEvent evt = _aT2WiFiDataQueue->get(0);
     if(evt.status == osEventMessage){
         data_msg = (wifi_data_msg_t*)evt.value.p;
@@ -531,7 +597,7 @@
 
 void WiFiManager::status_callback(nsapi_event_t status, intptr_t param)
 {
-    dbg_printf(LOG, "[WIFI-MAN] about call callback... \r\n");
+    dbg_printf(LOG, "[WIFI-MAN] about to call callback... \r\n");
     _event_queue.call_in(50, this, &WiFiManager::status_callback_event, status, param);
     //status_callback_event(status, param);
 }
@@ -555,6 +621,7 @@
                                                           DEFAULT_WIFI_CHANNEL);
             
             is_connected = true;
+            wifiBusy = 0;
             break;
         case NSAPI_STATUS_DISCONNECTED:
             dbg_printf(LOG, "No connection to network!\r\n");
@@ -564,6 +631,7 @@
             // attempt reconnection if always connected scheme is set
             if(internet_config.connectionScheme == ALWAYS_CONNECTED)
             {
+                wifiBusy = 1;
                 nsapi_error_t error;
                 error = connect();
                 queueATresponse(WIFI_RECONNECT_INFO);
@@ -616,15 +684,15 @@
     int i = 0;
     responseBytes[i++] = IPv4_CONNECTION; // connect type IPv4
     responseBytes[i++] = TCP_PROTOCOL; // Protocol = TCP
-    memcpy(&responseBytes[i], address->get_ip_bytes(), 4); // remote IPv4 address
-    strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
-    i +=4;
-    uint16_t port = address->get_port();
-    internet_config.remote_port = port;
-    memcpy(&responseBytes[i], &port, 2); // remote IPv4 port #
-    i +=2;
-    if(is_connected)
+    if(is_connected && result>0)
     {
+        memcpy(&responseBytes[i], address->get_ip_bytes(), 4); // remote IPv4 address
+        strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
+        i +=4;
+        uint16_t port = address->get_port();
+        internet_config.remote_port = port;
+        memcpy(&responseBytes[i], &port, 2); // remote IPv4 port #
+        i +=2;
         // local IPv4 address
         int ipAddr[4];
         strcpy(internet_config.local_IPv4Address, network->get_ip_address());
@@ -646,6 +714,8 @@
     }
     _event_queue.call_in(2, this, &WiFiManager::sendATresponseBytes, 
                                     CONNECT_EVENT, HOSTNAME_RESPONSE_LEN);
+    wifiBusy = 0;
+
 }   
 
 void WiFiManager::sendSocketConnectionEvent()
@@ -801,13 +871,14 @@
 }
 
 
-void WiFiManager::printBufferInHex(uint8_t *buf, int pLen)
+void WiFiManager::printBufferInHex(const uint8_t *buf, int pLen)
 {
-    for(int i =0;i<pLen;i++){
-        if(i%8==0) dbg_printf(LOG, "\n[%3d]",i);
-        dbg_printf(LOG, "%02x ", buf[i]);
-    }
-    dbg_printf(LOG, "\n");
+    //for(int i =0;i<pLen;i++){
+    //    if(i%8==0) dbg_printf(LOG, "\n[%3d]",i);
+    //    dbg_printf(LOG, "%02x ", buf[i]);
+    //}
+    //dbg_printf(LOG, "\n");
+    print_debug_hex(buf, pLen);
 }
 
 //#define TRY_PRINTF
@@ -823,6 +894,13 @@
     {
         dbg_printf(LOG, "[WIFI-MAN] response pointer NULL not!!\r\n");
     }
+    if(responseString == NULL && chunkNum==1)
+    {
+        responseString = (char *) malloc(100);
+        sprintf(responseString, "\r\nHTTPS BODY CALLBACK RECEIVED\r\n");
+        sendATresponseString(AT_EVENT);
+    }
+
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
 
@@ -871,10 +949,18 @@
     dbg_printf(LOG, "Updating internet_config... \r\n");
     nsapi_error_t error;
     SocketAddress * address = new SocketAddress;
-    error = socket->getpeername(address);   
-    strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
-    uint16_t port = address->get_port();
-    internet_config.remote_port = port;
+    error = socket->getpeername(address);
+    if(error>=0)   
+    {
+        strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
+        uint16_t port = address->get_port();
+        internet_config.remote_port = port;
+    }
+    else  
+    {
+        strcpy(internet_config.remote_IPv4Address, "");
+        internet_config.remote_port = 0;
+    }
     delete address;
 }
 
@@ -959,14 +1045,17 @@
                  dbg_printf(LOG, "TLS Socket connection failed - deleting data msg\r\n");
                  free_DataMsg();
                  dbg_printf(LOG, "data msg deleted \r\n");
+                 http_result = TLS_CONNECTION_FAILED;
                  return false;
             }
             // update remote peer details after socket connection
             updateRemotePeerDetails();
             // send socket connection event before proceeding to send https request
             // give about 2 ms
-            _event_queue.call_in(2, this, &WiFiManager::sendSocketConnectionEvent);
-            return true;
+            //_event_queue.call(this, &WiFiManager::sendSocketConnectionEvent);
+            sendSocketConnectionEvent();
+            //https_connection_active = true; // set true whenever connection succeeds
+            //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();
@@ -1002,22 +1091,7 @@
             setHttpsHeader("Content-Type", http_req_cfg->contentType);
             setHttpsHeader("Content-Length", http_req_cfg->contentLen);
             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)
-            {
-                dbg_printf(LOG, "current TLS tlsContext is not null [%d] \r\n", tlsContext->state);
-            }
-            else
-            {
-                dbg_printf(LOG, "TLS Context is NULL \r\n");
-            }
-            //_wmutex.lock();
             http_response = https_request->send(http_req_cfg->body, bodyLen);
-            //https_request->send(http_req_cfg->body, bodyLen);
-            //_wmutex.unlock();
         }
 #else
         setHttpsHeader("Host", http_req_cfg->hostName);
@@ -1033,6 +1107,7 @@
             char buf[100];
             mbedtls_strerror(https_request->get_error(), buf, 100);
             dbg_printf(LOG, "HttpsRequest failed (error code %s)\n", buf);
+            http_result = HTTP_REQUEST_FAILED;
             delete https_request; // free the memory
             https_request = NULL;
             https_connection_active = false; // reset true whenever connection fails
@@ -1063,6 +1138,7 @@
     dbg_printf(LOG, "deleted https_request\r\n");
     https_request = NULL;
     http_response = NULL;
+    http_result = RESPONSE_OK;
     return true;
 }
 
--- a/source/WiFiManager.h	Thu May 02 21:50:17 2019 +0000
+++ b/source/WiFiManager.h	Sun May 05 08:24:46 2019 +0000
@@ -73,6 +73,10 @@
 
     bool is_connected;
     bool http_response_hdr_sent;
+    int  wifiBusy;
+    Timer wifiWatchdogTimer;
+    uint32_t watchdogCnt;
+    http_result_t http_result;
     
     nsapi_size_or_error_t scanNetworks();
     nsapi_size_or_error_t getAvailableAPs(nsapi_size_t count);
@@ -105,7 +109,7 @@
                                                                 const uint8_t * buf, 
                                                                 int bufLen);
     bool                  createTLSconnection(const char *hostName);
-    void                  printBufferInHex(uint8_t *buf, int pLen);
+    void                  printBufferInHex(const uint8_t *buf, int pLen);
     bool                  copyResponseHdr2Queue(const uint8_t * buf);
     void                  sendATresponseString(at_cmd_resp_t);
     void                  sendATresponseBytes(at_cmd_resp_t at_cmd, int len);
@@ -116,6 +120,7 @@
     void                  gethostbyname();
     void                  sendSocketConnectionEvent();
     void                  updateRemotePeerDetails();
+    void                  callWifiWatchDog();
 
 
 
--- a/source/common_config.h	Thu May 02 21:50:17 2019 +0000
+++ b/source/common_config.h	Sun May 05 08:24:46 2019 +0000
@@ -19,8 +19,8 @@
 #define WIFI_LINK_ENABLED         "+UUWLE:"
 #define NETWORK_UP_URC            "+UUNU"
 #define PEER_CONNECTED_URC        "+UUDPC:"
-#define NETWORK_STATUS            "+UNSTAT="
-#define WIFI_NETWORK_STATUS       "+UWSSTAT="
+#define NETWORK_STATUS            "+UNSTAT:"
+#define WIFI_NETWORK_STATUS       "+UWSSTAT:"
 #define UDDRP_ERROR               "\r\nERROR\r\n"
 #define UDDRP_WRITE_OK            "\r\nOK\r\n" 
 #define HOSTNAME_RESPONSE_LEN     14
--- a/source/common_types.h	Thu May 02 21:50:17 2019 +0000
+++ b/source/common_types.h	Sun May 05 08:24:46 2019 +0000
@@ -46,6 +46,13 @@
 
 typedef enum
 {
+  RESPONSE_OK,
+  TLS_CONNECTION_FAILED,
+  HTTP_REQUEST_FAILED
+}http_result_t;
+
+typedef enum
+{
   WIFI_CONFIG_RESET,
   WIFI_CONFIG_STORE,
   WIFI_CONFIG_LOAD,
@@ -89,7 +96,8 @@
   AT_EVENT = 15,
   CONNECT_EVENT = 16,
   DATA_EVENT = 17,
-  AT_COMMAND_FAILED = 18
+  AT_COMMAND_FAILED = 18,
+  WIFI_WATCH_DOG = 19
 }at_cmd_resp_t;
 
 typedef enum edm_msg_id
--- a/source/debug.cpp	Thu May 02 21:50:17 2019 +0000
+++ b/source/debug.cpp	Sun May 05 08:24:46 2019 +0000
@@ -91,6 +91,7 @@
 * @param        None 
 * @retval       None 
 */
+//#define DEBUG_ENABLED
 void initialise_debug(void)
 {   
   memset(g_dbg_buffer, 0, sizeof(g_dbg_buffer));
@@ -98,8 +99,11 @@
   //. Set the version strings
   set_fw_ver_string();
   set_fw_ver_bytes();
-  
-  current_debug_level = NONE; //(LOG | ERR | TXT | DBG); // 
+#ifdef DEBUG_ENABLED  
+  current_debug_level = (LOG | ERR | TXT | DBG); //NONE; // 
+#else
+  current_debug_level = NONE; // 
+#endif
   dbg_data_mode = DATA_ASCII;
   dbg_rx_pos = 0;
   dbg_rx_count = 0;
@@ -168,7 +172,8 @@
 //{
 //    dbg_print(FILE_CODE, __LINE__, debug_level, ...);
 //}
-void dbg_printf(uint8_t debug_level, const char *text, ...)
+void dbg_print(const char *file_code, uint16_t line_number, 
+                uint8_t debug_level, const char *text, ...)
 {
   //const char *file_code, uint16_t line_number,
                 
@@ -180,7 +185,8 @@
     
     if (debug_level != TXT)
     {
-      sprintf(g_dbg_buffer, "|%s|%10u|", debug_level_to_string(debug_level), Kernel::get_ms_count());
+      //sprintf(g_dbg_buffer, "|%s|%10u|", debug_level_to_string(debug_level), Kernel::get_ms_count());
+      sprintf(g_dbg_buffer, "|%s|%s|%4d|%10u|", debug_level_to_string(debug_level), file_code, line_number, Kernel::get_ms_count());
       len_bytes = strlen(g_dbg_buffer);
     }
     
--- a/source/debug.h	Thu May 02 21:50:17 2019 +0000
+++ b/source/debug.h	Sun May 05 08:24:46 2019 +0000
@@ -32,7 +32,7 @@
 
 #define DBG_RX_CMDDATA_SIZE_BYTES       32   
 
-//#define dbg_printf(debug_level, ...) dbg_print(FILE_CODE, __LINE__, debug_level, __VA_ARGS__)
+#define dbg_printf(debug_level, ...) dbg_print(FILE_CODE, __LINE__, debug_level, __VA_ARGS__)
 
 //-------- Constants & enums -------------------------------------------------//
 
@@ -88,8 +88,9 @@
 
 void print_debug_hex(const uint8_t* p_buf, uint16_t len);
 
-void dbg_printf(uint8_t debug_level, const char *text, ...);
-//void dbg_printf(uint8_t debug_level, ...);
+//void dbg_printf(uint8_t debug_level, const char *text, ...);
+void dbg_print(const char* file_name, uint16_t line_number, 
+                       uint8_t debug_level, const char *text, ...);
 //----------------------------------------------------------------------------//
 
 #endif /* DEBUG_H */