-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
First UDP packet always lost #3481
Comments
I also have faced this issue... First, I thought there was some issue with my code, but there is an issue with the library or the wifi chip.. |
As a test, try putting a 1 sec delay between UDP sends. It's possible that the library buffers (or drops) the packet until the ARP request/response completes in order to find the receivers MAC address. Note that by definition, UDP is unreliable and packet loss should be expected. It might be surprising but the library might technically be correct if even if it dropped packets until it gets an ARP reply... |
It seems that even a |
Which suggests it's the delay required for the ARP response. If so, then there's probably a race between getting the response and your sketch making the next call (either In any case, it's probably not a bug. |
In order to get more accurate timestamps with NTP I have taken to "ping" the IP address I'm sending to first to force the arp request. |
Unfortunately the Espressif SDK is not open source, so we can't just look at what's going on. I would have expected |
Why don't just use esp-open-sdk and do what you want to?
Odesláno z iPhonu
6. 9. 2017 v 22:54, AndreKR <[email protected]>:
… Unfortunate the Espressif SDK is not open source, so we can't just look at what's going on. I would have expected endPacket() to block until the packet is sent. Can it be related to having to yield the CPU to the firmware?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@AndreKR said: I thought that their SDK, which seems to be based on the 15 year old 'lwIP' stack was here: While it purports to have a 'this hardware only' MIT License, I don't really see how that would not be a derivative work from the plain, non-restricted lwIP one |
@herrold @suculent It's unclear to me how to use it with Arduino. |
@AndreKR is this still valid with latest git? with latest git and lwip2? (you can select lwip2 from the Arduino IDE menu). |
How to use the git version? |
When installing git version, it should not go into Appdata, instead place
it into 'hardware' directory either under Arduino IDE directory or your
sketchbook direcotry.
…On Fri, Nov 17, 2017, 22:58 AndreKR ***@***.***> wrote:
How to use the git version?
I deleted
%LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\esp8266\2.3.0
and instead downloaded the master branch and put it in
%LOCALAPPDATA%\Arduino15\packages\esp8266\hardware\esp8266com\esp8266
as described in the README. Then I cd'ed into tools and ran python get.py
which completed without errors.
When I now start the Arduino IDE, there are no ESP8266 board available in
Tools -> Boards.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3481 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEJcesIR5jCWY90smQzSjy2VDw89mkd_ks5s3Z8XgaJpZM4Oo0pH>
.
|
Yes, this issue still happens with the current git master and "IwIP Variant" set to "v2", which was the default. |
On current master, I don't have the issue with lwip2. However it indeed does not work with lwip1.4. Here is my complete sketch.
|
Sketch:
Serial output (without bootup gibberish):
Dump:
|
@AndreKR it works for me. I receive |
Strange. I added
Output:
But still no "aaa" in the dump. |
Agreed, strange. Can you try my sketch ? |
Output:
Dump:
Yes, that's the complete dump. :) |
I have no clue. I sent you a mail to do further tests. Can someone else try this with master/lwip2 and report back ? |
The issue might be caused by the link layer dropping the packet after netif output function has returned OK. The fact that this happens in one setup (@AndreKR's) and doesn't happen in the other (@d-a-v's) might be caused by different WiFi data rates, for example (send queue overflows in one case but not the other). |
@d-a-v I responded to your mail. By the way, when I add |
@AndreKR @igrr Thanks, I just misleaded myself believing that the sketch could work in any situation. I had answered in some other issues that UDP must not be used like this, but I just omitted to apply that rule to myself :] |
@d-a-v since a long time there has been the question of why when sending UDP packets too fast, some are dropped. It is understood that it is expected for some UDP packets to get dropped in transit, but we shouldn't be dropping them before even getting them out the door. |
is this related to #3095 ?? i have three esp8266 devices and "both" problems.. original Problem was, after a while (some hours), the first UDP packet was not received.. but (maybe since wlan router firmaware update) it got worth.. sorry to ask, but is there any resolution expectable? i also think, ping from NAS (my DHCP server) wich does not need ARP |
Can you try with |
Still seems to be a problem in 2.5. If multiple UDP packets are sent just after the wifi connection is established only the last one is actually transmitted. Adding a delay(1000) (my guess would be based on chip or xmit speed as 500 does not work for me) after the first packet allows it to go an then any number following will also work without needing any delay. It works fine in 2.4.2 without a delay, all packets are sent. |
Some update, It happens that when sent too quickly (
|
@d-a-v Small progress. I am posting here instead of my issue #5955 as its more relevant. Observation: ARP behaviour post boot is different between In 2.4.2, post esp reset, ARP queries my OTA host roughly 10s after reset. In master (and r2.5.0, 2.5.0b3), there is never an ARP request to my OTA host post boot. When the OTA host initiates the OTA handshake using UDP FLASH command, esp immediately ARP queries the OTA host and gets a reply, BUT there is never the UDP reply OK back to the OTA host causing OTA to fail first time. This is repeatable 100% and confirmed using wireshark and netdump. I think @hridder in his comment above #3481 (comment) almost two years ago eluded to this. It may be that UDP or other packet type are/should be dropped if there's no ARP entry for the dest addr. Some systems implement one packet queues. I can think of few solutions:
|
ARP_QUEUEING Looks promising, it was changed to 0 on Nov 27, 2018 in commit d-a-v/esp82xx-nonos-linklayer@ea83a83#diff-1b7c800f71ea90dc45a57dc398b8bf24 The original lwip distros always had |
When switching from lwIP-2.0 to lwIP-2.1 there were lots of changes in |
It indeed fixes the OTA issue #5955 which is one use case for the "First UDP packet always lost". Using your torture test above with D=0 & So in conclusion, we will always have a first UDP packet loss for a client that is transmitting many UDP packets > A PR on lwip2 repo was created, all that work for one line change, typical ;-)
|
Change ARP_QUEUEING to 1, details in issue esp8266/Arduino#3481 (comment)
#3481 (comment) d-a-v/esp82xx-nonos-linklayer#33 it was removed by error on 9 oct 2018 a1e59e9#diff-8a46852651388faec204ec21c86b8098L586
I understand the question of the number of packets queued per the ARP_QUEUE_LEN parameter, and also the problem in general (packets will be overwritten if prior one has not been sent out yet because arp was not answered). But none of this seem to really fix the issue. If I understand right, having ARP_QUEUE_LEN=1 only makes the problem go to the second packet, but we still have the problem. How can I make sending the first packet out block until arp comes back? Or is there a flag that I can check to avoid sending the next until the one before was really sent out? (This way I can do other stuff and only block on the network). In my tests, this happens in the middle of communications too, it is just a matter of expiring the arp cache and you lose more packets again. |
I see there is a function to get entries from the arp cache: http://www.nongnu.org/lwip/2_0_x/etharp_8c.html#a8038c9e819e16bfdb4c94e2dcdd66784 Maybe there is a way to check if the entry is not there and block? (I can't find a good example of how to use this function). |
Hardware: ESP-12F
Core Version: 2.3.0
I'm sending four UDP packets, with payload "aaa", "bbb", "ccc" and "ddd".
The first of those packets never appears on the receiving machine. It happens absolutely every time, the first packet is always missing.
Serial output:
TCP dump on the receiving machine:
The text was updated successfully, but these errors were encountered: