esp_http_client_fetch_headers behaviour

Zingemneire
Posts: 68
Joined: Tue Apr 17, 2018 7:35 am

esp_http_client_fetch_headers behaviour

Postby Zingemneire » Wed Nov 21, 2018 2:59 pm

Hi,

I have some code which calls a few functions in this order:
  1. httpClient = esp_http_client_init ( &clientConfig );
  2. ESP_LOGI ( TAG, "httpClient configured and created!");
  3. espError = esp_http_client_open( httpClient, 0);
  4. imageLength = esp_http_client_fetch_headers ( httpClient );
  5. ESP_LOGI ( TAG, "Reported image length: %d ", imageLength );


In clientConfig I do not specify a timeout but I have had a look at the code in esp_http_client_init and in that case it should provide a default timeout value of 5000 milliseconds. When the code executes I would expect that calling esp_http_client_fetch_headers will therefore allow up to 5000 milliseconds for the headers to be received.
At least that is what I think it should do when I look at the source code for that function.

However: I have log files from the UART output that clearly show that the output from both the ESP_LOGI calls above occur within the same microsecond.

The really odd thing is that I have several units that consistently report "Reported image length: -1" while others do provide the correct image length value. If I put my own 2 second time delay before calling esp_http_client_fetch_headers it always works OK. It very much looks like the timeout value is ignored but why ?

Any ideas/suggestions much appreciated.

Zingemneire
Posts: 68
Joined: Tue Apr 17, 2018 7:35 am

Re: esp_http_client_fetch_headers behaviour

Postby Zingemneire » Thu Nov 22, 2018 8:19 am

Hi again,

I really wanted/needed to know what is causing this so I did some experimenting.

Instead of not providing a timeout value myself, and therefore relying on the code used in esp_http_client_init to fill in the default value of 5000 milliseconds, now I do provide a timeout value of 2000 milliseconds myself.

Sure enough: now it works perfectly OK, Once it calls esp_http_client_fetch_headers there is a delay of a few tenths of a second before the correct Image length is reported, exactly the sort of behaviour you would expect to see.

Its almost as if the section of code below in function _set_config in file esp_http_client.c is never executed.
  1.     if (client->timeout_ms == 0) {
  2.         client->timeout_ms = DEFAULT_TIMEOUT_MS;
  3.     }

An obvious reason this may happen is that client->timeout_ms is not 0 but something like 1 but it should be 0 as client points to a local variable declared, and therefore set to all 0, in the function that calls esp_http_client_init to set up and configure a new HTTP client.

User avatar
luisonoff
Posts: 40
Joined: Fri Feb 09, 2018 12:20 pm

Re: esp_http_client_fetch_headers behaviour

Postby luisonoff » Thu Nov 22, 2018 10:10 am

I think you should report this here: https://github.com/espressif/esp-idf/issues
And could be somehow related to: https://github.com/espressif/esp-idf/issues/2684

Who is online

Users browsing this forum: No registered users and 86 guests