low speed when reading constantly from Pendrive and performing http post to XAMP server
Posted: Fri Nov 17, 2023 9:26 am
Hello Community,
I am using IDF example to read 2048 bytes from USB Pen drive and then perform HTTP post every time from esp32 to XAMP server until the complete file is read. When I test the read speed. I got 0.5 MB/s from USB for 6MB file. However, when I do multiple post with 2048 bytes read to the XAMP server, I get a very low speed of 12.5 KB/sec. Firstly, I don't know what ideal value I should expect but I am certain this is very poor upload speed. I also went through the iperf and tried changing the tx buffer size. But, it didn't help. Here is the main code content of the prototyping code.
I would greatly appreciate some inputs here!
//**--reading and performing post operation**--//
static void file_operations(void)
{
while (1)
{
memset(buffer, 0, sizeof(buffer));
read_bytes = fread(buffer, 1, sizeof(buffer), file);
if (read_bytes <= 0)
{
break; // End of file reached
}
else
{
err = post_rest_function();
}
}
}
//**--post is called after every read of 2048 bytes**--//
static esp_err_t post_rest_function(void)
{
static char *post_data = buffer;
esp_http_client_set_post_field(client, post_data, strlen(post_data);
esp_err_t err = esp_http_client_perform(client);
return err;
}
//** ---http intialisation happens in main**--//
void app_main()
{
esp_http_client_config_t config_post = {
.url = "http://192.168.10.21/uploads/upload_file.php",
.method = HTTP_METHOD_POST,
.cert_pem = NULL,
};
client = esp_http_client_init(&config_post);
}
I am using IDF example to read 2048 bytes from USB Pen drive and then perform HTTP post every time from esp32 to XAMP server until the complete file is read. When I test the read speed. I got 0.5 MB/s from USB for 6MB file. However, when I do multiple post with 2048 bytes read to the XAMP server, I get a very low speed of 12.5 KB/sec. Firstly, I don't know what ideal value I should expect but I am certain this is very poor upload speed. I also went through the iperf and tried changing the tx buffer size. But, it didn't help. Here is the main code content of the prototyping code.
I would greatly appreciate some inputs here!
//**--reading and performing post operation**--//
static void file_operations(void)
{
while (1)
{
memset(buffer, 0, sizeof(buffer));
read_bytes = fread(buffer, 1, sizeof(buffer), file);
if (read_bytes <= 0)
{
break; // End of file reached
}
else
{
err = post_rest_function();
}
}
}
//**--post is called after every read of 2048 bytes**--//
static esp_err_t post_rest_function(void)
{
static char *post_data = buffer;
esp_http_client_set_post_field(client, post_data, strlen(post_data);
esp_err_t err = esp_http_client_perform(client);
return err;
}
//** ---http intialisation happens in main**--//
void app_main()
{
esp_http_client_config_t config_post = {
.url = "http://192.168.10.21/uploads/upload_file.php",
.method = HTTP_METHOD_POST,
.cert_pem = NULL,
};
client = esp_http_client_init(&config_post);
}