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

Dependencies:   mbed-http

Branch:
PassingRegression
Revision:
122:62166886db5f
Parent:
119:8d939a902333
Child:
123:a49e9ffbaca6
--- a/source/WiFiManager.cpp	Sat Jun 01 15:29:03 2019 +0000
+++ b/source/WiFiManager.cpp	Tue Jun 11 20:23:43 2019 +0000
@@ -50,7 +50,7 @@
     watchdogCnt = 0;
     //_event_queue.call_every(10000, this, &WiFiManager::callWifiWatchDog);
     keep_alive_id = _event_queue.call_every(CLOUD_KEEP_ALIVE_INTERVAL, this, &WiFiManager::callInternetKeepAlive);
-    watchDogTick.attach(callback(this, &WiFiManager::callWifiWatchDogIsr), 10.0); // call flip function every 10 seconds
+    //watchDogTick.attach(callback(this, &WiFiManager::callWifiWatchDogIsr), 10.0); // call flip function every 10 seconds
     
 }
 
@@ -102,33 +102,42 @@
     {
         setNextCommand(WIFI_CMD_INTERNET_KEEP_ALIVE);
     }
+    else
+    {
+        setNextCommand(WIFI_CMD_TLS_CONNECT);
+    }
 }
 
 
 void WiFiManager::keepSocketAlive()
 {
     // Send data
-    nsapi_error_t serr;
+    nsapi_size_or_error_t error;
     //serr = socket->send("GET /nudgebox/v1 HTTP/1.0\r\nHost: https://dev2.dnanudge.io\r\n\r\n", 18);
-    serr = socket->send(HELLO_MSG, sizeof(HELLO_MSG));
+    error = socket->send(HELLO_MSG, sizeof(HELLO_MSG));
     
-    if(serr <= 0)
+    if(error < 0)
     {
        queueATresponse(AT_SOCKET_KEEP_ALIVE_FAILED);
+       https_connection_active = false;
+       socket->close();
+       delete socket;
+       return;
     }
     
     // Receive data
     char buf[500];
-    nsapi_size_or_error_t error;
     error = socket->recv(buf, 500);
-    if(error > 0)
+    if(error >= 0)
     {
         dbg_printf(LOG, "\n[WIFI MAN] KEEP ALIVE SERVER RESPONSE: \r\n %s\r\n", buf);
         queueATresponse(AT_SOCKET_KEEP_ALIVE_OK);
+        https_connection_active = true;
     }
     else
     {
        queueATresponse(AT_SOCKET_KEEP_ALIVE_FAILED);
+       https_connection_active = false;
     }
 }
 
@@ -242,7 +251,10 @@
                 nsapi_size_or_error_t cnt_err;
                 cnt_err = getAvailableAPs(lastScanCount);
                 wifiCmd = WIFI_CMD_NONE;
-                queueATresponse(AT_DETAILED_SCAN_RESP);
+                if(cnt_err >= 0)
+                {
+                    queueATresponse(AT_DETAILED_SCAN_RESP);
+                }
                 wifiBusy = 0;
                 break;
             }
@@ -399,6 +411,23 @@
                 keep_alive_id = _event_queue.call_every(CLOUD_KEEP_ALIVE_INTERVAL, this, &WiFiManager::callInternetKeepAlive);
                 //network->attach(callback(this, &WiFiManager::status_callback));
                 break;
+            }            
+            case WIFI_CMD_TLS_CONNECT:
+            {
+                char* hostName = strstr(internet_config->url,"//");
+                wifiBusy = 1;
+                if(hostName != NULL)
+                {
+                    hostName += 2; 
+                    https_connection_active = createTLSconnection(hostName);
+                    if(https_connection_active == false)
+                    {
+                        queueATresponse(AT_SOCKET_KEEP_ALIVE_FAILED);
+                    }
+                }
+                wifiCmd = WIFI_CMD_NONE;
+                wifiBusy = 0;
+                break;
             }
             case WIFI_CMD_INTERNET_KEEP_ALIVE:
                 wifiBusy = 1;
@@ -1138,12 +1167,14 @@
     {
         dbg_printf(LOG, "[WIFI-MAN] response pointer NULL not!!\r\n");
     }
+#ifdef SEND_DEBUG_MESSAGES
     if(responseString == NULL && chunkNum==1)
     {
         responseString = (char *) malloc(100);
         sprintf(responseString, "\r\nHTTPS BODY CALLBACK RECEIVED\r\n");
         sendATresponseString(AT_EVENT);
     }
+#endif
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }