Skip to content

Packet loss on WiFi #129

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

Closed
maxosprojects opened this issue Jan 16, 2017 · 10 comments
Closed

Packet loss on WiFi #129

maxosprojects opened this issue Jan 16, 2017 · 10 comments

Comments

@maxosprojects
Copy link

I'm noticing packet loss on ESP32 Thing (from Sparkfun) on WiFi in infrastructure mode.
The device is, supposedly, connected via 802.11n

I disabled SoftAP mode, but that didn't change anything:

  // Set STA mode (disable softAP)
  WiFi.mode(WIFI_MODE_STA);
  //Initiate connection
  WiFi.begin(ssid, pwd);

The problem was discovered with TCP and then I ran some tests with ICMP pings.
Here are the results at different intervals between requests. Tests were executed on a wired connection to the AP to which ESP32 is connected via WiFi:

1s
200 packets transmitted, 196 received, 2% packet loss, time 199325ms
rtt min/avg/max/mdev = 1.117/16.662/1007.573/72.556 ms, pipe 2

100ms
200 packets transmitted, 191 received, 4% packet loss, time 20097ms
rtt min/avg/max/mdev = 1.045/17.414/458.020/48.626 ms, pipe 5

10ms
200 packets transmitted, 195 received, 2% packet loss, time 2101ms
rtt min/avg/max/mdev = 0.982/4.113/48.350/5.878 ms, pipe 3

Loss rate varies form test to test.

At the same time, a Raspberry Pi 3 connected to the same AP shows no hiccups, nor a single packet loss.

I suspect problem is in one of the binary libraries pulled in here. How can I track down which one?

@maxosprojects maxosprojects changed the title WiFi packet loss Packet loss on WiFi Jan 16, 2017
@igrr
Copy link
Member

igrr commented Jan 16, 2017

We are tracking a similar issue about packet loss with ESP-IDF WiFi driver internally. I will post an update here once we resolve it.

@maxosprojects
Copy link
Author

Thank you!
Could you please link the issue here?

@maxosprojects
Copy link
Author

Any followup on this?

@me-no-dev
Copy link
Member

can you please check the latest version and report back?

@me-no-dev
Copy link
Member

Closing because of no response

@Pgpapa-doodl
Copy link

Hello All,
I want to detect the data packet loss in esp32. Any idea how to do that?
Test setup: temperature sensor-master esp32-slave esp32.
I will send temperature sensor data from temperature sensor to Master esp32 and then using wifi to slave esp32. Then I need to check data packet loss when I receive data back from slave to master.

I am a newbie in this field. Kindly cooperate.

Thank you:)

@lbernstone
Copy link
Contributor

TCP/IP has packet loss detection and correction built in. Please don't hijack threads from 3 years ago. Open a new thread and follow the directions in the issue template.

@Pgpapa-doodl
Copy link

TCP/IP has packet loss detection and correction built in. Please don't hijack threads from 3 years ago. Open a new thread and follow the directions in the issue template.

I want to measure the data packet loss for different intra communication protocol like I2C, SPI and ESP-NOW.
So how can I use TCP/IP for all these protocols?
Also yes I'll keep your advice in mind from next time.

@hidogan
Copy link

hidogan commented Mar 20, 2021 via email

@wachidsusilo
Copy link

wachidsusilo commented Dec 8, 2022

With version 2.0.5, this is still happening. When using WebSocket client, the received WebSocket header has correct payload length, but the data is truncated.

// [PacketLength]: [Data]

45: {
  "type": "reg",
  "data": "audio-player"
}
45:                             -> PACKET LOSS
45: {
  "type": "reg",
  "data": "audio-player"
}
45: {
  "type": "reg",
  "data": "audio-player"
}
45: {
  "type": "reg",
  "data": "aud                  -> PACKET LOSS
45: {
  "type": "reg",
  "data": "audio-player"
}
45: {
  "type": "reg",
  "data": "audio-player"
}
45:                             -> PACKET LOSS
45: {
  "type": "reg",
  "data": "audio-player"
}
45: {
  "type": "reg",
  "                             -> PACKET LOSS
45: {
  "type": "reg",
  "data": "audio-player"
}
45: {
  "type": "reg",
  "data": "audio-player"
}

And this is the implementation of the WebSocket client for reading incoming packet:

if (!client || !client->available()) return;

uint16_t bin = 0;
int i = 0;

while (isConnected()) {
    int res = client->read();
    if (res >= 0) bin |= ((uint8_t)res) << i++ * 8;
    if (i > 1) break;
}

Frame::Header header(bin);
uint16_t payloadLen = header.payload;

if ((useMask && header.mask) || (!useMask && !header.mask) || !Frame::isValid(Frame::Opcode(header.opcode))) {
    _close(CloseReason_ProtocolError);
    return;
}

if (header.opcode == 0) {
    _close(CloseReason_UnsupportedData);
    return;
}

if (header.payload == 127) {
    _close(CloseReason_MessageTooBig);
    return;
}

if (header.payload == 126) {
    bin = 0;
    i = 0;
    while (isConnected()) {
        int res = client->read();
        if (res >= 0) bin |= ((uint8_t)res) << i++ * 8;
        if (i > 1) break;
    }
    payloadLen = Crypto::swapEndianness(bin);
}

uint8_t maskingKey[4];
if (header.mask) {
    int res = client->read(maskingKey, 4);
}

char payload[payloadLen + 1];
payload[payloadLen] = 0;
uint16_t read = 0;
uint32_t start = millis();

while (isConnected() && read < payloadLen) {
    int res = client->read((uint8_t*)payload + read, payloadLen - read);
    if (res > 0) read += res;
    if (millis() - start > 1000) {
        break;
    }
}

String payloadData(payload); // UPDATE: This is where it goes wrong.
if (header.mask) Crypto::remaskData(payloadData, maskingKey);
Serial.println(String(payloadLen) + ": " + payloadData);

UPDATE 08/12/2022:
Never mind, this was on me. I've found what is the problem. I should have demasking the data before putting it into a String. Because the unmasked data could be '\0' i guess.

brentru added a commit to adafruit/arduino-esp32 that referenced this issue Oct 22, 2024
Add Feather ESP32-S3, QT Py ESP32-S3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants