This was bugging me so I just ran a quick non optimized test in my local infrastructure (ie Mac and ESP32 on the same Wi-Fi network)
on my Mac I ran in a terminal window:
nc -l 1234 > test.log
which basically listens on port 1234
and dump whatever arrives into test.log
until the end of transmission (client goes away).
I ran this code on the ESP32:
#include <WiFi.h>
/* UPDATE THOSE FOR YOUR SYSTEM */
const char* ssid = "****";
const char* password = "****";
const char * host = "10.0.0.13"; // my Mac running the 'nc -l 1234' command
const uint16_t port = 1234; // the port being used on the Mac
const size_t bufferSize = 1024; // 1kB
uint8_t buffer[bufferSize];
// sends n instances of buffer to the WiFiClient
void blast(WiFiClient& client, size_t n) {
for (size_t i = 0; i < n; i++)
if (client.write(buffer, bufferSize) != bufferSize) {
Serial.println("Data transfer Error");
break;
}
}
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.write('.');
}
Serial.print("\nWiFi connected with IP: ");
Serial.println(WiFi.localIP());
for (size_t i = 0; i < bufferSize; i++) buffer[i] = 'a' + (i % 26); // fill buffer with small caps alphabet
Serial.println("\nrun 'nc -l 1234 > test.log' on your server");
Serial.println("*** enter key to start ***");
while (Serial.read() == -1) yield(); // active wait for user to type 'enter'
WiFiClient client;
if (client.connect(host, port)) {
size_t bufferCount[] = {1024ul, 5 * 1024ul, 10 * 1024ul, 20 * 1024ul, 40 * 1024ul}; // 1MB, 5MB, 10MB, 20MB, 40MB
for (byte i = 0; i < sizeof bufferCount / sizeof bufferCount[0]; i++) {
uint32_t t0 = millis();
blast(client, bufferCount[i]);
uint32_t t1 = millis();
Serial.print(bufferCount[i]);
Serial.write('\t'); Serial.print((t1 - t0) / 1000.0, 3);
Serial.print("s\t"); Serial.print(1000.0 * ((bufferCount[i]*bufferSize) / 1024) / (t1 - t0)); Serial.println(" kB/s");
}
client.stop();
} else {
Serial.println("Connection to host failed");
}
}
void loop() {}
the code should be self explanatory, after you hit the enter key in the Serial monitor, I basically send 1MB, 5MB, 10MB, 20MB and 40MB and measure the time it takes and display in the the Serial monitor at 115200 bauds
that's what I got:
.....
WiFi connected with IP: 10.0.0.33
run 'nc -l 1234 > test.log' on your server
*** enter key to start ***
1024 1.822s 562.02 kB/s
5120 8.867s 577.42 kB/s
10240 17.829s 574.35 kB/s
20480 35.328s 579.71 kB/s
40960 64.567s 634.38 kB/s
if I check on the server, test.log does holed 79691776 bytes of 'abcdefghi...xyz'
I send (40960 + 20480 + 10240 + 5120 + 1024) = 77 824 buffers of 1024 bytes and 77 824 x 1024 = 79691776 ➜ all was received correctly.
So I was able to blast from SRAM to an open socket a 40 meg file, in chunks of 1k, at 634.38 kB/s and it took a bit more than a minute from my ESP32. (tried a few times and got up to ~700kB/s)
Reading the buffer from an SD card or flash memory of course would add to this.