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 Apr 07 10:52:37 2019 +0000
Parent:
89:45f6db09a76d
Child:
91:d6b6319ad681
Commit message:
https response format implemented and tested

Changed in this revision

mbed_app.json Show annotated file Show diff for this revision Revisions of this file
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/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_types.h Show annotated file Show diff for this revision Revisions of this file
source/wifi_demo.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/mbed_app.json	Mon Apr 01 08:00:41 2019 +0000
+++ b/mbed_app.json	Sun Apr 07 10:52:37 2019 +0000
@@ -35,6 +35,7 @@
         "MBED_STACK_STATS_ENABLED=1",
         "MBED_MEM_TRACING_ENABLED=1",
         "MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=0",
+        "MBEDTLS_SSL_MAX_CONTENT_LEN=16384",
         "DEBUG_ISR_STACK_USAGE=1",
         "MBED_CONF_APP_ERROR_FILENAME_CAPTURE_ENABLED=1"
     ],
--- a/source/ATCmdManager.cpp	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/ATCmdManager.cpp	Sun Apr 07 10:52:37 2019 +0000
@@ -61,21 +61,15 @@
     _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity));
     //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage));
  
-//AT+UWSC=0,2,<SSID>
-//AT+UWSC=0,8,<PWD>
-//AT+UWSC=0,5,2 (WPA)
-    //_parser.oob("ATE0", callback(this, &ATCmdManager::_oob_startup_hdlr));
     printf("\n --- ATCmdManager constructor completed ---\n");
     at_resp = AT_RESP_NONE;
     dataMode = AT_CMD_DATA_MODE;
     event_queue.call_every(3600000,&print_memory_info);
-    //AT+UMRS=230400,2,8,1,1,1
-    // AT+UBTLE
 }
 
 
 void ATCmdManager::runMain(){
-    printf("\r\n [ATCMD MAN]  Thread Id = %d\r\n", Thread::gettid());
+    printf("\r\n [ATCMD MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
     while(true){
         _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true);
         wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time 
@@ -93,94 +87,96 @@
                 break;
             case AT_SCAN_RESP:
                 // AT_SCAN_RESP response state
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_DETAILED_SCAN_RESP:
                 // AT_DETAILED_SCAN_RESP response state
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_CONNECT_RESP:  
                 // AT_CONNECT_RESP response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_DISCONNECT_RESP:  
                 // AT_DISCONNECT_RESP response state 
                 //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_CONFIG_RESP:  
                 // AT_CONFIG_RESP response state 
                 //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_INTERNET_CONFIG_RESP:  
                 // AT_CONFIG_RESP response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\n");
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_HTTPS_RESP:  
                 // AT_HTTP_RESP response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n");
                 return_response();
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_HTTPS_RESP_DOWNLOAD:  
                 // AT_HTTPS_RESP_DOWNLOAD response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\n");
                 return_response(true); // set download paramter to true
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_HTTP_RESP:  
                 // AT_HTTP_RESP response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n");
                 return_response(); 
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_HTTP_RESP_DOWNLOAD:  
                 // AT_HTTP_RESP response state 
-                //////_smutex.lock();
                 printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n");
                 return_response(true); // set download paramter to true
+                _smutex.lock();
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
             default:
                 // UNKNOWN response state
-                //////_smutex.lock();
+                _smutex.lock();
                 printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\n");
                 _parser.send("OK\n");
-                //////_smutex.unlock();
+                _smutex.unlock();
                 at_resp = AT_RESP_NONE;
                 break;
         }
@@ -209,6 +205,9 @@
     if(edm_header.payloadLen > MAX_EDM_PAYLOAD_LEN ||
        edm_header.payloadLen < MIN_EDM_PAYLOAD_LEN 
        ) return false; // unexpected length received!
+    if(edm_header.channel_id != WIFI_CHANNEL &&
+       edm_header.channel_id != BLE_CHANNEL 
+       ) return false; // unexpected channel_id received!
     return true;
 }
 
@@ -228,88 +227,101 @@
 }
 bool ATCmdManager::createHttpRequest()
 {
-    http_request_t http_req;
-    printf("\nsizeof(http_req) on creation = %d\n", sizeof(http_req));
-
+    http_request_t *http_req; // = new http_request_t;
+    wifi_data_msg_t data_msg;
+    http_req = (http_request_t *)data_msg.buffer;
     char s1[32];
     char s2[32];
     char s3[32];
-    int n = 0;
-    int pos = 0;
-    char * strPtr = (char *)&rx_buf_ptr[1];
+    int len = 0;
+    int n;
+    char * strPtr = (char *)rx_buf_ptr;
     char * p;
     char * p2 = strstr(strPtr, "\r\n\r\n");
     char * nxtPtr = strPtr;
+    char * outPtr;
     char * bodyPtr = p2+4;
     printf("\nstrPtr address= %x",strPtr);
     printf("\np2 address= %x", p2);
     for(int i = 0; i < 5; i++){
         if(i == 0)// firstline scan method uri and http_ver
         {
-            //n = sscanf(nxtPtr,"%s %s %s", &s1[0], &s2[0], &s3[0]);
             n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3);
+            if(n!=3) return false; // error in input abort
             printf("\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 );
             //http_req.method = str2HttpMethod(s1.c_str());
-            http_req.method = str2HttpMethod(s1);
-            http_req.request_URI.assign(s2);
-            http_req.http_version.assign(s3);
-            printf("\nhttp_req.method = %d \n", http_req.method);
+            http_req->method = str2HttpMethod(s1);
+            http_req->request_URI = (char *) http_req->buffer; // point 1st string to start of buffer
+            len = strlen(s2)+1;
+            strncpy(http_req->request_URI, s2, len);
+            http_req->http_version = http_req->request_URI + len; // point 2nd string to after 1st
+            len = strlen(s3)+1;
+            strncpy(http_req->http_version, s3, len);
+            printf("\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method, 
+                                                                      http_req->request_URI, 
+                                                                      http_req->http_version );
+            printf("\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI, 
+                                                                      http_req->http_version );
+            outPtr = http_req->http_version + len; // point output buffer ptr to after 2nd string
         }
         else{ // scan header pairs
             //n = sscanf(nxtPtr,"%s %s", &s1[0], &s2[0]);
             n = sscanf(nxtPtr,"%s %s", s1, s2);
+            if(n!=2) return false; // error in input abort
             p = strstr(s1,":");
             *p = NULL;
-            //pos = s1.find(":");
-            //s1.replace(pos,1,"");
             printf("\nname = %s value = %s",s1, s2);
-            //if(s1.find("Host")!= string::npos){
             if(strstr(s1, "Host")!= NULL){
-                http_req.hostName.assign(s2);
+                http_req->hostName = outPtr;
+                len = strlen(s2)+1;                
+                strncpy(outPtr, s2, len);
+                printf("\nname = %s value = %s",s1, outPtr);
+                outPtr += len; // point output buffer ptr to after current string
             }
             else if(strstr(s1, "Accept")!= NULL){
-                http_req.AcceptVal.assign(s2);
+                http_req->AcceptVal = outPtr;
+                len = strlen(s2)+1;                
+                strncpy(outPtr, s2, len);
+                printf("\nname = %s value = %s",s1, outPtr);
+                outPtr += len; // point output buffer ptr to after current string
             }
             else if(strstr(s1, "Content-Type")!= NULL){
-                http_req.contentType.assign(s2);
+                http_req->contentType = outPtr;
+                len = strlen(s2)+1;                
+                strncpy(outPtr, s2, len);
+                printf("\nname = %s value = %s",s1, outPtr);
+                outPtr += len; // point output buffer ptr to after current string
             }
             else if(strstr(s1, "Content-Length")!= NULL){
-                http_req.contentLen.assign(s2);
+                //http_req.contentLen.assign(s2);
+                http_req->contentLen = outPtr;
+                len = strlen(s2)+1;                
+                strncpy(outPtr, s2, len);
+                printf("\nname = %s value = %s",s1, outPtr);
+                outPtr += len; // point output buffer ptr to after current string
             }
             
-            
+            printf("\noutPtr = %X len = %d\n", outPtr, len);
         }
         nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line
         if(nxtPtr >= p2) break;
     }
+    // print header from http_req_struct
+    printf("\nhttp request header: \n %s\n", http_req->buffer);
     int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr);
     printf("\nLen = %d\n", bodyLen);
-    memcpy(http_req.body, bodyPtr, bodyLen);
+    http_req->body = (uint8_t *) outPtr;
+    memcpy(outPtr, bodyPtr, bodyLen);
+    if(bodyLen > 10){
+        printf("\n Message Body:\n");
+        printBufferInHex(http_req->body, bodyLen);
+    }
+    outPtr += bodyLen; // move output pointer to end output (header + body)
     // package and send on wifi data queue
-    wifi_data_msg_t data_msg;
     data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ;
-    printf("\nsizeof(http_req) on population = %d\n", sizeof(http_req));
-
-    data_msg.dataLen = sizeof(http_req.method) + 
-                       sizeof(http_req.body) + 
-                       http_req.request_URI.capacity() +
-                       http_req.http_version.capacity() + 
-                       http_req.hostName.capacity() +
-                       http_req.AcceptVal.capacity() +
-                       http_req.contentType.capacity() +
-                       http_req.contentLen.capacity();
-
-/*
-    data_msg.dataLen = sizeof(http_req.method) + 
-                       sizeof(http_req.body) + 
-                       http_req.request_URI.size() +
-                       http_req.http_version.size() + 
-                       http_req.hostName.size() +
-                       http_req.AcceptVal.size() +
-                       http_req.contentType.size() +
-                       http_req.contentLen.size();
-*/
-    memcpy(data_msg.buffer,&http_req, data_msg.dataLen);
+    printf("\nsizeof(http_req) on population = %d\n", sizeof(*http_req));
+    data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t);
+    printf("\ndata_msg.dataLen = %d\n", data_msg.dataLen);
     // queue next data request
     queueWiFiDataRequest(data_msg);
     return true;
@@ -319,6 +331,7 @@
     set_timeout(timeout);
     static int cnt = 0;
     int start;
+    //channel_id_t chan_id;
     if(dataMode == AT_EXT_DATA_MODE)
     {
         int n;
@@ -331,13 +344,15 @@
             edm_hdr.startByte = edm[0];
             edm_hdr.payloadLen = edm[1]*256 + edm[2];
             edm_hdr.payloadID = edm[3]*256 + edm[4];
+            edm_hdr.channel_id = (channel_id_t) edm[5];
             start = Kernel::get_ms_count();
             if(n == -1) break; // break if it times out
             printf("%d bytes read!\n", n);
-            if(n==5)
-            printf("Start = %d, payloadID = %d len = %d\n", edm_hdr.startByte, 
-                                                            edm_hdr.payloadID, 
-                                                            edm_hdr.payloadLen);
+            if(n==EDM_HDR_LEN)
+            printf("Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte, 
+                                                                         edm_hdr.payloadID, 
+                                                                         edm_hdr.payloadLen,
+                                                                         edm_hdr.channel_id);
             if(n == EDM_HDR_LEN && validate(edm_hdr)) // if AT command use process oob to decode
             {
                 if(edm_hdr.payloadID == AT_REQUEST)
@@ -347,7 +362,7 @@
                 }
                 else
                 {
-                    int pLen = edm_hdr.payloadLen-1;
+                    int pLen = edm_hdr.payloadLen-2;
                     rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte
                     rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected
                     n = _parser.read((char *)rx_buf_ptr, pLen);
@@ -356,7 +371,10 @@
                     printBufferInHex(rx_buf_ptr, pLen);
                     printf("rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]);
                     if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) {
-                        break; // exit if stop byte now found - possible data corruption!
+                        _smutex.lock();
+                        _parser.send("ERR");
+                        _smutex.unlock();
+                        break; // exit if stop byte not found - possible data corruption!
                     }
                     switch(edm_hdr.payloadID)
                     {
@@ -372,10 +390,14 @@
                         case DATA_COMMAND:
                             printf("DATA_COMMAND received!\n");
                             if(createHttpRequest() == true){
+                                _smutex.lock();
                                 _parser.send("OK");
+                                _smutex.unlock();
                             }
                             else{
+                                _smutex.lock();
                                 _parser.send("NACK");
+                                _smutex.unlock();
                             }
                             int stop = Kernel::get_ms_count();
                             printf("\n Time Elapsed = %d\n", stop-start);
@@ -417,9 +439,9 @@
 }
 
 void ATCmdManager::_oob_ok_hdlr(){
-    //_smutex.lock();
+    _smutex.lock();
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 
@@ -467,28 +489,28 @@
 
 void ATCmdManager::_oob_echo_off()
 {
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received ATEO OOB command!!\n");
     printf("\n turning echo OFF!!\n");
     _parser.debug_on(false);
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 
 void ATCmdManager::_oob_echo_on()
 {
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received ATE1 OOB command!!\n");
     printf("\n turning echo ON!!\n");
     _parser.debug_on(true);
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 
 void ATCmdManager::_oob_data_mode(){
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received EDM mode command!!\n");
     if(_parser.scanf("%d", &dataMode) >0) {
         printf("\nATCmdParser: Data mode=%d\n", dataMode);
@@ -514,12 +536,12 @@
         printf("\nATCmdParser: Retrieving Uart Options failed\n");
     }
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_get_mac_addr(){
     int bleOrWifi;
-    //_smutex.lock();
+    _smutex.lock();
     if(_parser.scanf("=%d", &bleOrWifi) >0) {
         switch(bleOrWifi)
         {
@@ -537,30 +559,30 @@
         printf("\nATCmdParser: Retrieving Uart Options failed");
     }
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_get_ble_role(){
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received get BLE role command!!\n");
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_ena_ble_peri(){
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received enable BLE Peripheral command!!\n");
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_reboot(){
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received reboot command!!\n");
     _parser.send("OK\n");
     _parser.send("System Resetting....\n");
     system_reset();
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 const char * ATCmdManager::sec2str(nsapi_security_t sec)
@@ -593,10 +615,10 @@
 
 
 void ATCmdManager::_oob_scanWiFiNetworks(){
-    //_smutex.lock();
+    _smutex.lock();
     printf("\n Received scanWiFiNetworks command!!\n");
     _parser.send("OK\n");
-    //_smutex.unlock();
+    _smutex.unlock();
     wifi_cmd_t cmd = WIFI_CMD_SCAN;
     // queue next command
     queueWiFiCommand(cmd);
@@ -622,27 +644,28 @@
 
 void ATCmdManager::_oob_setupInternetConnection()
 {
-    char str[200];
-    char url[60];
+    char str[MAX_URL_LEN];
+    char url[MAX_URL_LEN];
     int n;
     internet_config_t internet_config;
-    //_smutex.lock();
+    _smutex.lock();
     printf("sizeof internet_config_t = %d\n", sizeof(internet_config_t));
-    n = ReadBytes((uint8_t *)str, 199);
+    n = ReadBytes((uint8_t *)str, MAX_URL_LEN);
     str[n]=NULL;
     printf("\n read string = %s , n = %d\n", str, n);
-    n = sscanf(str, "=%1d,%199[^,],%1d", &internet_config.peer_id, 
-                                      url,
-                                     &internet_config.connectionScheme);
+    //n = sscanf(str, "=%1d,%199[^,],%1d", &(uint8_t)internet_config.peer_id, 
+    n = sscanf(str, "=%1d,%99[^,],%1d", &internet_config.peer_id, 
+                                         url, //internet_config.url,
+                                         &internet_config.connectionScheme);
     strncpy(internet_config.url, url, strlen(url)+1);
-    printf("\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(url));
+    printf("\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url));
     if(n>0) 
     {
         printf("peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, 
-                                                          internet_config.url, ///->c_str(), 
-                                                          internet_config.connectionScheme);
+                                                              internet_config.url, 
+                                                              internet_config.connectionScheme);
         // package and send on wifi data queue
-        wifi_data_msg_t data_msg; // = (wifi_data_msg_t *) malloc(sizeof(wifi_data_msg_t));
+        wifi_data_msg_t data_msg; 
         data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG;
         data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url);
         printf("\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url );
@@ -655,7 +678,7 @@
         printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \n", n);
         _parser.send("NAK\n");
     }
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 wifi_config_t ATCmdManager::init_wifi_config()
@@ -702,7 +725,7 @@
 {
     int n;
     wifi_config_t wifi_cfg = init_wifi_config();
-    //_smutex.lock();
+    _smutex.lock();
     n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32);
     printf("[ATCMD MAN]: number of bytes read = %d\n", n);
     if(n>0) 
@@ -719,14 +742,14 @@
         printf("\n[ATCMD MAN]: wifi configuration failed  \n");
         _parser.send("NAK\n");
     }
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_setWiFiPWD()
 {
     int n;
     wifi_config_t wifi_cfg = init_wifi_config();
-    //_smutex.lock();
+    _smutex.lock();
     //n = _parser.scanf("%31[^\r\n]", wifi_cfg.pass);
     n = readStringBytes((uint8_t *)wifi_cfg.pass, 32);
     if(n>0) 
@@ -743,15 +766,16 @@
         printf("\n[ATCMD MAN]: wifi configuration failed  \n");
         _parser.send("NAK\n");
     }
-    //_smutex.unlock();
+    _smutex.unlock();
 }
 
 void ATCmdManager::_oob_setWiFiSecurity()
 {
     int n;
     wifi_config_t wifi_cfg = init_wifi_config();
-    //_smutex.lock();
+    _smutex.lock();
     n = _parser.scanf(",%d", &wifi_cfg.security);
+    _smutex.unlock();
     if(n>0) 
     {
         printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
@@ -764,7 +788,9 @@
         _parser.send("OK\n");
     } else {
         printf("\n[ATCMD MAN]: wifi configuration failed  \n");
+        _smutex.lock();
         _parser.send("NAK\n");
+        _smutex.unlock();
     }
     //_smutex.unlock();
 }
@@ -836,9 +862,29 @@
     return true;
 }
 
+void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen, 
+                                 edm_msg_id_t identifier, edm_msg_type_t type)
+{
+    int epLen = pLen + 2; // edm payload length = data length + 2
+    _smutex.lock();
+    // send EDM Message start byte
+    _parser.putc(EDM_START_BYTE);
+    // send EDM Message length
+    _parser.putc(epLen>>8);
+    _parser.putc(epLen%256);
+    // send EDM Identifier + Type
+    _parser.putc(identifier>>8);
+    _parser.putc(identifier%256 | type);
+    // send the data
+    _parser.write((const char *)buf, pLen);
+    // send EDM Message stop byte
+    _parser.putc(EDM_STOP_BYTE);
+    _smutex.unlock();
+}
 
 void ATCmdManager::return_response(bool download) {
     char * resp = (char *) resp_data->buffer;
+    _smutex.lock();
     printf("\n[ATCMD MAN] received response:\n");
     if(download == false) // not download must be ascii header
     {
@@ -848,7 +894,9 @@
     {
         printBufferInHex((uint8_t *)resp, resp_data->dataLen);
     }
-    _parser.write(resp, resp_data->dataLen);
+    //_parser.write(resp, resp_data->dataLen);
+    outputEDMdata((const uint8_t *)resp, resp_data->dataLen, DATA_MSG_ID, EVENT_MSG_TYPE);
+    _smutex.unlock();
     _wiFi2ATDatamPool->free(resp_data);
     
     
--- a/source/ATCmdManager.h	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/ATCmdManager.h	Sun Apr 07 10:52:37 2019 +0000
@@ -108,6 +108,8 @@
     http_method str2HttpMethod(const char * methodStr);
     void        return_response(bool download=false); 
     void        printBufferInHex(uint8_t *buf, int pLen);
+    void        outputEDMdata(const uint8_t *buf, int pLen, 
+                              edm_msg_id_t identifier, edm_msg_type_t type);
     
     /**
     * Allows timeout to be changed between commands
--- a/source/BleManager.cpp	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/BleManager.cpp	Sun Apr 07 10:52:37 2019 +0000
@@ -78,7 +78,7 @@
 /** Start BLE interface initialisation */
 void SMDevice::run()
 {
-    printf("\r\n [BTLE MAN]  Thread Id = %d\r\n", Thread::gettid());
+    printf("\r\n [BTLE MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
 
     ble_error_t error;
 
--- a/source/WiFiManager.cpp	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/WiFiManager.cpp	Sun Apr 07 10:52:37 2019 +0000
@@ -64,7 +64,7 @@
 
 void WiFiManager::runMain(){
     nsapi_error_t error;
-    printf("\r\n [WIFI MAN]  Thread Id = %d\r\n", Thread::gettid());
+    printf("\r\n [WIFI MAN]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
     while(true){
         dequeueWiFiCommands();
         dequeueATdataResponse();
@@ -348,29 +348,66 @@
 }
 
 void WiFiManager::sendResponseDownloadData(at_cmd_resp_t at_cmd, const uint8_t * buf, int bufLen)
-{
-    at_data_msg_t *at_data_resp;     
+{    
+
     at_data_resp = new at_data_msg_t;
     at_data_resp->at_resp = at_cmd;
     size_t bufSize = sizeof(at_data_resp->buffer);
     int pos = 0;
     at_data_resp->dataLen = 0;
     bool queueResult = true;
+    int hdrLen = 0;
     do {
-        if(!queueResult) wait_ms(10); // wait 10 ms to allow data to be transferred
-        at_data_resp->dataLen = (bufLen - pos) > bufSize? bufSize : (bufLen - pos) ;
-        memcpy(at_data_resp->buffer, &buf[pos], bufLen);
+        if(!queueResult) 
+        {
+            wait_ms(10); // wait 10 ms to allow data to be transferred
+        }
+        else {            
+            if(http_response_hdr_sent == false){
+                copyResponseHdr2Queue();  
+                hdrLen =  at_data_resp->dataLen;
+                http_response_hdr_sent = true;        
+            }
+            int cpyLen = (bufLen - pos) > bufSize? bufSize : (bufLen - pos - hdrLen ) ;
+            at_data_resp->dataLen += cpyLen;
+            memcpy(&at_data_resp->buffer[hdrLen], &buf[pos], cpyLen);
+        }
         queueResult = queueWiFiDataResponse(*at_data_resp);
-        if(queueResult) pos+= at_data_resp->dataLen;
+        if(queueResult){ 
+            pos+= at_data_resp->dataLen;
+            at_data_resp->dataLen = 0;
+            hdrLen = 0; 
+        }
     }while(queueResult ==  false || pos < bufLen);
     delete at_data_resp;
 }
 
+void WiFiManager::copyResponseHdr2Queue()
+{
+    int numChars = 0;
+    // create message pointer for response header generation
+    char * msgPtr = (char *)at_data_resp->buffer;
+    // do status line
+    numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", http_response->get_status_code(), 
+                                                     http_response->get_status_message().c_str());
+    msgPtr += numChars;
+    for (size_t ix = 0; ix < http_response->get_headers_length(); ix++) {
+        numChars = sprintf(msgPtr, "%s: %s\r\n", 
+                           http_response->get_headers_fields()[ix]->c_str(), 
+                           http_response->get_headers_values()[ix]->c_str());
+        msgPtr += numChars;
+    }
+    numChars = sprintf(msgPtr, "\r\n");
+    msgPtr += numChars;
+    // print out generated header
+    printf("[WiFi MAN] generated response header:\n");
+    printf("%s\r\n", (char *)at_data_resp->buffer);
+    // calculate header length 
+    at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
+}
+
 void WiFiManager::return_response(HttpResponse* res) {
     
-    //queueWiFiDataResponse(at_data_msg_t at_data_resp);
-    
-    at_data_msg_t *at_data_resp;
     at_data_resp = new at_data_msg_t;
     int numChars = 0;
     // create message pointer for response header generation
@@ -386,18 +423,14 @@
     }
     numChars = sprintf(msgPtr, "\r\n\r\n");
     msgPtr += numChars;
-    //strncpy(msgPtr, res->get_body_as_string().c_str(), res->get_body_length()+1);
     // print out generated header
-    printf("generated response:\n");
+    printf("[WiFi MAN] generated response header:\n");
     printf("%s\r\n", (char *)at_data_resp->buffer);
-    //printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+    // calculate header length 
     at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
-    //printf("WIFI MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
-    // package and send on wifi data queue
     
+    // package and send on wifi data queue    
     at_data_resp->at_resp = AT_HTTPS_RESP;
-    //at_data_resp.at_data_resp = sizeof(wifi_config_t);
-    //memcpy(at_data_resp.buffer, res, at_data_resp.dataLen);
     bool queueResult = true;
     int wait_count = 0;
     do
@@ -411,34 +444,21 @@
     }while(queueResult == false);
     delete at_data_resp;
 }
+
+
+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]);
+    }
+    printf("\n");
+}
+
 //#define TRY_PRINTF
 
-void WiFiManager::body_callback(const char *at, uint32_t length) {
-    
+void WiFiManager::body_callback(const char *at, uint32_t length) {    
     printf("\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
-    //device->printf("\n Try Print Header as string:\n\n ");
-    //device->printf("recv %d [%.*s]\n", length, strstr((char *)at, "\r\n")-(char *)at, (char *)at);
-    //if(false)
-    //if(chunkNum < 2)
-    //for(int i=0; i < length; i++){
-    //    
-    //putc((uint8_t)at[i]);
-        //int resp = write( (const uint8_t *)at, (int) length, &completed, SERIAL_EVENT_TX_COMPLETE);
-    //}
-    //if(false)
-#ifdef DUMP_BODY_BYTES
-    if(chunkNum < 2)
-    for (size_t ix = 0; ix < length; ix++) {
-        printf("%02X: ", (uint8_t)at[ix]);
-        if((ix % 32) == 0 and ix)
-        printf("\n");
-    }
-#endif
-#ifdef TRY_PRINTF
-    printf("%s\n", at);
-#endif    
-
-    printf("\n\n");
     chunkNum++;
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
@@ -446,10 +466,8 @@
 
 bool WiFiManager::createTLSconnection(const char * hostName)
 {
+    //mbed_trace_init();
     socket = new TLSSocket();
-    printf("\n\nafter TLS socket creation\n");
-    print_memory_info();
-    //printf("\n[WIFI MAN] TLS Host = %s\n", hostName);
 
     nsapi_error_t r;
     // make sure to check the return values for the calls below (should return NSAPI_ERROR_OK)
@@ -481,36 +499,36 @@
 {
     // reset chunk #;
     chunkNum = 0;
+    http_response_hdr_sent = false;
     printf("\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.c_str());
+    printf("\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI);
     printf("\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.c_str(), http_req_cfg->hostName.size());
-    printf("\n[WIFI MAN] server url = %s\n", full_url);
-    //strncat(internet_config.url, http_req_cfg->request_URI.c_str(), http_req_cfg->request_URI.size());
-    strncat(full_url, http_req_cfg->request_URI.c_str(), http_req_cfg->request_URI.size());
-    //printf("\n[WIFI MAN] server url = %s\n", internet_config.url);
+    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.c_str());
-    printf("\n[WIFI MAN] Accept = %s\n", http_req_cfg->AcceptVal.c_str());
-    printf("\n[WIFI MAN] Content-Type = %s\n", http_req_cfg->contentType.c_str());
-    printf("\n[WIFI MAN] contentLenstr = %s\n", http_req_cfg->contentLen.c_str());
-    //printf("\n[WIFI MAN] server url = %s\n", internet_config.url.c_str());
-    //const char* url = internet_config.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);
                                            
     int bodyLen;
-    sscanf(http_req_cfg->contentLen.c_str(), "%d", &bodyLen);
-    printf("contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen.c_str(), bodyLen);
+    sscanf(http_req_cfg->contentLen, "%d", &bodyLen);
+    printf("contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen);
+    
+    if(bodyLen > 10){
+        printf("\n Message Body:\n");
+        printBufferInHex(http_req_cfg->body, bodyLen);
+    }
     if(strstr(internet_config.url, "http:")!=NULL) // http request
     {
         http_request = new HttpRequest(network,  
-                                         //SSL_CA_PEM, 
-                                         http_req_cfg->method, 
-                                         full_url,
-                                         callback(this, &WiFiManager::body_callback));
+                                       http_req_cfg->method, 
+                                       full_url,
+                                       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);
@@ -539,6 +557,7 @@
     }
     else
     {
+#ifndef DONT_USE_TLS_SOCKET
         if(https_connection_active == false){
             bool tlsResult;
             tlsResult = createTLSconnection(host);
@@ -549,6 +568,8 @@
             }
             printf("[create https] TLS connection successful for https site :  %s\n", host);
         }        
+        printf("after call to createTLSconnection \n");
+        print_memory_info();
         // Pass in `socket`, instead of `network` as first argument, and omit the `SSL_CA_PEM` argument
         //HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418");
         //_wmutex.lock();
@@ -556,9 +577,15 @@
                                          http_req_cfg->method, 
                                          full_url,
                                          callback(this, &WiFiManager::body_callback));
-        
+#else
+        https_request = new HttpsRequest(network, 
+                                         SSL_CA_PEM,
+                                         http_req_cfg->method, 
+                                         full_url,
+                                         callback(this, &WiFiManager::body_callback));
+#endif        
 #ifdef TESTING_HTTPS
-        printf("http_req_cfg->method = %d\n");
+        printf("http_req_cfg->method = %d\n", http_req_cfg->method);
         if(http_req_cfg->method == HTTP_GET){
             printf("HTTP_GET -- ignoring body\n");
             setHttpsHeader("Host", http_req_cfg->hostName);
@@ -570,8 +597,8 @@
         else{
             setHttpsHeader("Host", http_req_cfg->hostName);
             setHttpsHeader("Accept", http_req_cfg->AcceptVal);
-            setHttpHeader("Content-Type", http_req_cfg->contentType);
-            setHttpHeader("Content-Length", http_req_cfg->contentLen);
+            setHttpsHeader("Content-Type", http_req_cfg->contentType);
+            setHttpsHeader("Content-Length", http_req_cfg->contentLen);
             http_response = https_request->send(http_req_cfg->body, bodyLen);
         }
 #else
@@ -583,7 +610,7 @@
 #endif        
         
         //_wmutex.unlock();
-        free_DataMsg();
+        //free_DataMsg();
         if (!http_response) {
             char buf[100];
             mbedtls_strerror(https_request->get_error(), buf, 100);
@@ -591,13 +618,18 @@
             delete https_request; // free the memory
             https_connection_active = false; // reset true whenever connection fails
             delete socket;
+            free_DataMsg();
             return;
         }
         https_connection_active = true; // set true whenever connection succeeds
         printf("\n----- HTTPS POST response -----\r\n");
    }
-    return_response(http_response);
-    delete http_response;
+   if(http_response != NULL){
+    //return_response(http_response);
+    delete http_response; // free the response memory
+    }
+     free_DataMsg();
+    //delete https_request; // free the request memory
 }
 
 void WiFiManager::createHttpRequest(http_method method,
--- a/source/WiFiManager.h	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/WiFiManager.h	Sun Apr 07 10:52:37 2019 +0000
@@ -43,6 +43,7 @@
     HttpRequest* http_request;
     HttpResponse* http_response;
     http_request_t *http_req_cfg;
+    at_data_msg_t *at_data_resp; 
     nsapi_size_or_error_t lastScanCount;
     bool                  https_connection_active;
     TLSSocket*            socket;
@@ -67,6 +68,7 @@
     Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
 
     bool is_connected;
+    bool http_response_hdr_sent;
     
     nsapi_size_or_error_t scanNetworks();
     nsapi_size_or_error_t getAvailableAPs(nsapi_size_t count);
@@ -99,6 +101,9 @@
                                                                 const uint8_t * buf, 
                                                                 int bufLen);
     bool                  createTLSconnection(const char *hostName);
+    void                  printBufferInHex(uint8_t *buf, int pLen);
+    void                  copyResponseHdr2Queue();
+
 
     /**
     * Allows timeout to be changed between commands
--- a/source/common_types.h	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/common_types.h	Sun Apr 07 10:52:37 2019 +0000
@@ -11,7 +11,7 @@
 #define MAX_PASSKEY_LEN 32
 #define EDM_START_BYTE       0xAA
 #define EDM_STOP_BYTE        0x55
-#define EDM_HDR_LEN          5
+#define EDM_HDR_LEN          6
 #define MAX_EDM_PAYLOAD_LEN  (4096-1)
 #define MIN_EDM_PAYLOAD_LEN (2)
 #define MAX_HTTP_HEADER_LINES
@@ -73,6 +73,32 @@
   AT_HTTP_RESP_DOWNLOAD
 }at_cmd_resp_t;
 
+typedef enum edm_msg_id
+{
+  CONNECT_MSG_ID    = 0x0010,
+  DISCONNECT_MSG_ID = 0x0020,
+  DATA_MSG_ID       = 0x0030,
+  AT_MSG_ID         = 0x0040   
+}edm_msg_id_t;
+
+
+typedef enum edm_msg_type
+{
+  EVENT_MSG_TYPE        = 0x01,
+  INDICATION_MSG_TYPE   = 0x02,
+  RESPONSE_MSG_TYPE     = 0x03,
+  REQUEST_MSG_TYPE      = 0x04,
+  CONFIRMATION_MSG_TYPE = 0x05,
+  COMMAND_MSG_TYPE      = 0x06
+}edm_msg_type_t;
+
+typedef enum channel_id
+{
+  WIFI_CHANNEL          = 0x00,
+  BLE_CHANNEL           = 0x01
+}channel_id_t;
+
+
 
 typedef enum at_data_mode
 {
@@ -122,19 +148,22 @@
 
 typedef struct {
     http_method   method;       /* POST/GET etc... */
-    std::string   request_URI;  /* request URI/path */
-    std::string   http_version; /* http verstion HTTP/1.1 */
-    std::string   hostName;     /* host name */
-    std::string   AcceptVal;    /* types accepted */
-    std::string   contentType;  /* content type */
-    std::string   contentLen;   /* content length as string   */
-    uint8_t       body[900];    /* body     */
+    char *        request_URI;  /* request URI/path */
+    char *        http_version; /* http verstion HTTP/1.1 */
+    char *        hostName;     /* host name */
+    char *        AcceptVal;    /* types accepted */
+    char *        contentType;  /* content type */
+    char *        contentLen;   /* content length   */
+    uint8_t *     body;         /* body     */
+    uint8_t       buffer[TX_BUFFER_LEN - 8*sizeof(char *) 
+                                     - sizeof(http_method)]; // buffer   
 } http_request_t;
 
 typedef struct {
     uint8_t       startByte;   /* start Byte 0xAA */
     uint16_t      payloadLen;  /* payload Length */
     uint16_t      payloadID;   /* payload identifier     */
+    channel_id_t  channel_id;   /* channel_id_t*/
 } edm_header_t;
 
 typedef struct {
@@ -146,8 +175,7 @@
 typedef struct {
     uint8_t       peer_id          ;  /* peer id */
     conn_scheme_t connectionScheme;   /* connection scheme     */
-    //string     *  url;          /* body     */
-    char        url[MAX_URL_LEN];          /* body     */
+    char          url[MAX_URL_LEN];   /* url string     */
 } internet_config_t;
 
 #endif  // __COMMON_TYPES_H__
\ No newline at end of file
--- a/source/wifi_demo.cpp	Mon Apr 01 08:00:41 2019 +0000
+++ b/source/wifi_demo.cpp	Sun Apr 07 10:52:37 2019 +0000
@@ -13,7 +13,14 @@
     for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
         device->printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
     }
+    char * body = (char *) res->get_body();
     device->printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+        for (size_t ix = 0; ix < res->get_body_length(); ix++) {
+        device->printf("%02X: ", body[ix]);
+        if((ix % 32) == 0 and ix)
+        device->printf("\n");
+    }
+
 }
 
 void completed(){
@@ -53,6 +60,7 @@
     wait(1); // wait for 1 sec 
 
     mbed_trace_init();
+#ifdef RUN_ALL    
     wait(1); // wait for 1 sec 
 
     // GET request to os.mbed.com
@@ -201,7 +209,6 @@
     }
 
     wait(1); // wait for 1 sec 
-
     // POST request to httpbin.org
     if(false)
     {
@@ -230,6 +237,61 @@
 
         delete post_req;
     }
+    
+#endif
+    
+        // POST request to dev2.dnanudge.io
+    if(true)
+    {
+        device->printf("\n----- HTTPS POST request to dev2.dnanudge.io -----\n");
+        TLSSocket*            socket;
+        socket = new TLSSocket();
+        char hostName[] = "dev2.dnanudge.io";
+        nsapi_error_t r;
+        // make sure to check the return values for the calls below (should return NSAPI_ERROR_OK)
+        r = socket->open(network);
+        if(r != NSAPI_ERROR_OK)
+        { 
+            printf("TLS open failed!!\n");
+            return 0;
+        }
+        printf("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");
+            return 0;
+        }
+        printf("TLS set_root_ca_cert passed!!\n");
+        r = socket->connect(hostName, 443);
+        if(r != NSAPI_ERROR_OK)
+        { 
+            printf("TLS connect failed for hostname %s!!\n", hostName);
+            return 0;
+        }
+        printf("TLS connection successful for https site :  %s\n", hostName);
+        //HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://dev2.dnanudge.io/nudgebox/v1");
+        HttpsRequest* post_req = new HttpsRequest(socket, HTTP_POST, "https://dev2.dnanudge.io/nudgebox/v1");
+        //post_req->set_header("Content-Type", "application/json");
+        post_req->set_header("Accept", "*/*");
+        post_req->set_header("Content-Type", "application/octet-stream");
+        post_req->set_header("Content-Length", "20");
+
+        const char body[] = {0x00, 0x08, 0x6a, 0x48, 0xf8, 0x2d, 0x8e, 
+                             0x82, 0x01, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x67, 
+                             0xc3, 0x19, 0xf8};
+        HttpResponse* post_res = post_req->send(body, 20);
+        if (!post_res) {
+            device->printf("HttpRequest failed (error code %d)\n", post_req->get_error());
+            return 1;
+        }
+
+        device->printf("\n----- HTTPS POST response from dev2.dnanudge.io -----\n");
+        dump_response(post_res);
+
+        delete post_req;
+    }
+
      wait(1); // wait for 1 sec 
      delete device;
      return 0;