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:
Mon May 27 12:34:58 2019 +0000
Branch:
PassingRegression
Parent:
118:8df0e9c2ee3f
Child:
120:779b74689747
Commit message:
- implemented cloud connection keep-alive mechanism; - implemented BLE manager state machine for processing messages from radio RX and AT commands.; this version passes end-2-end testing

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/BleManager.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/main-https.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/ATCmdManager.cpp	Sat May 25 16:25:42 2019 +0000
+++ b/source/ATCmdManager.cpp	Mon May 27 12:34:58 2019 +0000
@@ -246,12 +246,46 @@
                 at_resp = AT_RESP_NONE;
                 break;
             }
+            case BLE_CONNECT_EVENT:  
+            {
+                // AT Event state 
+                dbg_printf(LOG, "\n [ATCMD MAN] BLE_CONNECT_EVENT RESPONSE RECEIVED!!\r\n");
+                uint8_t * respBytes = ble_resp_data->buffer;
+                sendBleConnectEvent((const char *)respBytes, ble_resp_data->dataLen);
+                at_resp = AT_RESP_NONE;
+                break;
+            }
+            case AT_BLE_EVENT:  
+            {
+                // AT Event state 
+                dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_EVENT RESPONSE RECEIVED!!\r\n");
+                respStr = (char *) resp_data->buffer;
+                sendBleAtEvent(respStr, resp_data->dataLen);
+                at_resp = AT_RESP_NONE;
+                break;
+            }
             case AT_BLE_RESPONSE:  
             {
                 // AT Event state 
-                dbg_printf(LOG, "\n [ATCMD MAN] BLE RESPONSE RECEIVED!!\r\n");
-                respStr = (char *) resp_data->buffer;
-                sendBleDataEvent(respStr, resp_data->dataLen);
+                dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_RESPONSE RECEIVED!!\r\n");
+                respStr = (char *) ble_resp_data->buffer;
+                sendBleDataEvent(respStr, ble_resp_data->dataLen);
+                at_resp = AT_RESP_NONE;
+                break;
+            }
+            case AT_SOCKET_KEEP_ALIVE_OK:  
+            {
+                // AT Event state 
+                dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE OK RESPONSE RECEIVED!!\r\n");
+                sendAtEvent("\r\nCLOUD CONNECTION OK\r\n");
+                at_resp = AT_RESP_NONE;
+                break;
+            }
+            case AT_SOCKET_KEEP_ALIVE_FAILED:  
+            {
+                // AT Event state 
+                dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE FAILED RESPONSE RECEIVED!!\r\n");
+                sendAtEvent("\r\nCLOUD CONNECTION FAILED\r\n");
                 at_resp = AT_RESP_NONE;
                 break;
             }
@@ -548,6 +582,7 @@
                         dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen);
                         free(rx_buf_ptr); // make sure to free buffer
                         rx_buf_ptr = NULL;
+                        sendAtConfirmation(UART_TIMEOUT_ERROR);
                         break; // timeout!
                     }
                     dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen);
@@ -1260,8 +1295,58 @@
             break;
     }
     _smutex.unlock();
-    _wiFi2ATDatamPool->free(resp_data);
-    resp_data = NULL;
+    _ble2ATDatamPool->free(ble_resp_data);
+    ble_resp_data = NULL;
+}
+
+
+
+void ATCmdManager::sendBleAtEvent(const char *buf, int len)
+{
+    _smutex.lock();
+    switch(dataMode){
+        case AT_CMD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_STD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_EXT_DATA_MODE:
+        {
+            outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
+            break;
+        }
+        default:
+            _parser.send(buf);
+            break;
+    }
+    _smutex.unlock();
+    _ble2ATDatamPool->free(ble_resp_data);
+    ble_resp_data = NULL;
+}
+
+void ATCmdManager::sendBleConnectEvent(const char *buf, int len)
+{
+    _smutex.lock();
+    switch(dataMode){
+        case AT_CMD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_STD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_EXT_DATA_MODE:
+        {
+            outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
+            break;
+        }
+        default:
+            _parser.send(buf);
+            break;
+    }
+    _smutex.unlock();
+    _ble2ATDatamPool->free(ble_resp_data);
+    ble_resp_data = NULL;
 }
 
 
--- a/source/ATCmdManager.h	Sat May 25 16:25:42 2019 +0000
+++ b/source/ATCmdManager.h	Mon May 27 12:34:58 2019 +0000
@@ -16,6 +16,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 UART_TIMEOUT_ERROR "\r\nUART TIMEOUT ERROR\r\n"
 #define BOX_UBLOX_DEMO_TESTING
 //extern void print_memory_info();
 //extern void blinkLEDs();
@@ -43,14 +44,13 @@
 
 private:
 // UART settings
+    UARTSerial _serial;
     uart_config_t *uart_config;
-    UARTSerial _serial;
     Mutex _smutex; // Protect serial port access
     Mutex _rmutex; // Reset protection
     // define event queue
     events::EventQueue &_event_queue;
     // AT Command Parser
-    ATCmdParser _parser;
     SMDevicePeripheral *blePeripheral;
     WiFiManager *wiFiManager;
     at_cmd_resp_t at_resp;
@@ -82,10 +82,13 @@
     /*  Queue and memory pool for BLE to AT data */
     MemoryPool<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDatamPool;
     Queue<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDataQueue;
+    ATCmdParser _parser;
 
     
-    //pointer to response data - should be deleted after processing
+    //pointer to wifi response data - should be deleted after processing
     at_data_msg_t *resp_data;
+    //pointer to ble response data - should be deleted after processing
+    ble_at_msg_t *ble_resp_data;
     edm_header_t   edm_hdr;
     uint8_t        *rx_buf_ptr;
     int            debug_flag;
@@ -152,6 +155,8 @@
     int         readAtCommandString(char *strbuf, size_t bufLen);
     void        updateWiFiMgrStatus();
     void        sendBleDataEvent(const char *buf, int len);
+    void        sendBleAtEvent(const char *buf, int len);
+    void        sendBleConnectEvent(const char *buf, int len);
     
     /**
     * Allows timeout to be changed between commands
--- a/source/BleManager.cpp	Sat May 25 16:25:42 2019 +0000
+++ b/source/BleManager.cpp	Mon May 27 12:34:58 2019 +0000
@@ -32,7 +32,7 @@
 //static const uint8_t DEVICE_NAME[] = "SM_device";
 //static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID};
 extern UARTService *uart;
-extern char buffer[BUFFER_LEN];
+
 /** This example demonstrates all the basic setup required
  *  for pairing and setting up link security both as a central and peripheral
  *
@@ -97,10 +97,13 @@
     ble_error_t error;
 
     /* to show we're running we'll blink every 10secs */
-    _event_queue.call_every(10000, this, &SMDevice::blink);
+    //_event_queue.call_every(10000, this, &SMDevice::blink);
 
     /* to show we're advertising we'll print status every minute */
-    _event_queue.call_every(60000, this, &SMDevice::reportGapState);
+    //_event_queue.call_every(60000, this, &SMDevice::reportGapState);
+
+    /* process queues every BLE_PROCESS_QUEUES_INTERVAL_MS */
+    _event_queue.call_every(BLE_PROCESS_QUEUES_INTERVAL_MS, this, &SMDevice::processQueues);
 
 
 
@@ -534,6 +537,94 @@
 }
 
 
