this is using the mbed os version 5-13-1
Diff: source/WiFiManager.cpp
- Branch:
- PassingRegression
- Revision:
- 119:8d939a902333
- Parent:
- 118:8df0e9c2ee3f
- Child:
- 122:62166886db5f
--- a/source/WiFiManager.cpp Sat May 25 16:25:42 2019 +0000
+++ b/source/WiFiManager.cpp Mon May 27 12:34:58 2019 +0000
@@ -49,6 +49,7 @@
wifiWatchdogTimer.start();
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
}
@@ -95,6 +96,43 @@
#endif
}
+void WiFiManager::callInternetKeepAlive()
+{
+ if(https_connection_active)
+ {
+ setNextCommand(WIFI_CMD_INTERNET_KEEP_ALIVE);
+ }
+}
+
+
+void WiFiManager::keepSocketAlive()
+{
+ // Send data
+ nsapi_error_t serr;
+ //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));
+
+ if(serr <= 0)
+ {
+ queueATresponse(AT_SOCKET_KEEP_ALIVE_FAILED);
+ }
+
+ // Receive data
+ char buf[500];
+ nsapi_size_or_error_t error;
+ error = socket->recv(buf, 500);
+ 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);
+ }
+ else
+ {
+ queueATresponse(AT_SOCKET_KEEP_ALIVE_FAILED);
+ }
+}
+
+
void WiFiManager::sendThreadATresponseString(const char * buf, at_cmd_resp_t at_cmd)
{
if(at_data_resp != NULL) return;
@@ -111,7 +149,7 @@
{
if(!queueResult){
wait_count+=10;
- dbg_printf(LOG, "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);
wait_ms(10);
}
queueResult = queueWiFiDataResponse(*at_data_resp);
@@ -293,6 +331,8 @@
break;
case WIFI_CMD_SEND_HTTPS_REQ:
{
+ // cancel keep alive event as not needed since new request has come in.
+ _event_queue.cancel(keep_alive_id);
wifiBusy = 1;
#ifdef SEND_DEBUG_MESSAGES
if(outputBuffersAvailable())
@@ -355,9 +395,17 @@
print_memory_info();
wifiCmd = WIFI_CMD_NONE;
wifiBusy = 0;
+ // enable keep alive after https request completes
+ 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_INTERNET_KEEP_ALIVE:
+ wifiBusy = 1;
+ keepSocketAlive();
+ wifiCmd = WIFI_CMD_NONE;
+ wifiBusy = 0;
+ break;
case WIFI_CMD_SEND_HTTP_REQ:
break;
default:
@@ -390,7 +438,7 @@
{
if(!queueResult){
wait_count+=10;
- dbg_printf(LOG, "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);
wait_ms(10);
}
queueResult = queueWiFiDataResponse(*at_data_resp);
@@ -417,7 +465,7 @@
if(!queueResult){
wait_count+=10;
wait_ms(10);
- dbg_printf(LOG, "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);
}
queueResult = queueWiFiDataResponse(*at_data_resp);
}while(queueResult == false && wait_count<QUEUE_WAIT_TIMEOUT_MS);