-->
Page 1 of 3

Very Slow TCP and Client Connection

PostPosted: Sun Jan 17, 2016 6:23 pm
by laxmimerit
MY esp modules tcp transmission is very slow. please refer the following code
Code: Select allvoid loop(void) {
  if (!serverClient.connected()) {
    delay(100);
    serverClient = server.available();
  }
    if (serverClient.connected()) {
      int adc = analogRead(A0);
      Serial.write("\nwaiting for input");
      String line = serverClient.readStringUntil('\n');
      Serial.write("\nSending ADC value to client");
      line = String(adc);                               // if I comment this line, its speed is much enough to gain 50 sample/second
      serverClient.println(line);
      Serial.write("\nADC Value sent");
      delay(100);
  }
}


But if I comment " line = String(adc) ", i.e. if I return same value what I received it boost its speed. what could be possible mistakes.
P.S. TCP client program is working fine, I have tested that client program with server written in lua language.

Re: Very Slow TCP and Client Connection

PostPosted: Sun Jan 17, 2016 7:10 pm
by martinayotte
That's really strange that a simple Integer to String conversion slow the whole TCP transmission ... :?
But why are you doing the "String line = serverClient.readStringUntil('\n');" call if you only wish to send something ?
This is waiting for the client to send CR each time before continue in your loop, so the latency your see is probably some kind of timeout.

Re: Very Slow TCP and Client Connection

PostPosted: Sun Jan 17, 2016 7:17 pm
by WereCatf
martinayotte wrote:That's really strange that a simple Integer to String conversion slow the whole TCP transmission ... :?


It's not the conversion, it's the length of the resulting string that causes the issue, something to do with the TCP-packet buffer length. What's the length of the string before the conversion, ie. the length of the data read from the client? I read about this elsewhere, but I forget where, and the solution for now seems to be padding the outgoing data with extra content, like e.g. space characters.

Re: Very Slow TCP and Client Connection

PostPosted: Sun Jan 17, 2016 7:23 pm
by laxmimerit
martinayotte wrote:That's really strange that a simple Integer to String conversion slow the whole TCP transmission ... :?
But why are you doing the "String line = serverClient.readStringUntil('\n');" call if you only wish to send something ?
This is waiting for the client to send CR each time before continue in your loop, so the latency your see is probably some kind of timeout.


If it is timeout then why it is working fine when I am sending back same signal what I receive. any suggestion ?