+void SMDevicePeripheral::processQueues()
+{
+    dequeueATdataResponse();
+    switch(bleCmd)
+    {
+    case BLE_CMD_NONE:
+        break;
+    case BLE_CMD_CONFIG:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_CONNECT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_DISCONNECT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_SEND_RX_DATA_2AT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_SEND_AT_DATA_2BLE:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    default:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    }
+    
+}
+
+
+bool SMDevicePeripheral::queueBleDataResponse(ble_at_msg_t at_resp)
+{
+    ble_at_msg_t *atData = _ble2ATDatamPool->alloc();
+    if(atData == NULL) return false; // queue full;
+    atData->at_resp        = at_resp.at_resp;
+    atData->dataLen        = at_resp.dataLen;
+    memcpy(atData->buffer, at_resp.buffer, at_resp.dataLen);
+    _ble2ATDataQueue->put(atData);
+    dbg_printf(LOG, "[BLE-MAN] queued data size = %d : at_resp = %d\n", at_resp.dataLen, at_resp.at_resp);
+    return true;
+}
+
+
+bool SMDevicePeripheral::dequeueATdataResponse(){
+    if(bleCmd != BLE_CMD_NONE) return false; // busy
+    osEvent evt = _aT2BleDataQueue->get(0);
+    if(evt.status == osEventMessage){
+        data_msg = (at_ble_msg_t*)evt.value.p;
+        setNextCommand(data_msg->ble_cmd);
+        //_wiFi2ATDatamPool->free(data_msg);
+    }
+    return true;
+}
+
+void  SMDevicePeripheral::sendATresponseBytes(at_cmd_resp_t at_cmd, const uint8_t * buf, int len)
+{
+    at_data_resp = new ble_at_msg_t;
+    // package and send on BLE data queue    
+    // set string length 
+    at_data_resp->dataLen = len;
+    // copy data
+    memcpy(at_data_resp->buffer, buf, len);
+    // copy response type
+    at_data_resp->at_resp = at_cmd;
+    bool queueResult = true;
+    int wait_count = 0;
+    queueResult = queueBleDataResponse(*at_data_resp);
+    delete at_data_resp;
+    at_data_resp = NULL;
+    dbg_printf(LOG, "[BLE-MAN] sendATresponseBytes completed successfully\r\n");
+}                                            
+
+bool SMDevicePeripheral::setNextCommand(ble_cmd_t cmd)
+{
+    dbg_printf(LOG, "\n [BLE-MAN] About to set next BLE manager command to %d\n", cmd);
+    if(bleCmd == BLE_CMD_NONE){
+        bleCmd = cmd;
+        return true; // success
+    }
+    dbg_printf(LOG, "\n [BLE-MAN] Busy : current state = %d \n", bleCmd);
+    return false; // BleManager busy
+}
 
 /** A central device will scan, connect to a peer and request pairing. */
 
--- a/source/BleManager.h	Sat May 25 16:25:42 2019 +0000
+++ b/source/BleManager.h	Mon May 27 12:34:58 2019 +0000
@@ -95,6 +95,7 @@
 protected:
     // connection status
     bool isConnected;
+    char buffer[MAX_BLE_PACKET_SIZE];
 private:
    /** Override to start chosen activity when initialisation completes */
     virtual void start() = 0;
@@ -123,6 +124,13 @@
     
 
     void reportGapState();
+
+    // application virtual methods called by peripheral
+    virtual bool queueBleDataResponse(ble_at_msg_t at_resp) = 0;
+    virtual bool dequeueATdataResponse() = 0;
+    virtual void sendATresponseBytes(at_cmd_resp_t at_cmd, const uint8_t * buf, int len) = 0;
+    virtual bool setNextCommand(ble_cmd_t cmd) = 0;
+    virtual void processQueues() = 0;
     
     /**
      * This callback allows the LEDService to receive updates to the ledState Characteristic.
@@ -134,8 +142,14 @@
     //void passkeyDisplayCallback(Gap::Handle_t handle, const SecurityManager::Passkey_t passkey);
     //void securitySetupCompletedCallback(Gap::Handle_t handle, SecurityManager::SecurityCompletionStatus_t status);
 
-private:
-    DigitalOut _led1;
+protected:
+    BLE &_ble;
+    events::EventQueue &_event_queue;
+    BLEProtocol::AddressBytes_t &_peer_address;
+    ble_cmd_t bleCmd;
+    at_ble_msg_t *data_msg;
+    ble_at_msg_t *at_data_resp;
+protected:
     /*  Queue and memory pool for AT to BLE data */
     MemoryPool<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDatamPool;
     Queue<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDataQueue;
