this is using the mbed os version 5-13-1
Revision 96:f5ed273881af, committed 2019-04-19
- Comitter:
- ocomeni
- Date:
- Fri Apr 19 08:51:58 2019 +0000
- Parent:
- 95:290859010c8c
- Child:
- 97:0aa46e5ef15d
- Commit message:
- response instability issues resolved. ; Able to run 10 consecutive hello cloud requests.
Changed in this revision
--- a/source/ATCmdManager.cpp Wed Apr 17 18:11:45 2019 +0000
+++ b/source/ATCmdManager.cpp Fri Apr 19 08:51:58 2019 +0000
@@ -93,110 +93,110 @@
break;
case AT_SCAN_RESP:
// AT_SCAN_RESP response state
- printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n");
//_smutex.lock();
//sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
//_smutex.unlock();
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
at_resp = AT_RESP_NONE;
break;
case AT_DETAILED_SCAN_RESP:
// AT_DETAILED_SCAN_RESP response state
- printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n");
//_smutex.lock();
//sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
//_smutex.unlock();
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
at_resp = AT_RESP_NONE;
break;
case AT_CONNECT_RESP:
// AT_CONNECT_RESP response state
- printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n");
//_smutex.lock();
//sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
//_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");
+ printf("\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n");
//_smutex.lock();
//sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
//_smutex.unlock();
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
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();
+ printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n");
+ //_smutex.lock();
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
at_resp = AT_RESP_NONE;
break;
case AT_NETWORK_STATUS_RESP:
// AT_CONFIG_RESP response state
//////_smutex.lock();
- printf("\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n");
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
at_resp = AT_RESP_NONE;
break;
case AT_WIFI_STATUS_RESP:
// AT_CONFIG_RESP response state
//////_smutex.lock();
- printf("\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n");
respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
at_resp = AT_RESP_NONE;
break;
case AT_INTERNET_CONFIG_RESP:
// AT_CONFIG_RESP response state
- printf("\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n");
//_smutex.lock();
- //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
//_smutex.unlock();
- respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ //respStr = (char *) resp_data->buffer;
+ //sendAtConfirmationFreeMpool(respStr);
at_resp = AT_RESP_NONE;
break;
case AT_HTTPS_RESP:
// AT_HTTP_RESP response state
- printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n");
return_response();
- _smutex.lock();
+ //_smutex.lock();
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
at_resp = AT_RESP_NONE;
break;
case AT_HTTPS_RESP_DOWNLOAD:
// AT_HTTPS_RESP_DOWNLOAD response state
- printf("\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n");
return_response(true); // set download paramter to true
- _smutex.lock();
+ //_smutex.lock();
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
at_resp = AT_RESP_NONE;
break;
case AT_HTTP_RESP:
// AT_HTTP_RESP response state
- printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
return_response();
- _smutex.lock();
+ //_smutex.lock();
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
at_resp = AT_RESP_NONE;
break;
case AT_HTTP_RESP_DOWNLOAD:
// AT_HTTP_RESP response state
- printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n");
+ printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
return_response(true); // set download paramter to true
//_smutex.lock();
//sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
@@ -205,25 +205,34 @@
break;
case AT_COMMAND_FAILED:
// AT_HTTP_RESP response state
- printf("\n [ATCMD MAN] WIFI COMMAND FAILED!!\n");
+ printf("\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n");
//_smutex.lock();
//_parser.send("\r\nNACK\r\n");
//_smutex.unlock();
char * respStr = (char *) resp_data->buffer;
- sendAtConfirmation(respStr);
+ sendAtConfirmationFreeMpool(respStr);
AT_RESP_NONE;
break;
default:
// UNKNOWN response state
//_smutex.lock();
- printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\n");
- sendAtConfirmation(ERROR_RESP); //_parser.send(OK_RESP);
+ printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
+ sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP);
//_smutex.unlock();
at_resp = AT_RESP_NONE;
break;
}
}
+
+void ATCmdManager::sendAtConfirmationFreeMpool(const char *buf)
+{
+ sendAtConfirmation(buf);
+ _wiFi2ATDatamPool->free(resp_data);
+ resp_data = NULL;
+}
+
+
void ATCmdManager::printBufferInHex(uint8_t *buf, int pLen)
{
for(int i =0;i<pLen;i++){
@@ -447,10 +456,11 @@
break;
case DATA_COMMAND:
printf("DATA_COMMAND received!\n");
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
if(createHttpRequest() == true){
- _smutex.lock();
- sendAtConfirmation(OK_RESP); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.lock();
+ //sendAtConfirmation(OK_RESP); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
+ //_smutex.unlock();
}
else{
_smutex.lock();
@@ -458,6 +468,7 @@
_smutex.unlock();
}
free(rx_buf_ptr);
+ rx_buf_ptr = NULL;
int stop = Kernel::get_ms_count();
printf("\n Time Elapsed = %d\n", stop-start);
break;
@@ -498,9 +509,9 @@
}
void ATCmdManager::_oob_ok_hdlr(){
- _smutex.lock();
+ //_smutex.lock();
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
}
@@ -551,31 +562,32 @@
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);
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _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);
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _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);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
switch(dataMode)
{
case 0:
@@ -598,13 +610,12 @@
} else {
printf("\nATCmdParser: Retrieving Uart Options failed\n");
}
- sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
}
void ATCmdManager::_oob_get_mac_addr(){
int bleOrWifi;
- _smutex.lock();
+ //_smutex.lock();
if(_parser.scanf("=%d", &bleOrWifi) >0) {
switch(bleOrWifi)
{
@@ -622,30 +633,30 @@
printf("\nATCmdParser: Retrieving Uart Options failed");
}
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
}
void ATCmdManager::_oob_get_ble_role(){
- _smutex.lock();
+ //_smutex.lock();
printf("\n Received get BLE role command!!\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
}
void ATCmdManager::_oob_ena_ble_peri(){
- _smutex.lock();
+ //_smutex.lock();
printf("\n Received enable BLE Peripheral command!!\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
}
void ATCmdManager::_oob_reboot(){
- _smutex.lock();
+ //_smutex.lock();
printf("\n Received reboot command!!\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
_parser.send("System Resetting....\n");
system_reset();
- _smutex.unlock();
+ //_smutex.unlock();
}
const char * ATCmdManager::sec2str(nsapi_security_t sec)
@@ -678,10 +689,10 @@
void ATCmdManager::_oob_scanWiFiNetworks(){
- _smutex.lock();
+ //_smutex.lock();
printf("\n Received scanWiFiNetworks command!!\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- _smutex.unlock();
+ //_smutex.unlock();
wifi_cmd_t cmd = WIFI_CMD_SCAN;
// queue next command
queueWiFiCommand(cmd);
@@ -696,7 +707,7 @@
action_id_t action_id; // interface id for request
_parser.scanf("%d,%d", &if_id, &action_id);
//_smutex.lock();
- printf("\n Received WiFi Configuration Action command!!\n");
+ printf("\n Received WiFi Configuration Action command!!\r\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
if(if_id == WIFI_CONFIG_ID && (uint8_t)action_id <5){
wifi_cmd_t cmd;
@@ -731,11 +742,11 @@
void ATCmdManager::_oob_disconnectWiFiNetwork()
{
- _smutex.lock();
+ //_smutex.lock();
printf("\n Received WiFi Disconnect command!!\n");
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
wifi_cmd_t cmd = WIFI_CMD_DISCONNECT;
- _smutex.unlock();
+ //_smutex.unlock();
// queue next command
queueWiFiCommand(cmd);
return;
@@ -747,7 +758,7 @@
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, MAX_URL_LEN);
str[n]=NULL;
@@ -779,15 +790,15 @@
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 );
memcpy(data_msg.buffer,&internet_config, data_msg.dataLen);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
// queue next data request
queueWiFiDataRequest(data_msg);
print_memory_info();
- sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
} else {
- printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \n", n);
+ printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n);
_parser.send("NAK\n");
}
- _smutex.unlock();
+ //_smutex.unlock();
}
wifi_config_t ATCmdManager::init_wifi_config()
@@ -836,7 +847,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)
@@ -847,20 +858,20 @@
data_msg.wifi_cmd = WIFI_CMD_CONFIG;
data_msg.dataLen = sizeof(wifi_config_t);
memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
queueWiFiDataRequest(data_msg);
- sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
} else {
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)
@@ -871,13 +882,13 @@
data_msg.wifi_cmd = WIFI_CMD_CONFIG;
data_msg.dataLen = sizeof(wifi_config_t);
memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
queueWiFiDataRequest(data_msg);
- sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
} else {
printf("\n[ATCMD MAN]: wifi configuration failed \n");
_parser.send("NAK\n");
}
- _smutex.unlock();
+ //_smutex.unlock();
}
void ATCmdManager::_oob_setWiFiSecurity()
@@ -895,8 +906,8 @@
data_msg.wifi_cmd = WIFI_CMD_CONFIG;
data_msg.dataLen = sizeof(wifi_config_t);
memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
+ sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
queueWiFiDataRequest(data_msg);
- sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
} else {
printf("\n[ATCMD MAN]: wifi configuration failed \n");
_smutex.lock();
@@ -996,8 +1007,10 @@
setNextResponse(resp->at_resp);
#ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
_wiFi2ATmPool->free(resp);
+ resp = NULL;
#else
free(resp);
+ resp = NULL;
#endif
}
return true;
@@ -1030,6 +1043,7 @@
void ATCmdManager::sendAtConfirmation(const char *buf)
{
+ _smutex.lock();
switch(dataMode){
case AT_CMD_DATA_MODE:
_parser.send(buf);
@@ -1038,16 +1052,19 @@
_parser.send(buf);
break;
case AT_EXT_DATA_MODE:
- int len = strlen(buf) + 1;
+ int len = strlen(buf);
outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
break;
default:
_parser.send(buf);
break;
}
+ //wait_ms(1);
+ _smutex.unlock();
}
void ATCmdManager::sendAtEvent(const char *buf)
{
+ _smutex.lock();
switch(dataMode){
case AT_CMD_DATA_MODE:
_parser.send(buf);
@@ -1056,13 +1073,14 @@
_parser.send(buf);
break;
case AT_EXT_DATA_MODE:
- int len = strlen(buf) + 1;
+ int len = strlen(buf);
outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
break;
default:
_parser.send(buf);
break;
}
+ _smutex.unlock();
}
void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen,
@@ -1070,6 +1088,8 @@
channel_id_t channel_id)
{
int epLen = pLen + 2; // edm payload length = data length + 2
+ if(channel_id != NO_CHANNEL)
+ epLen += 1;
_smutex.lock();
// send EDM Message start byte
_parser.putc(EDM_START_BYTE);
@@ -1086,6 +1106,8 @@
_parser.write((const char *)buf, pLen);
// send EDM Message stop byte
_parser.putc(EDM_STOP_BYTE);
+ int msWait = (pLen + 5+20)/20;
+ wait_ms(msWait);
_smutex.unlock();
}
@@ -1106,7 +1128,7 @@
EVENT_MSG_TYPE, WIFI_CHANNEL);
_smutex.unlock();
_wiFi2ATDatamPool->free(resp_data);
-
+ resp_data = NULL;
//print_memory_info();
print_heap_and_isr_stack_info();
}
--- a/source/ATCmdManager.h Wed Apr 17 18:11:45 2019 +0000
+++ b/source/ATCmdManager.h Fri Apr 19 08:51:58 2019 +0000
@@ -117,6 +117,7 @@
channel_id_t channel_id);
void sendAtConfirmation(const char *buf);
+ void sendAtConfirmationFreeMpool(const char *buf);
void sendAtEvent(const char *buf);
/**
--- a/source/WiFiManager.cpp Wed Apr 17 18:11:45 2019 +0000
+++ b/source/WiFiManager.cpp Fri Apr 19 08:51:58 2019 +0000
@@ -183,8 +183,10 @@
setNextCommand(cmd->wifi_cmd);
#ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
_aT2WiFimPool->free(cmd);
+ cmd = NULL;
#else
free(cmd);
+ cmd = NULL;
#endif
}
return true;
@@ -450,6 +452,7 @@
{
// free memory after processing
_aT2WiFiDatamPool->free(data_msg);
+ data_msg = NULL;
}
@@ -518,7 +521,7 @@
}
printf("[WIFI-MAN] Connecting to network ssid = %s passwd = %s security = %s \r\n",
wifi_config.ssid,
- wifi_config.pass,
+ "****************",
sec2str(wifi_config.security));
error = network->connect(wifi_config.ssid,
wifi_config.pass,
@@ -537,7 +540,11 @@
void WiFiManager::sendResponseDownloadData(at_cmd_resp_t at_cmd, const uint8_t * buf, int bufLen)
{
+ printf("before call to new at_data_msg_t \n");
+ print_memory_info();
at_data_resp = new at_data_msg_t;
+ printf("after call to new at_data_msg_t \n");
+ print_memory_info();
at_data_resp->at_resp = at_cmd;
size_t bufSize = sizeof(at_data_resp->buffer);
int pos = 0;
@@ -583,11 +590,40 @@
// 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());
+ printf("after getting HTTP status line \n");
+ print_memory_info();
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());
+ //vector<string*> hdrFields(http_response->get_headers_fields());
+ //hdrFields.reserve(http_response->get_headers_length());
+ //printf("after defining HTTP header fields vector \r\n");
+ //hdrFields = http_response->get_headers_fields();
+ //printf("after getting HTTP header fields \n");
+ //print_memory_info();
+ //vector<string*> hdrValues(http_response->get_headers_values());
+ //printf("after getting HTTP header values \n");
+ //print_memory_info();
+ int hdrsLen = http_response->get_headers_length();
+ printf("after getting HTTP headers length = %d\n", hdrsLen);
+ print_memory_info();
+ for (size_t ix = 0; ix < hdrsLen; ix++) {
+ int sLen = http_response->get_headers_fields()[ix]->size()+1;
+ printf("before creating allocation HTTP headers field [size = %d] \n", sLen);
+ char * hdrField = (char *) malloc(sLen);
+ printf("after creating allocation HTTP headers field \n");
+ print_memory_info();
+ std::strcpy (hdrField, http_response->get_headers_fields()[ix]->c_str());
+ printf("after getting HTTP headers field copy \n");
+ print_memory_info();
+ char * hdrValue = new char [http_response->get_headers_values()[ix]->size()+1];
+ std::strcpy (hdrValue, http_response->get_headers_values()[ix]->c_str());
+ numChars = sprintf(msgPtr, "%s: %s\r\n", hdrField, hdrValue);
+ //numChars = sprintf(msgPtr, "%s: %s\r\n",
+ // http_response->get_headers_fields()[ix]->c_str(),
+ // http_response->get_headers_values()[ix]->c_str());
+ printf("after call #%d to get http header field:values \r\n", ix);
+ print_memory_info();
+ free(hdrField);
+ delete hdrField;
msgPtr += numChars;
}
numChars = sprintf(msgPtr, "\r\n");
@@ -693,11 +729,16 @@
return true;
}
#define TESTING_HTTPS
+//#define DONT_USE_TLS_SOCKET
void WiFiManager::createHttpsRequest()
{
// reset chunk #;
chunkNum = 0;
+#ifdef MIX_HDR_AND_BODY
http_response_hdr_sent = false;
+#else
+ http_response_hdr_sent = true;
+#endif
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);
@@ -767,10 +808,10 @@
free_DataMsg();
return;
}
- printf("[create https] TLS connection successful for https site : %s\n", host);
+ //printf("[create https] TLS connection successful for https site : %s\n", host);
+ printf("after call to createTLSconnection \n");
+ print_memory_info();
}
- 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();
@@ -796,17 +837,21 @@
http_response = https_request->send(NULL, 0);
}
else{
+ printf("about to setup https headers\r\n");
setHttpsHeader("Host", http_req_cfg->hostName);
setHttpsHeader("Accept", http_req_cfg->AcceptVal);
setHttpsHeader("Content-Type", http_req_cfg->contentType);
setHttpsHeader("Content-Length", http_req_cfg->contentLen);
+ printf("https headers setup - about to send request\r\n");
+ //_wmutex.lock();
http_response = https_request->send(http_req_cfg->body, bodyLen);
+ //_wmutex.unlock();
}
#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);
#endif
@@ -817,20 +862,29 @@
mbedtls_strerror(https_request->get_error(), buf, 100);
printf("HttpsRequest failed (error code %s)\n", buf);
delete https_request; // free the memory
+ https_request = NULL;
https_connection_active = false; // reset true whenever connection fails
delete socket;
+ socket = NULL;
free_DataMsg();
return;
}
https_connection_active = true; // set true whenever connection succeeds
printf("\n----- HTTPS POST response -----\r\n");
- }
- if(http_response != NULL){
- //return_response(http_response);
- delete http_response; // free the response memory
}
- free_DataMsg();
- //delete https_request; // free the request memory
+ if(http_response != NULL){
+
+#ifndef MIX_HDR_AND_BODY
+ return_response(http_response);
+#endif
+ //delete http_response; // free the response memory
+ //http_response = NULL;
+ //printf("deleted http_response\r\n");
+ }
+ free_DataMsg();
+ delete https_request; // free the request & response memory
+ printf("deleted https_request\r\n");
+ https_request = NULL;
}
void WiFiManager::createHttpRequest(http_method method,