this is using the mbed os version 5-13-1
Revision 107:f1a83fd41b17, committed 2019-05-06
- Comitter:
- ocomeni
- Date:
- Mon May 06 16:44:40 2019 +0000
- Branch:
- PassingRegression
- Parent:
- 106:e1f04c3d0647
- Child:
- 108:3c8fb2c6e7bf
- Commit message:
- now succefully sending and responsing to Box cloud message up till BLE ID and OTP request
Changed in this revision
--- a/source/ATCmdManager.cpp Mon May 06 10:24:53 2019 +0000
+++ b/source/ATCmdManager.cpp Mon May 06 16:44:40 2019 +0000
@@ -742,6 +742,7 @@
}
#define TTP_DEBUGGING
+#define TTP_DEBUGGING_UART_NOCHANGE
void ATCmdManager::_oob_uart_setup(){
int uOpts[NUM_UART_OPTIONS];
//if(_parser.recv("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5])) {
@@ -750,12 +751,12 @@
//printf("\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]);
//AT+UMRS=230400,2,8,1,1,1
dbg_printf(LOG, "\n Changing Baud Rate to %d\n", uOpts[0]);
-#ifdef TTP_DEBUGGING
+#ifdef TTP_DEBUGGING_UART_NOCHANGE
sendAtConfirmation(OK_RESP);
#else
sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
- wait(0.1);
+ //wait(0.1);
_serial.set_baud(uOpts[0]);
wait(0.1);
dbg_printf(LOG, "\n Baud Rate now %d\n", uOpts[0]);
--- a/source/WiFiManager.cpp Mon May 06 10:24:53 2019 +0000
+++ b/source/WiFiManager.cpp Mon May 06 16:44:40 2019 +0000
@@ -58,8 +58,9 @@
watchdogCnt++;
if(watchdogCnt >= 6 && responseString==NULL) // every minute
{
- responseString = (char *) malloc(100);
- sprintf(responseString, "\r\n[WiFi-MAN] WiFi Manager Alive\r\n");
+ responseString = (char *) malloc(120);
+ sprintf(responseString, "\r\n[WiFi-MAN] WiFi Manager Alive : state = %d busy = %d httpsConnActive = %d\r\n",
+ wifiCmd, wifiBusy, https_connection_active);
sendATresponseString(WIFI_WATCH_DOG);
watchdogCnt = 0;
}
@@ -67,7 +68,7 @@
{
if(wifiCmd == WIFI_CMD_NONE)
inactivity_monitor++;
- responseString = (char *) malloc(100);
+ responseString = (char *) malloc(120);
sprintf(responseString, "\r\n[WiFi-MAN] Main Loop InActive : state = %d busy = %d httpsConnActive = %d\r\n",
wifiCmd, wifiBusy, https_connection_active);
sendATresponseString(WIFI_WATCH_DOG);
@@ -172,11 +173,24 @@
wifiBusy = 0;
break;
case WIFI_CMD_INTERNET_CONFIG:
+ {
wifiBusy = 1;
+ backgroundTaskCompleted = false;
set_internet_config();
- queueATresponse(AT_INTERNET_CONFIG_RESP);
+ int msecCount = 0;
+ while(!backgroundTaskCompleted && msecCount < 1000)
+ {
+ msecCount++;
+ wait_ms(10);
+ }
+ if(backgroundTaskCompleted)
+ {
+ queueATresponse(AT_INTERNET_CONFIG_RESP);
+ }
+ backgroundTaskCompleted = false;
wifiCmd = WIFI_CMD_NONE;
break;
+ }
case WIFI_CMD_NETWORK_STATUS:
wifiBusy = 1;
getNetworkStatus();
@@ -192,6 +206,7 @@
wifiBusy = 0;
break;
case WIFI_CMD_SEND_HTTPS_REQ:
+ {
wifiBusy = 1;
if(responseString == NULL)
{
@@ -203,7 +218,32 @@
dbg_printf(LOG, "\r\n[WIFI-MAN] Received HTTPS request...\r\n");
print_memory_info();
//network->attach(NULL);
+#ifdef USE_EVENTS_FOR_HTTPS_REQUESTS
+
+ // Events can be cancelled as long as they have not been dispatched. If the
+ // event has already expired, cancel has no side-effects.
+ int event_id = _event_queue.call(this, &WiFiManager::createSendHttpsRequest);
+ backgroundTaskCompleted = false;
+ int msecCount = 0;
+ while(!backgroundTaskCompleted && msecCount < 1000)
+ {
+ msecCount++;
+ wait_ms(10);
+ }
+ if(backgroundTaskCompleted)
+ {
+ queueATresponse(AT_INTERNET_CONFIG_RESP);
+ result = true;
+ }
+ else
+ {
+ _event_queue.cancel(event_id);
+ result = false;
+ }
+ backgroundTaskCompleted = false;
+#else
result = createHttpsRequest();
+#endif
if(result == false)
{
responseString = (char *) malloc(100);
@@ -223,6 +263,7 @@
wifiBusy = 0;
//network->attach(callback(this, &WiFiManager::status_callback));
break;
+ }
case WIFI_CMD_SEND_HTTP_REQ:
break;
default:
@@ -233,6 +274,10 @@
}
+void WiFiManager::createSendHttpsRequest()
+{
+ backgroundTaskCompleted = createHttpsRequest();
+}
void WiFiManager::sendATresponseString(at_cmd_resp_t at_cmd)
{
@@ -267,7 +312,7 @@
// set string length
at_data_resp->dataLen = len;
memcpy(at_data_resp->buffer, responseBytes, len);
- free(responseBytes);
+ delete responseBytes;
responseBytes = NULL;
// package and send on wifi data queue
at_data_resp->at_resp = at_cmd;
@@ -685,11 +730,12 @@
void WiFiManager::gethostbyname_callback(nsapi_error_t result, SocketAddress *address)
{
dbg_printf(LOG, "gethostbyname_callback called... result = %d \r\n", result);
- responseBytes = (uint8_t *) malloc(HOSTNAME_RESPONSE_LEN);
+ print_memory_info();
+ responseBytes = new uint8_t[HOSTNAME_RESPONSE_LEN]; //malloc(HOSTNAME_RESPONSE_LEN);
int i = 0;
responseBytes[i++] = IPv4_CONNECTION; // connect type IPv4
responseBytes[i++] = TCP_PROTOCOL; // Protocol = TCP
- if(is_connected && result>0)
+ if(is_connected && result>=0)
{
memcpy(&responseBytes[i], address->get_ip_bytes(), 4); // remote IPv4 address
strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
@@ -711,15 +757,24 @@
responseBytes[i++] = 0;
responseBytes[i] = 0;
printBufferInHex(responseBytes, HOSTNAME_RESPONSE_LEN);
+ _event_queue.call_in(10, this, &WiFiManager::sendATresponseBytes,
+ CONNECT_EVENT, HOSTNAME_RESPONSE_LEN);
}
else
{
// if unconnected set ip and port to zeroes
memset(&responseBytes[i], 0x00, 6);
- }
- _event_queue.call_in(2, this, &WiFiManager::sendATresponseBytes,
- CONNECT_EVENT, HOSTNAME_RESPONSE_LEN);
+ delete responseBytes;
+ dbg_printf(LOG, "\r\nHOSTNAME TRANSLATION FAILURE : error code = %d \r\n", result);
+ if(responseString == NULL)
+ {
+ //responseString = (char *) malloc(100);
+ //sprintf(responseString, "\r\nHOSTNAME TRANSLATION FAILURE : error code = %d \r\n", result);
+ //sendATresponseString(AT_EVENT);
+ }
+ }
wifiBusy = 0;
+ backgroundTaskCompleted = true;
}
@@ -976,8 +1031,12 @@
void WiFiManager::sendDebugMessage()
{
+#ifdef SEND_HTTPS_DEBUG_MESSAGES
sendATresponseString(AT_EVENT);
wait_ms(100);
+#else
+ free(responseString);
+#endif
}
#define TESTING_HTTPS
--- a/source/WiFiManager.h Mon May 06 10:24:53 2019 +0000
+++ b/source/WiFiManager.h Mon May 06 16:44:40 2019 +0000
@@ -52,6 +52,7 @@
char* responseString; // response string formated for Box
uint8_t* responseBytes; // response bytes formated for Box
wifi_cmd_t wifiCmd;
+ bool backgroundTaskCompleted;
//at_data_msg_t *at_data_resp;
int chunkNum;
/* Queue and memory pool for AT to Wifi commands */
@@ -73,6 +74,7 @@
bool is_connected;
bool http_response_hdr_sent;
+ bool http_request_result;
int wifiBusy;
Timer wifiWatchdogTimer;
uint32_t watchdogCnt;
@@ -87,6 +89,7 @@
void set_internet_config();
nsapi_error_t connect();
nsapi_error_t disconnect();
+ void createSendHttpsRequest();
bool createHttpsRequest();
void createHttpRequest(http_method method,
const char* url,
--- a/source/debug.cpp Mon May 06 10:24:53 2019 +0000
+++ b/source/debug.cpp Mon May 06 16:44:40 2019 +0000
@@ -91,7 +91,7 @@
* @param None
* @retval None
*/
-#define DEBUG_ENABLED
+//#define DEBUG_ENABLED
void initialise_debug(void)
{
memset(g_dbg_buffer, 0, sizeof(g_dbg_buffer));
--- a/source/main-https.cpp Mon May 06 10:24:53 2019 +0000 +++ b/source/main-https.cpp Mon May 06 16:44:40 2019 +0000 @@ -54,7 +54,7 @@ uint8_t TxBuffer[TX_BUFFER_LEN]; uint8_t RxBuffer[RX_BUFFER_LEN]; #endif -static EventQueue eventQueue(/* event count */ 20 * EVENTS_EVENT_SIZE); +static EventQueue eventQueue(/* event count */ 32 * EVENTS_EVENT_SIZE); //static EventQueue eventQueue2(/* event count */ 10 * EVENTS_EVENT_SIZE); LEDService *ledServicePtr;