-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ESP8266 Losing packets #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I suppose the reason is that client.flush(); discards all data in RX buffer. On Thu, Oct 22, 2015, 01:38 drmpf [email protected] wrote:
|
try this and see if it works better |
@igrr I changed my code to
But still loose packet data about once in 5 times. I had look at the HardwareSerial.cpp flush() method.
Looks to me like it just waits until all the data has been taken? @me-no-dev Thanks for the link. Looks good for Telnet, but not so good for general streaming data. ESP only seems to handle on packet at a time outgoing on the fly and then waits for the ACK to come back before sending the next one. NoTCPDelay does not make any difference. So my code attempts to send filled packets if you are sending streaming data.
for a full incoming packet (1460 bytes) and so not handle the incoming Serial data. |
@me-no-dev Also the Telnet to Serial code has problems with half closed connections. If the client goes away (dies or wifi breaks), the server stays connected to its client connection and the no clients, even the original one, can connect until the connection times out. Not good if you have flaky WiFi or if your client gets killed by the user. |
I thought your code called WiFiClient::flush, not HardwareSerial::flush. Unlike HardwareSerial::flush, WiFiClient::flush will discard all RX data. Will see if i can write a sketch to reproduce your issue. |
@igrr OK, let me remove the client.flush() as well it may be causing problem. |
Just to make it more clear, client.write() blocks until either data is sent and ACKed, or timeout occurs (currently hard-coded to 5 seconds). So client.flush() doesn't "force" sending data after client.write(), because there is no output buffer which can be flushed. It does discard incoming data though. |
OK that would be the magic statement. The client.flush() would drop discard my incoming data :-( Rather than having the sketch blocked for 5sec, is there some way to tell if last packet has been sent and Acked. Acking takes about 0.2sec with windows client. That way I could buffer incoming serial until client available to take next packet. |
Sketch is blocked until either packet is acked, or timeout expires. So if the packet is ACKed in 0.2 seconds, sketch will not get blocked for 5 sec. While there is no "nonblocking write" API in WiFiClient, you may use LwIP APIs directly to process data in an event-driven manner. |
Thanks, was hoping to avoid the 0.2sec delay. At 115200 that is about 2K of incoming Serial data the sketch is not handling. |
This isn't available since ESP8266WiFi library API is a blocking one, like WiFi Shield library. |
200ms seems a bit high. I am able to make 8ms request/response times with the http server which does parsing and whatnot. Other than that I get your problem and I'm currently in the same boat, but i'm looking for a way without timeout |
@igrr Sure I will close this. thanks again and great work. |
I had done some tests and 13ms are possible for windows. |
Thanks for the cross link. For non- full packets (<1460bytes), I consistently get 200mS between incoming packet and outgoing ACK (as measured by Wireshark running on the Windows PC). Not sure if Windows acks full packets any quicker. |
hi @Links2004 , |
I use a Router with openwrt and the AP only is used for the ESPs. the whole setup looks like this: but it dont need to be so complex ;) |
I am coding a UART to WiFi bridge for ESP8266 running as a server.
Using build 1.6.5-947-g39819f0
I am finding that the ESP client is losing packets between the ESP TCP/IP stack and the client.available() method.
ESP Code is
Testing with Wireshark from Windows, I find the following
where the client sends {.} to the ESP which responds with
. from the ESP code (above) and . from the Arduino code consuming the ESP serial out. E.g.
A longer sequence of msgs is
however the ESP looses the last {.} above and does not respond and the client closes the connection due to lack of response.
Checking the WireShark files shows that the {.} packet was acked by the ESP, but the bytes did not make it to the client.available() call.
client sends {.}
24 3.833327000 192.168.0.2 192.168.0.100 TCP 57 59029→4989 [PSH, ACK] Seq=10 Ack=714 Win=16807 Len=3
Esp acks {.}
25 3.950966000 192.168.0.100 192.168.0.2 TCP 54 4989→59029 [ACK] Seq=714 Ack=13 Win=5828 Len=0
This problem only seems to happen when the ESP is also sending data back i.e. the
41.00,0,0,0,0,0,0,0,0,0,0,0
etc.
If I disable the sending of that extra data, things seem to work.
Data and responses are provided by an Arduino board connected to the ESP serial TXRX
EDIT: Actually also loose packet data even when not sending extra data back.
The text was updated successfully, but these errors were encountered: