Description
Board
ESP32-S3-DevKitC-1
Device Description
nothing
Hardware Configuration
nothing
Version
v3.0.1
IDE Name
Arduino IDE
Operating System
Windows 10
Flash frequency
QIO 80Mhz
PSRAM enabled
no
Upload speed
115200
Description
I called the function stream->readBytes();
in the HTTPClient.h
library to download resources from the internet, but found that the download speed is extremely slow, averaging between 100kb/s and 200kb/s. It has been confirmed that the current network status is good, and there is no speed limit on the resource download. Although the ESP32S3 has been tested with iperf and can achieve a download speed of around 5Mb, using the HTTPClient.h
library for internet resource downloads has become very slow. Is this due to the inherent limitations of the ESP32S3, or is there something happening in the data acquisition function stream->readBytes()
that is causing the download speed to be so slow?
Sketch
#include <WiFi.h>
#include <HTTPClient.h>
const char *ssid = "mywifi";
const char *password = "mywifi";
// const char *fileDownloadUrl = "https://code.visualstudio.com/docs/?dv=win64user";//vscode
static size_t CycleTime = 0;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Successfully connected to WiFi");
HTTPClient http;
http.begin(fileDownloadUrl);
const char *headerKeys[] = {"Location"};
http.collectHeaders(headerKeys, 1);
size_t startTime = millis();
size_t uselessTime = 0;
int httpCode = http.GET();
while (httpCode == HTTP_CODE_MOVED_PERMANENTLY || httpCode == HTTP_CODE_FOUND)
{
String newUrl = http.header("Location");
Serial.printf("Redirecting to: %s\n", newUrl.c_str());
http.end();
http.begin(newUrl);
httpCode = http.GET();
}
if (httpCode == HTTP_CODE_OK)
{
size_t fileSize = http.getSize();
Serial.printf("Starting file download...\n");
Serial.printf("file size: %f Mb\n", fileSize / 1024.0 / 1024.0);
WiFiClient *stream = http.getStreamPtr();
size_t temp_count_s = 0;
size_t temp_fileSize = fileSize;
uint8_t *buf_1 = (uint8_t *)heap_caps_malloc(100 * 1024, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
// uint8_t buf_1[4096] = {0};
CycleTime = millis() + 1000;
while (http.connected() && (fileSize > 0 || fileSize == -1))
{
size_t availableSize = stream->available();
if (availableSize)
{
temp_fileSize -= stream->readBytes(buf_1, min(availableSize, (size_t)(100 * 1024)));
if (millis() > CycleTime)
{
size_t temp_time_1 = millis();
temp_count_s++;
Serial.printf("Download speed: %f Kb/s\n", ((fileSize - temp_fileSize) / 1024.0) / temp_count_s);
Serial.printf("Remaining file size: %f Mb\n\n", temp_fileSize / 1024.0 / 1024.0);
CycleTime = millis() + 1000;
size_t temp_time_2 = millis();
uselessTime = uselessTime + (temp_time_2 - temp_time_1);
}
}
// delay(1);
if (temp_fileSize == 0)
{
break;
}
}
http.end();
size_t endTime = millis();
Serial.printf("Download completed!\n");
Serial.printf("Total download time: %f s\n", (endTime - startTime - uselessTime) / 1000.0);
Serial.printf("Average download speed: %f Kb/s\n", (fileSize / 1024.0) / ((endTime - startTime - uselessTime) / 1000.0));
}
else
{
Serial.printf("Failed to download\n");
Serial.printf("Error httpCode: %d \n", httpCode);
}
}
void loop()
{
}
Debug Message
Download speed: 144.199386 Kb/s
Remaining file size: 0.254036 Mb
Download speed: 144.062446 Kb/s
Remaining file size: 0.118031 Mb
Download completed!
Total download time: 38.091000 s
Average download speed: 139.327173 Kb/s
Other Steps to Reproduce
nothing
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.