ATWINC1500 throughput with TLS

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to determine what the upper limit for data transfer speeds are with the ATWINC1500 module under a TCP socket connection secured with TLS. I've seen a few discussions on here of overall ATWINC1500 transfer rates under TCP, with this one the most relevant, and it seems like people can get around 300-350 kilobyte per second transfer rates. I'm getting that rate over an open TCP connection, but with a TLS connection that drops to about 100 kilobyte per second for me. The code for running the data transfer is exactly the same between the open TCP and TLS cases, other than the fact that I'm opening the TCP socket with the SOCKET_FLAGS_SSL flag. Just to make sure this was the WINC and not the remote server, I wrote a python script on my PC to test transfer rates from my local network to the server, and was getting >5MBps. 

 

Is ~100 kBps the upper limit for the WINC under a TLS connection? Anything I could do to speed things up? Any other ideas of things to look into?

 

Here is the code where the TCP/TLS connection is opened - this is right from the ATWINC1500 library SSL example:

if (gbConnectedWifi && !gbTcpConnection) {
		if (gbHostIpByName) {
			/* Open TCP client socket. */
			if (tcp_client_socket < 0) {
				if ((tcp_client_socket = socket(AF_INET, SOCK_STREAM, SOCKET_FLAGS_SSL)) < 0) {
					printf("main: failed to create TCP client socket error!\r\n");
					return;
				}
			}

			/* Connect TCP client socket. */
			addr_in.sin_family = AF_INET;
			addr_in.sin_port = _htons(MAIN_SERVER_PORT);
			addr_in.sin_addr.s_addr = gu32HostIp;
			if (connect(tcp_client_socket, (struct sockaddr *)&addr_in, sizeof(struct sockaddr_in)) != SOCK_ERR_NO_ERROR) {
				printf("main: failed to connect socket error!\r\n");
				return;
			}

			gbTcpConnection = true;
		}
	}

 

And the code running the transfer (BLOCK_SIZE=1400):

static void binary_bulk_transfer(void)
{
	static uint8_t status = 0;					/* 0 = not started, 1 = in progress, 2 = complete */
	static uint16_t blockCounter = 0;		/* counter for number of blocks transferred */	
	static uint8_t errCounter = 0;			/* counter for transmission errors, to implement timeout */
	static bool waitMessageSent = false;
	
	/* number of blocks to transmit (total transfer size is numBlocks * BLOCK_SIZE bytes */
	const uint32_t numBlocks = 10000;
	const uint32_t printInterval = 1000;
				
	/* buffer to hold a single block of data */
	static uint8_t dummyBuffer[BLOCK_SIZE];
	
	switch (status)
	{
		case 0:
			/* start transmission */
			gu16SendCount = 0;
		
			/* populate the block with dummy binary data */
			for (uint16_t i = 0; i < BLOCK_SIZE; i++)
				dummyBuffer[i] = (uint8_t) (i & 0xFF);
		
			/* initialize the transmit string buffer */
			m2m_memset(gau8ReceivedBuffer, 0, sizeof(gau8ReceivedBuffer));
		
			/* send header - number of bytes we'll be sending */
			gau8ReceivedBuffer[0] = numBlocks >> 8;
			gau8ReceivedBuffer[1] = numBlocks & 0xFF;
			gau8ReceivedBuffer[2] = BLOCK_SIZE >> 8;
			gau8ReceivedBuffer[3] = BLOCK_SIZE & 0xFF;			
			gau8ReceivedBuffer[4] = 0;
			
			send(tcp_client_socket, gau8ReceivedBuffer, 4, 0);	
		
			/* update status */
			status++;
			
			/* set bulk transfer flag to true */
			gbBulkTransfer = true;
		
			break;
		case 1:
			/* transmit block */
			
			/* make sure we don't overload the buffer, wait for last send to complete before starting this one */
			if (blockCounter > (gu16SendCount+2))
			{
				if (!waitMessageSent) 
				{
					printf("waiting for send buffer to clear (block count = %d; send count = %d)\r\n", blockCounter, gu16SendCount);
					waitMessageSent = true;
				}
				break;
			}
		
			if (waitMessageSent)
			{
				printf("Resuming send of block %d\r\n", blockCounter);
				waitMessageSent = false;
			}		
						
			if (send(tcp_client_socket, dummyBuffer, BLOCK_SIZE, 0) == SOCK_ERR_NO_ERROR)
			{
				blockCounter++;
				errCounter = 0;
				
				if ((blockCounter % printInterval) == 0)
					printf("Sending block %d/%d\r\n", blockCounter+1, numBlocks);
			}
			else
			{
				printf("Error sending block %d\r\n", blockCounter+1);
				errCounter++;
				
				/* sleep to allow time for WINC to clear out backlog */
				// nm_bsp_sleep(100);				
			}						
			
			if (errCounter == 1000)
			{
				printf("Transmission timed out\r\n");
				status++;
			}
			
			if (blockCounter == numBlocks)
			{
				printf("Transmission finished\r\n");
				status++;
			}
			
			break;		
		case 2:
			/* complete transmission */
			gbBulkTransfer = false;
		
			/* clear main string buffer */
			// m2m_memset(gau8ReceivedBuffer, 0, MAIN_WIFI_M2M_BUFFER_SIZE);
					
			/* switch socket to receive mode */
			// recv(tcp_client_socket, &gau8ReceivedBuffer[0], MAIN_WIFI_M2M_BUFFER_SIZE, 0);
			
			// close socket
			close(tcp_client_socket);
			tcp_client_socket = -1;
		
		break;
		default:
			printf("Error in bulk transfer state machine\r\n");
			break;			
	}
}