HTTP connection issue during file download

bboulet
Posts: 1
Joined: Mon Jul 22, 2024 8:33 am

HTTP connection issue during file download

Postby bboulet » Mon Jul 22, 2024 9:13 am

Hello,

I've an issue regarding my http connection which disconnect itself during a file download.
Here is my problem :
I create a HTTP connection using : esp_http_client_init

here is my http setting :

Code: Select all

    
esp_http_client_config_t HttpConfig = { .host           = NETCOM_WEB_SERVER_URL,
                                            .transport_type = HTTP_TRANSPORT_OVER_SSL,
                                            .path           = "/",
                                            .cert_pem       = ( const char* ) SmartfitCertificatePemStart,
                                            .cert_len       = ( uint32_t ) SmartfitCertificatePemEnd -
                                                        ( uint32_t ) SmartfitCertificatePemStart,
                                            .timeout_ms        = 60000,
                                            .keep_alive_enable = true };
Then I Set the URL and open the connection

Code: Select all

esp_http_client_set_url( HttpClient, request );

if( ( HttpClient != NULL ) && ( esp_http_client_open( HttpClient, 0 ) == ESP_OK ) )
{
	ESP_LOGI( tag, "Connection established..." );
}
The I fetch the header :

Code: Select all

esp_http_client_fetch_headers( HttpClient );
and finaly I read the stream until that the function esp_http_client_read returns 0

Code: Select all

do
{
	ret = esp_http_client_read( HttpClient, ( char* ) Buf, len );
	SizeUpdate += len;
            
	ESP_LOGI( tag, "writing update file len %d", ret );
	if( ret > 0 )
	{
		FlashUpdateStatus = FLASH_WriteUpdateFile( Buf, ret );
	}
} while( ( ret > 0 )  && ( FlashUpdateStatus == APP_OK ) );
95% of time the connection closes and the download fail close to the end (98%),

I see :

Code: Select all

D (70334) HTTP_CLIENT: need_read=417, byte_to_read=417, rlen=-1, ridx=606
W (70337) HTTP_CLIENT: esp_transport_read returned:-1 and errno:128
what does mean rlen ?

So far the function esp_http_client_read doesn't return -1 or 0, and at the next function call I receive :

Code: Select all

I (70419) NetComModule: update Reading HTTP response...
D (70419) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
E (70422) esp-tls-mbedtls: read error :-0x004C:
I (70426) esp-tls-mbedtls: (FFFFFFB4): UNKNOWN ERROR CODE (004C)
E (70432) TRANSPORT_BASE: esp_tls_conn_read error, errno=Socket is not connected
D (70441) HTTP_CLIENT: need_read=1023, byte_to_read=512, rlen=-76, ridx=0
W (70447) HTTP_CLIENT: esp_transport_read returned:-76 and errno:128
D (70455) HTTP_CLIENT: Data processed 163263 != Data specified in content length 166912
What does mean "Data processed 163263 != Data specified in content length 166912" ?

Did i miss something ?

here is the full log

Code: Select all

I (70191) NetComModule: writing update file len 1023
D (70196) vfs_fat: vfs_fat_lseek: offset=160512, filesize:=160512
D (70202) vfs_fat: vfs_fat_lseek: offset=160640, filesize:=160640
D (70209) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
D (70216) TRANSPORT_BASE: remain data in cache, need to read again
D (70222) HTTP_CLIENT: need_read=1023, byte_to_read=512, rlen=512, ridx=0
D (70229) HTTP_CLIENT: http_on_body 512
D (70233) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
D (70240) TRANSPORT_BASE: remain data in cache, need to read again
D (70246) HTTP_CLIENT: need_read=511, byte_to_read=511, rlen=511, ridx=512
D (70253) HTTP_CLIENT: http_on_body 511
I (70257) NetComModule: writing update file len 1023
D (70263) vfs_fat: vfs_fat_lseek: offset=161536, filesize:=161536
D (70269) vfs_fat: vfs_fat_lseek: offset=161664, filesize:=161664
D (70275) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
D (70282) TRANSPORT_BASE: remain data in cache, need to read again
D (70288) HTTP_CLIENT: need_read=1023, byte_to_read=512, rlen=512, ridx=0
D (70295) HTTP_CLIENT: http_on_body 512
D (70299) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
D (70306) TRANSPORT_BASE: remain data in cache, need to read again
D (70312) HTTP_CLIENT: need_read=511, byte_to_read=511, rlen=94, ridx=512
D (70319) HTTP_CLIENT: http_on_body 94
D (70323) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
D (70334) HTTP_CLIENT: need_read=417, byte_to_read=417, rlen=-1, ridx=606
W (70337) HTTP_CLIENT: esp_transport_read returned:-1 and errno:128
I (70344) NetComModule: writing update file len 606
D (70350) vfs_fat: vfs_fat_lseek: offset=162560, filesize:=162560
D (70356) vfs_fat: vfs_fat_lseek: offset=162688, filesize:=162688
I (70362) NetComModule: Downloading firmware: 163680 / 166912  (98.06 %)
I (70419) NetComModule: update Reading HTTP response...
D (70419) HTTP_CLIENT: is_data_remain=1, is_chunked=0, content_length=166912
E (70422) esp-tls-mbedtls: read error :-0x004C:
I (70426) esp-tls-mbedtls: (FFFFFFB4): UNKNOWN ERROR CODE (004C)
E (70432) TRANSPORT_BASE: esp_tls_conn_read error, errno=Socket is not connected
D (70441) HTTP_CLIENT: need_read=1023, byte_to_read=512, rlen=-76, ridx=0
W (70447) HTTP_CLIENT: esp_transport_read returned:-76 and errno:128
D (70455) HTTP_CLIENT: Data processed 163263 != Data specified in content length 166912
I (70463) NetComModule: writing update file len -1
E (70468) NetComModule: esp_tls_conn_read  returned [-0x01](ESP_FAIL)


axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: HTTP connection issue during file download

Postby axellin » Sat Nov 16, 2024 2:50 pm

I hit the same (or similar) issue.
Just wondering how do you fix this issue?

Who is online

Users browsing this forum: No registered users and 388 guests