-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp_http_client_perform(client) slow and is_async causing non connect (IDFGH-11442) #12578
Comments
Updates ? |
hello, did you find what was causing the issue? Funny thing! when I use http_client_open(), it throws me the same error what you got. And after that if I modify my program to use http_client_perform(), it gives the same error and stops working all together! |
Hello @ThatBigPrint @suryasid09 Can you try the patch shared in this issue and check if that fixes your issue |
@hmalpani I tried with the patch you provided, it didn't fix the issue. A more context in what I am doing. I am reading from the USB 4KB of data until end of the file. After each 4KB read operation, I am uploading it to the locally created XAMP server using HTTP post. I was already getting good speed of around 400KB/sec but I want to improve it. So, I decided to use HTTP in streamer mode as mentioned in the documentation. However, I always get the error as above pointed. This is the screenshot from Wireshark and esp32. I would appreciate any help in this regard. |
Hello @ThatBigPrint Thanks! |
@hmalpani the patch worked but why isn't it in the main repo ? Also have we got an example of how i would for instance start the async and stream etc which currently works how do i do i put for instance on the same client to the same endppoint. ? |
Hello @ThatBigPrint I didn't quite understand the second question. Can you please elaborate? Thanks! |
so this is the part of my code the sse stream is fine but when i call the post on a separate client and handler it kicks the stream off am i missing something? i want to be able to post to the database whilst the main sse client is running i have tried the perform on the same client etc but this is the closest I've had it to working. do i need to interrupt the perform in the sse stream task whilst the post is happening? idealy i want to post using te same client and handler but im not sure how i can call the post within the inbound connection client ?
char* outbound_data = "{}";
} void sse_stream_task(void *pvParameters)
}` just to clarify the functions work indipendantly its just the posting whilst the sse is running blocks the sse as per the docs ive set up a second client and handler because the sse is in async mode ? |
@ThatBigPrint I hope this helps. If not can you share a sample application with which I can reproduce this issue? Thanks! |
ive also tried this but i dont think its not putting...
I (12169) esp-x509-crt-bundle: Certificate validated I (21536) Mesh/Firebase: System information, channel: 1, layer: 1, self mac: 68:b6:b3:44:ee:fc, parent bssid: c4:e5:32:85:a7:e9, parent rssi: -60, free heap: 202400 I (48068) Mesh/Firebase: Outbound data: {"brightness": "", "keep_alive": 1} I (77867) Mesh/Firebase: Outbound data: {"brightness": "", "keep_alive": 2}
|
Hello @ThatBigPrint |
|
Guys i still need help on this basicaly i want to have the incoming stream hapen and to be able to post out with the seperate function to the same endpoint do i need to interupt the client perform ? is this an issue with .is_async ? |
Would you please wrap this mess like this
so it becomes #include <stdio.h>
void app_main( void )
{
printf( "Hello, World!" );
} ? |
@KaeLL mess resoved... would be pretty good if github could do that when you click the <>.... any help? |
ok i have made some progress but at the cost of massive heap use, i just don't clean up the post function.... the issue im having is and yes i have attempted to use the same client... if i separate the clients and handlers performing cleanup on the post client kill the incoming client... if i use the same client and prepare the post data and perform nothing gets sent it just sits there... no heap change at all... so the only way i have it working is i do as below
This is far from ideal i really need help with this mainly waning to perform cleanup once the patch has been done as this is not need to be done frequently just every now and then but if the cleanup is called it kills everything according to the vague is_async docs its preferred if you re-use client but it just never submits the prepared data as previously said worse case is there a way to determine the stack size allocated to the patch task as it is very simple? |
Hello @ThatBigPrint This is my understanding of the problem you are facing. You want to use the same client handle for two purposes: first post data to the server and second read data from the server. I suppose these two are using POST and GET methods respectively. So I think, before calling esp_http_client_perform(), you need to set the method again. You can refer to the esp_http_client_example |
No, i want the is_async to remain running for incoming get (that remains running continuously) and the random patch to be able to run every now and then with a cleanup to free resources but as soon as you call cleanup for the patch it disconnects the continuous incoming client as well |
If you are using the same client handle for both the requests, while cleaning up, you might have cleaned up the resources required for the GET request (that remains running continuously). |
Closing this issue. Please feel free to reopen if you have more updates. Thanks! |
Answers checklist.
IDF version.
5.1 release
Espressif SoC revision.
Esp32-devkit
Operating System used.
macOS
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
Esp32-devkit
Power Supply used.
USB
What is the expected behavior?
I want the stream of data to be responsive its only responding to changes every 5 seconds... So I tried to use is_async but the client can't connect... I added certificates for https which was supposed to be a prerequisite
What is the actual behavior?
It's just looping through every 5 seconds ~ then giving me the new data if there is any... Or the keep alive
If I use the is_async I get the can't connect error
Steps to reproduce.
`// Include necessary headers
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_http_client.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "cJSON.h"
#include "esp_crt_bundle.h"
#include <sys/param.h>
#include <stdlib.h>
#include <ctype.h>
#include "esp_netif.h"
#include "esp_tls.h"
#include "freertos/event_groups.h"
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
#define MAX_HTTP_RECV_BUFFER 16384
#define MAX_HTTP_OUTPUT_BUFFER 2048
extern const uint8_t server_cert_pem_start[] asm("_binary_ca_cert_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end");
static EventGroupHandle_t s_wifi_event_group;
static const char *TAG = "wifi_station";
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
if (event_id == WIFI_EVENT_STA_START)
{
esp_wifi_connect();
}
else if (event_id == WIFI_EVENT_STA_DISCONNECTED)
{
esp_wifi_connect();
ESP_LOGI(TAG, "retry to connect to the AP");
xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
else if (event_id == IP_EVENT_STA_GOT_IP)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
}
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{
static char output_buffer; // Buffer to store response of http request from event handler
static int output_len; // Stores number of bytes read
switch (evt->event_id)
{
case HTTP_EVENT_ERROR:
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
break;
case HTTP_EVENT_ON_CONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
break;
case HTTP_EVENT_HEADER_SENT:
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
break;
case HTTP_EVENT_ON_HEADER:
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
break;
case HTTP_EVENT_ON_DATA:
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
// Clean the buffer in case of a new request
if (output_len == 0 && evt->user_data)
{
// we are just starting to copy the output data into the use
memset(evt->user_data, 0, MAX_HTTP_OUTPUT_BUFFER);
}
/
* Check for chunked encoding is added as the URL for chunked encoding used in this example returns binary data.
* However, event handler can also be used in case chunked encoding is used.
*/
if (!esp_http_client_is_chunked_response(evt->client))
{
// If user_data buffer is configured, copy the response into the buffer
int copy_len = 0;
if (evt->user_data)
{
// The last byte in evt->user_data is kept for the NULL character in case of out-of-bound access.
copy_len = MIN(evt->data_len, (MAX_HTTP_OUTPUT_BUFFER - output_len));
if (copy_len)
{
memcpy(evt->user_data + output_len, evt->data, copy_len);
}
}
else
{
int content_len = esp_http_client_get_content_length(evt->client);
if (output_buffer == NULL)
{
// We initialize output_buffer with 0 because it is used by strlen() and similar functions therefore should be null terminated.
output_buffer = (char *)calloc(content_len + 1, sizeof(char));
output_len = 0;
if (output_buffer == NULL)
{
ESP_LOGE(TAG, "Failed to allocate memory for output buffer");
return ESP_FAIL;
}
}
copy_len = MIN(evt->data_len, (content_len - output_len));
if (copy_len)
{
memcpy(output_buffer + output_len, evt->data, copy_len);
}
}
output_len += copy_len;
}
}
void wifi_init_sta()
{
s_wifi_event_group = xEventGroupCreate();
}
void sse_stream_task(void *pvParameters)
{
char *buffer = malloc(MAX_HTTP_RECV_BUFFER + 1);
if (buffer == NULL)
{
ESP_LOGE(TAG, "Cannot malloc http receive buffer");
return;
}
}
void app_main()
{
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
wifi_init_sta(); // Initialize WiFi
xTaskCreate(&sse_stream_task, "sse_stream_task", 4096, NULL, 5, NULL);
}
`
Debug Logs.
No response
More Information.
No response
The text was updated successfully, but these errors were encountered: