ESP8266 fast tcp via at commands

Hi, please
i use esp8266 with arduino mega. I sending tcp packets in loop but in server (on pc) i received only one packet per second. Why it is so slow? How can i do it faster?

My code:

void loop()
{
String message = "message";
String lenght = String(message.length());
String command = "AT+CIPSEND=" + lenght;
Serial1.println(command);
delay(5);
Serial1.println(message);
delay(5);
}

..i read about ACK issue in esp8266. But f.e. how can i do this little hack: send two packets every each time,it will response TCP ACK immediately

it is described in: No more than 2-3 packets/sec from the ESP8266? - Page 2 - ESP8266 Developer Zone
by Her Majesty

Thank you for your replies.

Why are you using AT commands?
Just program the ESP directly.

Pieter

Thanks for your reply.
I need send informations from mega to pc via esp8266. So i choose serial communication between esp and arduino

You can use serial communication without using AT commands.

Pieter

Thanks, i will try tomorow

Hi, i tried write programm direct to esp. But it slow too. Please help me with fast tcp communication

my code:

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {
Serial.begin(115200);
delay(10);

WiFiMulti.addAP(“MikroTik”, “Kecalop10”);
Serial.println();
Serial.println();
Serial.print("Wait for WiFi… ");

while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

delay(500);
}

void loop() {
const uint16_t port = 4235;
const char * host = “192.168.1.32”;

Serial.print("connecting to ");
Serial.println(host);

WiFiClient client;

if (!client.connect(host, port)) {
Serial.println(“connection failed”);
Serial.println(“wait 5 sec…”);
delay(5000);
return;
}

client.print(“Send this data to server”);
String line = client.readStringUntil(’\r’);
client.println(line);
Serial.println(“closing connection”);
client.stop();
Serial.println(“wait 5 sec…”);
}

ou, ok. I get connecting to client to setup and client.print is alone in loop cycle. And its fast.
Thanks PieterP for your advice.