@@ -144,14 +158,11 @@
     /*  Queue and memory pool for BLE to AT data */
     MemoryPool<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDatamPool;
     Queue<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDataQueue;
-
-protected:
-    BLE &_ble;
     ble_config_t *ble_config;
-    events::EventQueue &_event_queue;
-    BLEProtocol::AddressBytes_t &_peer_address;
     ble::connection_handle_t _handle;
     bool _is_connecting;
+private:
+    DigitalOut _led1;
 };
 
 /** A peripheral device will advertise, accept the connection and request
@@ -173,6 +184,11 @@
     virtual void on_connect(const Gap::ConnectionCallbackParams_t *connection_event);
     void stopAdvertising();
     void startAdvertising();
+    virtual bool queueBleDataResponse(ble_at_msg_t at_resp);
+    virtual bool dequeueATdataResponse();
+    virtual void sendATresponseBytes(at_cmd_resp_t at_cmd, const uint8_t * buf, int len);
+    virtual bool setNextCommand(ble_cmd_t cmd);
+    virtual void processQueues();
     
 };
 
--- 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);
--- a/source/WiFiManager.h	Sat May 25 16:25:42 2019 +0000
+++ b/source/WiFiManager.h	Mon May 27 12:34:58 2019 +0000
@@ -15,8 +15,31 @@
  */
 #include "https_certificates.h"
 #include "common_types.h"
+//const char HELLO_MSG[] = 
+
+const uint8_t HELLO_MSG[] = {0x50,0x4f
+                            ,0x53,0x54,0x20,0x2f,0x6e,0x75,0x64,0x67
+                            ,0x65,0x62,0x6f,0x78,0x2f,0x76,0x31,0x20
+                            ,0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x31
+                            ,0x0d,0x0a,0x48,0x6f,0x73,0x74,0x3a,0x20
+                            ,0x33,0x35,0x2e,0x31,0x37,0x36,0x2e,0x31
+                            ,0x39,0x32,0x2e,0x33,0x33,0x3a,0x38,0x30
+                            ,0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,0x74
+                            ,0x3a,0x20,0x2a,0x2f,0x2a,0x0d,0x0a,0x43
+                            ,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54
+                            ,0x79,0x70,0x65,0x3a,0x20,0x61,0x70,0x70
+                            ,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e
+                            ,0x2f,0x6f,0x63,0x74,0x65,0x74,0x2d,0x73
+                            ,0x74,0x72,0x65,0x61,0x6d,0x0d,0x0a,0x43
+                            ,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c
+                            ,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,0x32
+                            ,0x30,0x0d,0x0a,0x0d,0x0a,0x00,0x08,0xd4
+                            ,0xca,0x6e,0x79,0x05,0x4e,0x01,0x68,0x65
+                            ,0x6c,0x6c,0x6f,0x00,0x00,0x91,0xb5,0xa4
+                            ,0x10};
 
 extern void print_memory_info();
