HTTP server fails after a while.
Posted: Sat Nov 18, 2023 7:33 pm
Hello I'm trying to use GET method with Telegram api.
And my function is working several times. After that I get an error like below:
I could not figure it out. Why this function fails?
Thanks in advance.
Code: Select all
static esp_err_t getUpdates_test (void)
{
char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request
// int content_length = 0;
char _msg_update_id_append[16] = "";
char url[512] = "";
/* Creating the string of the url*/
//Copy the url+TOKEN
strcat(url, url_string);
strcat(url, "/getUpdates?limit=1&offset=");
sprintf(_msg_update_id_append, "%d", _msg_update_id);
strcat(url, _msg_update_id_append);
ESP_LOGI(TAG3, "url string es: %s", url);
esp_http_client_config_t config = {
.url = url,
.transport_type = HTTP_TRANSPORT_OVER_SSL,
.event_handler = _http_event_handler,
.cert_pem = telegram_certificate_pem_start,
.method = HTTP_METHOD_GET,
};
ESP_LOGW(TAG3, "Iniciare");
esp_http_client_handle_t client = esp_http_client_init(&config);
ESP_LOGW(TAG3, "Enviare un mensaje a un chat");
ESP_LOGW(TAG3, "Open");
esp_err_t err = esp_http_client_open(client, 0);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
esp_http_client_cleanup(client);
}
ESP_LOGI(TAG, "client connection open");
int64_t content_length = esp_http_client_fetch_headers (client);
ESP_LOGI(TAG, "content_length= %lld", content_length);
int total_read_len = 0, read_len;
char *buffer = malloc ((size_t) (content_length + (int64_t) 1));
bzero (buffer, (size_t) (content_length + (int64_t) 1));
if (total_read_len < content_length)
{
read_len = esp_http_client_read (client, buffer, content_length);
if (read_len <= 0)
{
ESP_LOGE(TAG, "Error read data");
return ESP_FAIL;
}
buffer[read_len] = 0;
ESP_LOGI(TAG, "read_len = %d", read_len);
}
ESP_LOGI(TAG, "HTTP Stream reader Status = %d, content_length = %d",
esp_http_client_get_status_code (client),
(int) esp_http_client_get_content_length (client));
free (buffer);
err = esp_http_client_close(client);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Failed to close HTTP connection: %s", esp_err_to_name(err));
esp_http_client_cleanup(client);
}
ESP_LOGW(TAG, "Limpiare");
ESP_LOGI(TAG, "esp_get_free_heap_size: %ld", (long)esp_get_free_heap_size ());
return ESP_OK;
}
Code: Select all
I (37509) Sending sendMessage: url string es: https://api.telegram.org/bot<TOKEN>/getUpdates?limit=1&offset=0
W (37509) Sending sendMessage: Iniciare
W (37519) Sending sendMessage: Enviare un mensaje a un chat
W (37519) Sending sendMessage: Open
E (38199) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x2700
I (38199) esp-tls-mbedtls: Failed to verify peer certificate!
E (38199) esp-tls: Failed to open new connection
E (38209) transport_base: Failed to open a new connection
E (38219) HTTP_CLIENT: Connection failed, sock < 0
E (38219) HTTP_CLIENT Handler: Failed to open HTTP connection: ESP_ERR_HTTP_CONNECT
I (38229) HTTP_CLIENT Handler: HTTP_EVENT_DISCONNECTED
I (38229) HTTP_CLIENT Handler: Last esp error code: 0x801a
I (38239) HTTP_CLIENT Handler: Last mbedtls failure: 0x2700
I (38239) HTTP_CLIENT Handler: client connection open
I (38249) HTTP_CLIENT Handler: content_length= -1
I (38259) HTTP_CLIENT Handler: HTTP Stream reader Status = 0, content_length = 0
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x401787b5 PS : 0x00060530 A0 : 0x800f3b16 A1 : 0x3fff4540
0x401787b5: esp_transport_get_error_handle at D:/esp-idf/components/tcp_transport/transport.c:255 (discriminator 1)
A2 : 0x00000077 A3 : 0x3f408994 A4 : 0x3f408c4c A5 : 0x3fff4570
A6 : 0x3fff4550 A7 : 0x0000000c A8 : 0x8017b7f4 A9 : 0x3fff44e0
A10 : 0x0000005c A11 : 0x3ffc0b1c A12 : 0x3fff4550 A13 : 0x0000000c
A14 : 0xffffffff A15 : 0x00000003 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x000000af LBEG : 0x4008be39 LEND : 0x4008be49 LCOUNT : 0xfffffffa
0x4008be39: strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:84
0x4008be49: strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:96
Backtrace: 0x401787b2:0x3fff4540 0x400f3b13:0x3fff4560 0x400dc019:0x3fff4590 0x400dc07b:0x3fff5060 0x40091081:0x3fff5080
0x401787b2: esp_transport_get_error_handle at D:/esp-idf/components/tcp_transport/transport.c:254
0x400f3b13: esp_http_client_close at D:/esp-idf/components/esp_http_client/esp_http_client.c:1566
0x400dc019: getUpdates_test at D:/esp32s-deneme/cam-telegram/main/main.c:1077 (discriminator 13)
0x400dc07b: http_test_task at D:/esp32s-deneme/cam-telegram/main/main.c:800
0x40091081: vPortTaskWrapper at D:/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162
Thanks in advance.