Issue with http_rest_with_url function
Posted: Wed May 20, 2020 8:49 am
For a e-Paper display collecting data from a home automation server via REST we are using the basic examples from esp-idf repo in https://github.com/espressif/esp-idf/bl ... _example.c
Instead of fixed URLs from the example we pass the URLs we want to acquire via char variable *URL:
We only need the GET call so we deleted out all other calls.
Now the issue: When calling the function the first time we see the right response in the local_response_buffer and with the ESP_LOG_BUFFER_HEX macro.
However with second and all subsequent calls no log output is visible. Seems the local_response_buffer cannot be
initialized a second time although it's a local variable?
When changing the statement:
to:
we do define the variable with every call of the function but do not set all contents to "0"
Then we get again the right log with the first call but now every subsequent call appends the contents at the end of the existing
buffer. The buffer contents is correct now but grows longer with every call. THis means with 3 calls you get 3 REST responses in the buffer instead of ony by one.
It's obvious that something goes wrong with initializing local variable local_response_buffer but have no clue what?
We are using Eclipse IDE latest version with latest Eclipse plugin. Compilation works without issues
Instead of fixed URLs from the example we pass the URLs we want to acquire via char variable *URL:
Code: Select all
static void http_rest_with_url(char *URL)
{
char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0};
esp_http_client_config_t config = {
.url = URL,
.event_handler = _http_event_handler,
.user_data = local_response_buffer, // Pass address of local buffer to get response
};
esp_http_client_handle_t client = esp_http_client_init(&config);
// GET
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
} else {
ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
}
ESP_LOG_BUFFER_HEX(TAG, local_response_buffer, strlen(local_response_buffer));
....
Now the issue: When calling the function the first time we see the right response in the local_response_buffer and with the ESP_LOG_BUFFER_HEX macro.
However with second and all subsequent calls no log output is visible. Seems the local_response_buffer cannot be
initialized a second time although it's a local variable?
When changing the statement:
Code: Select all
char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0};
Code: Select all
char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER];
Then we get again the right log with the first call but now every subsequent call appends the contents at the end of the existing
buffer. The buffer contents is correct now but grows longer with every call. THis means with 3 calls you get 3 REST responses in the buffer instead of ony by one.
It's obvious that something goes wrong with initializing local variable local_response_buffer but have no clue what?
We are using Eclipse IDE latest version with latest Eclipse plugin. Compilation works without issues