+#define  CLOUD_KEEP_ALIVE_INTERVAL  9000
 class WiFiManager {
 public:
     WiFiManager(wifi_config_t *wifi_config, WiFiInterface *wifi, 
@@ -82,6 +105,7 @@
     uint32_t watchdogCnt;
     http_result_t http_result;
     bool     use_full_hostname;
+    int      keep_alive_id;
 #ifdef DNANUDGE_DEBUG
     rtos::Semaphore callback_semaphore;
 #endif    
@@ -135,6 +159,8 @@
     void                  callWifiWatchDogIsr();
     void                  processGetHostByNameResult(nsapi_error_t result, SocketAddress *addr);
     bool                  outputBuffersAvailable();
+    void                  callInternetKeepAlive();
+    void                  keepSocketAlive();
 
 
 
--- a/source/common_config.h	Sat May 25 16:25:42 2019 +0000
+++ b/source/common_config.h	Mon May 27 12:34:58 2019 +0000
@@ -1,8 +1,8 @@
 #ifndef __COMMON_CONFIG_H__
 #define __COMMON_CONFIG_H__
 
-#define   DEFAULT_BAUD_RATE   115200
-#define BUFFER_LEN 256
+#define DEFAULT_BAUD_RATE   115200
+#define MAX_BLE_PACKET_SIZE   256
 #define TX_BUFFER_LEN 4*256
 #define RX_BUFFER_LEN 4*256
 #define BTLE_THREAD_PRIORITY osPriorityRealtime
@@ -45,6 +45,7 @@
 #define QUEUE_WAIT_TIMEOUT_MS     1000
 #define CLOUD_RETRY_TIME_MS       10000
 #define MAX_BLE_PACKET_SIZE       20
+#define BLE_PROCESS_QUEUES_INTERVAL_MS  200 // check BLE queues every 200 ms
 //#define ENABLE_MEMORY_CHECKS
 #define SEND_DEBUG_MESSAGES
 typedef enum
--- a/source/common_types.h	Sat May 25 16:25:42 2019 +0000
+++ b/source/common_types.h	Mon May 27 12:34:58 2019 +0000
@@ -86,7 +86,8 @@
   WIFI_CMD_NETWORK_STATUS,
   WIFI_CMD_WIFI_STATUS,
   WIFI_CMD_SEND_HTTPS_REQ,
-  WIFI_CMD_SEND_HTTP_REQ
+  WIFI_CMD_SEND_HTTP_REQ,
+  WIFI_CMD_INTERNET_KEEP_ALIVE
 }wifi_cmd_t;
 
 typedef enum
@@ -111,7 +112,11 @@
   DATA_EVENT = 17,
   AT_COMMAND_FAILED = 18,
   WIFI_WATCH_DOG = 19,
-  AT_BLE_RESPONSE = 20
+  BLE_CONNECT_EVENT = 20,
+  AT_BLE_EVENT = 21,
+  AT_BLE_RESPONSE = 22,
+  AT_SOCKET_KEEP_ALIVE_OK = 23,
+  AT_SOCKET_KEEP_ALIVE_FAILED = 24
 }at_cmd_resp_t;
 
 typedef enum edm_msg_id
@@ -264,6 +269,7 @@
   BLE_CMD_CONFIG,
   BLE_CMD_CONNECT,
   BLE_CMD_DISCONNECT,
+  BLE_CMD_SEND_RX_DATA_2AT,
   BLE_CMD_SEND_AT_DATA_2BLE
 }ble_cmd_t;
 
--- a/source/main-https.cpp	Sat May 25 16:25:42 2019 +0000
+++ b/source/main-https.cpp	Mon May 27 12:34:58 2019 +0000
@@ -58,10 +58,10 @@
 static SMDevicePeripheral *peripheral;
 
 const static char     DEVICE_NAME_MAIN[] = "UBLOX-BLE";
-char buffer[BUFFER_LEN];
+//char buffer[BUFFER_LEN];
 static EventQueue eventQueue_atcmd(/* event count */ 32 * EVENTS_EVENT_SIZE);
-static EventQueue eventQueue_wifi(/* event count */ 32 * EVENTS_EVENT_SIZE);
-static EventQueue eventQueue_ble(/* event count */ 10 * EVENTS_EVENT_SIZE);
+static EventQueue eventQueue_wifi(/* event count */ 64 * EVENTS_EVENT_SIZE);
+static EventQueue eventQueue_ble(/* event count */ 32 * EVENTS_EVENT_SIZE);
 
 /*  Queue and memory pool for AT to Wifi commands */
 static MemoryPool<wifi_cmd_message_t, 16> aT2WiFimPool;