Is it possible to increase the uploading speed with Arduino on the web server?

Hello to all :raised_back_of_hand:
I send a file of about 200 KB to SD connected to the Arduino MEGA 2560 using the ESP 8266 module (the modules are connected via a serial port) but my problem is in the transfer speed because My transfer speed is about 28 kbps and it takes about 11 seconds for my file to upload to the server.
Do you think there is a way to upload my file to the server faster and in less time?
Please help me if there is a way (I have no problem paying)
Additional explanation (I think my problem is with the serial port, which may have a transfer speed limit because I tested the same code with NodeMcu and it sent at a speed of 460 kbps)

My Sketch :

#include <SD.h>
#include <SPI.h>
#include <WiFiEspAT.h>
#include <StreamLib.h>

#if defined(ARDUINO_ARCH_AVR) && !defined(HAVE_HWSERIAL1)

#define AT_BAUD_RATE 9600
#else
#define AT_BAUD_RATE 1000000
#endif

File myFile;

#define MTU_Size 2*1460

String post_host = "192.168.1.101";
const int post_port = 80;
String url = "/errtest.php?azyx=1&d=1";
char server[ ] = "192.168.1.101";

//format bytes
String formatBytes(unsigned int bytes) {
if (bytes < 1024) {
return String(bytes) + "B";
} else if (bytes < (1024 * 1024)) {
return String(bytes / 1024.0) + "KB";
} else if (bytes < (1024 * 1024 * 1024)) {
return String(bytes / 1024.0 / 1024.0) + "MB";
}
}

WiFiClient client;

void setup() {
Serial.begin(230400);
while (!Serial);

Serial1.begin(AT_BAUD_RATE);
WiFi.init(Serial1);

if (WiFi.status() == WL_NO_MODULE) {
Serial.println();
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}

// waiting for connection to Wifi network set with the SetupWiFiConnection sketch
Serial.println("Waiting for connection to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print('.');
}
Serial.println();
Serial.println("Connected to WiFi network.");

//test connect to sd
Serial.print("Initializing SD card...");

SD.begin(190000000, 53);

myFile = SD.open("data.wav", FILE_READ);

String fileName = myFile.name();
String fileSize = formatBytes(myFile.size());

Serial.println();
Serial.println("file exists");

if (myFile)
{
Serial.println("test file:ok");
// print content length and host
Serial.print("contentLength : ");
Serial.println(fileSize);
Serial.print("connecting to ");
Serial.println(post_host);

// We now create a URI for the request
Serial.println("Connected to server");
Serial.print("Requesting URL: ");
Serial.println(url);

//change with your content type
String contentType = "audio/x-wav";
String portString = String(post_port);
String hostString = String(post_host);
String requestHead = "--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"data\"; filename=\"data.wav\"\r\nContent-Type: audio/x-wav\r\n\r\n";
String tail = "\r\n--RandomNerdTutorials--\r\n";
unsigned long contentLength =  requestHead.length() + myFile.size() + tail.length();

client.connect(server, 80);

client.println("POST " + url + " HTTP/1.1");
client.println("Host: " + post_host);
client.println("Content-Length: " + String(contentLength, DEC));
client.println("Content-Type: multipart/form-data; boundary=RandomNerdTutorials");
client.println();
client.print(requestHead );

// send myFile:
//this method is for upload data very fast
//and only work in ESP software version after 2.3.0
//if your version is lower than please update
//esp software to last version or use bellow comment code
client.write(myFile);
// create file buffer
const int bufSize = 2048;
byte clientBuf[MTU_Size];
int clientCount = 0;

while (myFile.available())
{
  clientBuf [clientCount] = myFile.read ();
  clientCount++;
  if (clientCount > (MTU_Size - 1))
  {
    
    client.write((const uint8_t *)clientBuf, MTU_Size);
    clientCount = 0;
    
  }

}

if (clientCount > 0)
{
  
  client.write((const uint8_t *)clientBuf, clientCount);
  
}

client.print(tail);

}
else
{
// if the file didn't open, print an error:
Serial.println("error opening test.WAV");
Serial.println("Post Failure");
}

// Read all the lines of the reply from server and print them to Serial

Serial.println("request sent");
String responseHeaders = "";

while (client.connected() ) {
// Serial.println("while client connected");
String line = client.readStringUntil('\n');
Serial.println(line);
responseHeaders += line;
if (line == "\r") {
Serial.println("headers received");
break;
}
}

String line = client.readStringUntil('\n');

Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");

//close file
myFile.close();

}
//}
void loop()
{}

did you try 250000 baud?

and you could try larger buffers

and SD card is slow.

Yes, I even put 100,000 buad for esp8266 and arduino
I also set the sd speed to 50 MHz
Is this a problem?

250,000 baud

you can even try 500,000 if the wiring is good. I hope you don't have a voltage divider for logic level conversion

esp-01 supports up to 115200, no more than that as far as i know. (but correct me with the documentation if i am wrong please)

WiFi.init(Serial1);

pretty sure the WiFiEspAT library sets the baud rate, and gives the command to the ESP to switch to 9600 if it is using swSerial.

both ? oh wait a minute, faster is the same as in less time. Well as usual the ESP-01 is a 32-bit machine with loads of memory, and can be programmed directly. Unfortunately it does not support SPI (really, there is a version of swSPI i think)
Still if you are on 28kbps then the Serial port is not the bottle neck, that is running at 115kbps, then it is probably in the SD reader.

@Deva_Rishi, wrong in all 3 points
I tested 500k baud.
the speed is set in sketch.
esp8266 has hardware SPI.

why you even respond to this topic?

Because there is people like you. An esp8266 has hardware SPI, but on an ESP-01 what the OP has, these pins are not exposed.
The OP is using AT-commands to communicate with the ESP8266 which works with the firmware that defaults at 115200. Setting the baudrate of the Serial port does not automatically change the baud rate on the ESP.
I was mistaken only about the maximum baudrate, but even you (actually really how did you miss that ? ) could have figured out that if the OP is getting 28kbps, the Serial port is not the bottle neck.

@Deva_Rishi, did you noticed OP has it running on NodeMCU but wants to switch to Mega+esp01?

OP already uses 100k baudrate. They know how to change the baud rate.

I am the author of the WiFiEspAT library. I have all this tested with a download of a 1MB file over 500k baud Serial between Mega and esp8266.

The OP stated he switched already and was having problems, If he has a nodeMCU he should connect the SD-card reader straight to that, that has the SPI pins exposed (the esp-01 doesn't, but some form of swSPI can be achieved, mind you not with AT-commands as far as i know)

I didn't know, but kudos for that. With that library, you have made something which is essentially wrong a lot less cumbersome. I am sorry for any inaccuracies i posted, but regardless of that, your tone is the one of a man with a hangover. Again i was open to correction, but you just want to slap my face, and i know i do not deserve that.

http://sl4.org/crocker.html

Let me elaborate on that, if there is a need for a Mega with extra pins & uarts, then connect the nodeMCU with the sd-card reader to that, and use the ESP-01 for something else. Keep in mind that many of the nodeMCU actually have are 5v tolerant on GPIO3 (RX0) Not all nodeMCU's are but if you have difficulty getting it to work properly with a voltage divider, that may be the cause.

Sorry I bad typed, I mean one million (1,000,000) baud rate and I did not use voltage divider and also about LargeBuffer I read this part but I do not know where I had a problem because the values ​​inside WiFiEspAtConfig.h also according to their own words I changed but I did not see any effect on the speed of data upload to the server; Can you give me some advice on this?
I even changed the HardwareSerial.h values ​​including the values
​​( #if !defined(SERIAL_TX_BUFFER_SIZE) #if ((RAMEND - RAMSTART) < 1023) #define SERIAL_TX_BUFFER_SIZE 16 #else #define SERIAL_TX_BUFFER_SIZE 32 #endif #endif #if !defined(SERIAL_RX_BUFFER_SIZE) #if ((RAMEND - RAMSTART) < 1023) #define SERIAL_RX_BUFFER_SIZE 16 #else #define SERIAL_RX_BUFFER_SIZE 64 #endif #endif #if (SERIAL_TX_BUFFER_SIZE>256) typedef uint16_t tx_buffer_index_t; #else typedef uint8_t tx_buffer_index_t; #endif #if (SERIAL_RX_BUFFER_SIZE>256) typedef uint16_t rx_buffer_index_t; #else typedef uint8_t rx_buffer_index_t; #endif )
to 256, 512, 1024, 2048, and 5122, and even when compiled in ArduinoIDE software, the buffers took up more dynamic memory. But again, I did not see any change in the speed of data upload to the server

Yes; I use the Esp 12f module to connect to the Internet and upload files, but can you clarify what you mean?
I increased the frequency of the SD CARD module to 50 MHz, so I do not think my problem is with the sd card, but I have doubts about the serial port because I tested the same code on node mcu 1.0 and was able to send my file at a speed of 400 kbps. To my server
One thing I forgot to mention is that I can not use the nodemcu or the Esp 12f module directly because the Arduino mega 2560 is actually being used to record audio via an analog pin, which unfortunately I can not use the wifi and nodemcu modules

Really?!
Because I used your SDWebServer.ino example and I was only able to achieve a download speed of 22 KB / s by changing the BuadRate Esp12-f to 2,000,000. Can you tell me my problem that my download speed and even upload is not more than 22 to 28 KB/s?

In this part of the Buffering and buffers
at this line It is recommended to use WiFiClient.flush() after completing the output.
What does this (after completing the output) mean?

here you stop() the connection so it does flush().

I didn't do exact speed measurements. I was happy it is stable.

I guess you did everything possible on the Mega side and it will no got faster.

ATmega is much slower than esp8266. That may explain the processing speed difference.

thanks for your response;
Do you think that instead of saving my recorded wav file by mega 2560, I might transfer it directly to SPIFs nodemcu memory via SPI or Serial and then upload it to the server from there?
Or is there a microcontroller that has two SPI protocols and also can I record audio directly by esp 8266 itself?
, And can you suggest me a microcontroller that has both a Wi-Fi connection and can, for example, record surround sounds with the library (TMRpcm) and store them inside?

did you check esp32?

better start a new thread for this different approach

Is there a difference between the language and programming instructions esp 8266 and esp 32 within the Arduino IDE?

Excuse me, do you mean to create a new topic?