Hi!
I need some help with my project. I have two ESP8266 NodeMCUs that communicate with each other. One of them is the client, that sends data to the another one through WiFi.
My problem is that the client sometimes (randomly) freezes while sending the data for about 5 seconds. The server receives the data.
As I tried to figure out what's happening, it looks like, that the program stops at the client.println(data) command for 5sec (on the client side).
The client sends data in every 0.5s.
I found some info about this command, and as it is a TCP communication, I think it is waiting to receive an ACK message from the server.
Is there any method, that can break/exit from that command while it's running? I have been looking for the solution for days and found nothing yet.
Code of the client side:
void handlesend (String datasend) {
client.stop();
client.connect(server, port);
digitalWrite(ledPin, 0);
prevt = millis();
client.println(datasend);
sendtime = millis() - prevt;
Serial.print("Time: "); Serial.println(sendtime);
client.flush();
digitalWrite(ledPin, 1);
}
And the data receive code (server side):
String request;
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
digitalWrite(ledPin, 0);
prevt = millis();
request = client.readStringUntil('\r');
sendtime = millis() - prevt;
Serial.print("Received: ");
Serial.print(request); Serial.print(" ");
Serial.print("Time: "); Serial.println(sendtime);
client.flush();
digitalWrite(ledPin, 1);
}
client.stop();
}