client.print is slow?
Posted: Sun Sep 13, 2015 12:57 am
I've noticed in testing ESP8266 Arduino that the WiFiClient.print and WiFiClient.println functions seem to be quite slow to return?
Currently all of my code including comparisons of a few reasonably sized strings all executes in less than 2ms, but print seems to reliably take 50-100ms.
I tested this with the following code provided by martinayotte in this post: http://www.esp8266.com/viewtopic.php?p=26030#p26030
In total, it took 104756ms to call print 1000 times, for an average of 100ms per call.
I'm using the most recent stable version (1.6.5-947-g39819f0).
I believe the problem may be that the print command blocks while waiting for the TCP ACK packet (Wireshark shows roughly a 50ms delay from PSH to ACK). Am I right to think this? How can I send data without blocking in this way? Do I need to use the native SDK?
EDIT: On further testing, I have no idea what's going on, as the below code prints response times of ~2/3ms when sending data to an echo server. To add to the confusion, if I disable echo on the server and just have it accept the incoming data, the time-per-print shoots back up to 100ms again.
Currently all of my code including comparisons of a few reasonably sized strings all executes in less than 2ms, but print seems to reliably take 50-100ms.
I tested this with the following code provided by martinayotte in this post: http://www.esp8266.com/viewtopic.php?p=26030#p26030
In total, it took 104756ms to call print 1000 times, for an average of 100ms per call.
I'm using the most recent stable version (1.6.5-947-g39819f0).
I believe the problem may be that the print command blocks while waiting for the TCP ACK packet (Wireshark shows roughly a 50ms delay from PSH to ACK). Am I right to think this? How can I send data without blocking in this way? Do I need to use the native SDK?
EDIT: On further testing, I have no idea what's going on, as the below code prints response times of ~2/3ms when sending data to an echo server. To add to the confusion, if I disable echo on the server and just have it accept the incoming data, the time-per-print shoots back up to 100ms again.
Code: Select all
void loop() {
Serial.println("************");
long startTime = millis();
String str = ">>>>>>>>>>>>>>>";
client.print(str);
while(!client.available()){yield();};
while(client.available()){
client.read();
}
Serial.println((String)(millis() - startTime));
}