From 8e7f4e68dc4f387b216b0bf6bf6e1ff74c5ad7ab Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 8 Jan 2021 22:29:33 +0100 Subject: [PATCH] fix: https download offset --- main/https_mbedtls_example_main.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/main/https_mbedtls_example_main.c b/main/https_mbedtls_example_main.c index 6208ae2..9d3b3ce 100644 --- a/main/https_mbedtls_example_main.c +++ b/main/https_mbedtls_example_main.c @@ -130,17 +130,17 @@ https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu int32_t i32RetRetrieveData = ESP_OK; bzero(pu8Data, *pu32DataLenght); bool bRetriveData = true; + *pu32BytesRead = 0U; while (bRetriveData) { //Reading HTTP response - i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)pu8Data, *pu32DataLenght); + i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead))); if(i32RetRetrieveData > 0) { //Data received *pu32BytesRead = *pu32BytesRead + i32RetRetrieveData; - *pu32DataLenght = *pu32DataLenght - *pu32BytesRead; if(*pu32DataLenght > 0) { @@ -152,6 +152,7 @@ https_client_ret_t https_clientRetrieveData(unsigned char* pu8Data, uint32_t* pu //buffer full --> stop reading bRetriveData = false; } + } if(i32RetRetrieveData == 0) @@ -357,20 +358,36 @@ static void https_get_task(void *pvParameters) 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]); + //putchar(buffer[i]); + printf("%x ", buffer[i]); } - printf("\n END \n"); - + } + + }while(u32BytesRead > 0); + + printf("\n END %i\n", u32readCount); + https_clientDeinitialize(); while(1) { - + vTaskDelay( 500/portTICK_PERIOD_MS); } }