leandropg wrote on August 15, 2019:
Hello,
I am developing with AWS FreeRTOS 201906.00_Major over Microchip Curiosity PIC32MZ EF board. Currently I have using the Secure Socket Library for connecting from a FreeRTOS Task to a AWS Lambda Function.
https://docs.aws.amazon.com/freertos/latest/lib-ref/html2/secure_sockets/index.html
I have implemented TX and RX using AWS Secure Sockets and it works. But I have a problem: the time consumed. When I am sending and recieve data from the AWS Lambda Function, this process takes between 3 to 10 seconds in send and receive data when the Lambda function takes only 500 ms from a computer.
I have reviewed that the function SOCKETS_Recv and it takes much time. I understood in the documentation that this function wait an specific quantity of bytes, and when it does not receive any wait the timeout time before realease the read data, although the data is in the buffer. I am worry with the response time, because we are building a system that must send much data by second to the cloud and it is a serious problem.
Aditionally, with the Ethernet Module setting the timeout (Send: 1000 ms / Receive: 500 ms) the send and receive works fine. But when I use the WIFI Module setting timeout (Send: 5000 ms / Receive: 5000 ms) sometimes works and another I obtained SOCKETS_TLS_HANDSHAKE_ERROR before the start the transmission. Another times I obtain DNS Lookup Failed!
I want understand what is the real problem with use this library, because with FreeRTOS sockets the situation is the same. I extracted some the code for that you understand my implementation. I use the Amazon Root CA 1 certificate and works https://www.amazontrust.com/repository/AmazonRootCA1.pem
Thank you.
BaseType_t connectErrorCode;
Socket_t xClientSocket;
static const TickType_t xTimeOutSend = pdMS_TO_TICKS(5000);
static const TickType_t xTimeOutReceive = pdMS_TO_TICKS(5000);
xClientSocket = SOCKETS_Socket(SOCKETS_AF_INET,
SOCKETS_SOCK_STREAM,
SOCKETS_IPPROTO_TCP);
if(xClientSocket != SOCKETS_INVALID_SOCKET) {
SOCKETS_SetSockOpt(xClientSocket, 0, SOCKETS_SO_RCVTIMEO, &xTimeOutSend, sizeof(xTimeOutSend));
SOCKETS_SetSockOpt(xClientSocket, 0, SOCKETS_SO_SNDTIMEO, &xTimeOutReceive, sizeof(xTimeOutReceive));
SOCKETS_SetSockOpt(xClientSocket, 0, SOCKETS_SO_REQUIRE_TLS, NULL, ( size_t ) 0 );
SOCKETS_SetSockOpt(xClientSocket, 0, SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE, cTlsECHO_SERVER_CERTIFICATE_PEM, ulTlsECHO_SERVER_CERTIFICATE_LENGTH );
ulRemoteIPAddress = SOCKETS_GetHostByName("MY_URL");
if (ulRemoteIPAddress != 0) {
xRemoteAddress.usPort = SOCKETS_htons(443);
xRemoteAddress.ulAddress = ulRemoteIPAddress;
connectErrorCode = SOCKETS_Connect(xClientSocket, &xRemoteAddress, sizeof(xRemoteAddress));
if(connectErrorCode == 0) {
httpPostResponsePtr = &httpPostResponse[0];
httpPostResponseLength = 0;
qtyDataToSend = sprintf(httpPostQuery, "MY_POST_REQUEST");
qtyDataSent = SOCKETS_Send(xClientSocket, &httpPostQuery[0], qtyDataToSend, 0);
if(qtyDataSent > 0) {
do {
qtyDataReceived = SOCKETS_Recv(xClientSocket, &bufferTcpRx[0], 1024, 0);}
if (qtyDataReceived > 0) {
bufferTcpRxPtr = &bufferTcpRx[0];
for (i = 0; i < qtyDataReceived; i++) {
*httpPostResponsePtr++ = *bufferTcpRxPtr++;
httpPostResponseLength++;
}
}
} while(qtyDataReceived > 0);
SOCKETS_Shutdown(xClientSocket, SOCKETS_SHUT_RDWR);
}
}
SOCKETS_Close(xClientSocket);
}