Post topics, source code that relate to the Arduino Platform

User avatar
By laxmimerit
#39090 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.
User avatar
By martinayotte
#39098 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.
User avatar
By WereCatf
#39099
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.
User avatar
By laxmimerit
#39100
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 ?