added tls read timeout
This commit is contained in:
@ -30,7 +30,7 @@
|
||||
/* Constants that aren't configurable in menuconfig, yet */
|
||||
#define HTTPS_CLIENT_COMMON_NAME "ota.hendrikschutter.com"
|
||||
#define HTTPS_CLIENT_PORT "443"
|
||||
#define HTTPS_CLIENT_URL "https://ota.hendrikschutter.com/hello-world.bin"
|
||||
#define HTTPS_CLIENT_URL "https://ota.hendrikschutter.com/hex.txt"
|
||||
#define HTTPS_CLIENT_AUTH "b3RhOnB3" //base64("username:password")
|
||||
|
||||
#define HTTPS_CLIENT_OK 0
|
||||
@ -135,7 +135,8 @@ https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu
|
||||
while (bRetriveData)
|
||||
{
|
||||
//Reading HTTP response
|
||||
i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead)));
|
||||
mbedtls_ssl_conf_read_timeout(&sHTTPS_ClientConfig.conf, 1000); //mbedtls_ssl_config * conf,
|
||||
i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead)) );
|
||||
|
||||
if(i32RetRetrieveData > 0)
|
||||
{
|
||||
@ -152,7 +153,6 @@ https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu
|
||||
//buffer full --> stop reading
|
||||
bRetriveData = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(i32RetRetrieveData == 0)
|
||||
@ -161,6 +161,13 @@ https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu
|
||||
bRetriveData = false;
|
||||
}
|
||||
|
||||
if(i32RetRetrieveData == MBEDTLS_ERR_SSL_TIMEOUT ){
|
||||
printf("timeout\n");
|
||||
bRetriveData = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(i32RetRetrieveData == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY)
|
||||
{
|
||||
//connection is going to be closed
|
||||
@ -280,7 +287,7 @@ https_client_ret_t https_clientConnectToServer()
|
||||
|
||||
if(i32RetServerConnect == ESP_OK)
|
||||
{
|
||||
mbedtls_ssl_set_bio(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
|
||||
mbedtls_ssl_set_bio(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.server_fd, mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
|
||||
|
||||
//Performing the SSL/TLS handshake
|
||||
while ((i32RetServerConnect = mbedtls_ssl_handshake(&sHTTPS_ClientConfig.ssl)) != 0)
|
||||
@ -357,34 +364,32 @@ static void https_get_task(void *pvParameters)
|
||||
uint32_t u32BufferLenght = 1024U;
|
||||
unsigned char buffer[1024U];
|
||||
uint32_t u32BytesRead = 0;
|
||||
|
||||
|
||||
uint32_t u32readCount = 0U;
|
||||
|
||||
do {
|
||||
|
||||
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||
|
||||
printf("\nread: %i\n", u32BytesRead);
|
||||
|
||||
u32readCount++;
|
||||
|
||||
if(u32BytesRead == 293)
|
||||
{
|
||||
|
||||
// Print response directly to stdout as it is read
|
||||
for(uint32_t i = 0; i < u32BytesRead; i++) {
|
||||
//putchar(buffer[i]);
|
||||
printf("%x ", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}while(u32BytesRead > 0);
|
||||
|
||||
printf("\n END %i\n", u32readCount);
|
||||
|
||||
do {
|
||||
|
||||
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||
printf("read: %i\n", u32BytesRead);
|
||||
u32readCount++;
|
||||
} while(u32BytesRead > 0);
|
||||
printf("\n END %i\n", u32readCount);
|
||||
https_clientDeinitialize();
|
||||
/*
|
||||
u32BytesRead = 0;
|
||||
u32readCount = 0U;
|
||||
|
||||
do {
|
||||
|
||||
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||
printf("read: %i\n", u32BytesRead);
|
||||
u32readCount++;
|
||||
} while(u32BytesRead > 0);
|
||||
|
||||
printf("\n END %i\n", u32readCount);
|
||||
https_clientDeinitialize();
|
||||
|
||||
|
||||
*/
|
||||
while(1)
|
||||
{
|
||||
vTaskDelay( 500/portTICK_PERIOD_MS);
|
||||
|
Reference in New Issue
Block a user