-->
Page 1 of 1

ESP8266 delays the received data output to serial

PostPosted: Sat Jun 23, 2018 12:32 am
by waylander
Hello esp8266 comunity,

My first post, don't get angry if I do something wrong please ;)

So, I am connecting my ESP8266 to a TCP server running on my PC, the purpose is the board to receive certain strings and float values and to relay them to the serial port without changing them.
It does what's supposed to, however with a long delay - in the range of 9 to 10 seconds.
I am monitoring the traffic via Wireshark, and all looks fine there, the module responds to the server messages almost immediately sending ACK message, but on the serial port, there's a big pause before all messages are sent at once. No lost messages, but my application will be somehow time critical and this issue spoils all the fun.
here the snippet of the code running in loop:

Code: Select allvoid loop() {
  String line = client.readStringUntil('\r');
  Serial.println(line);
}


I also tried inserting
Code: Select allclient.flush()
after the read line, but no change.

Please advice what is that I'm not doing right.

Apart from that it's a great little board and I see lots of projects coming to this one.

Cheers!

Re: ESP8266 delays the received data output to serial

PostPosted: Sun Jun 24, 2018 11:55 am
by McChubby007
First, obviously the UART/serial is a low speed device, so it takes milliseconds to output a line of text. However, you also need to allow the background context to service wi-fi etc, by calling yield() or delay() [with a small delay].

Re: ESP8266 delays the received data output to serial

PostPosted: Sun Jun 24, 2018 12:11 pm
by waylander
Hi McChubby007, thanks for your answer.
While I was waiting for my first post to be approved I've done some investigation and the result was I discovered big delay in the readStringUntil() function, not sure why.
I've replaced that line with read() followed by a loop to assemble the string back from the read chars, and now the code works fine - no delay (or at least a very small one). As the Stream library is embedded in the Arduino IDE I could not locate the folder so I could not review the readStringUntil() function code, but as I got solution it's no longer needed.

Re: ESP8266 delays the received data output to serial

PostPosted: Sun Jun 24, 2018 1:45 pm
by torntrousers
9 seconds is a really long time so there must be something waiting somewhere. What happens if you change the code to not do the readStringUntil but instead something like
Code: Select allSerial.print(client.read())
?