Skip to content

Calling WiFiUDP::parsePacket() too often eventually causes it to return zero always #2871

Closed
@ssilverman

Description

@ssilverman

Hardware:

Board: Adafruit ESP32 Feather
IDE: PlatformIO + VSCode (framework-arduinoespressif32 v2.10002.190416)
IDE: Arduino IDE 1.8.9 (ESP32 v1.0.2)

Description:

I’m discovering that calling parsePacket() too often when receiving UDP packets from an external source causes it to eventually return zero always. Note that in the code below, the free heap is always printed every 5 seconds, it's just the parsePacket() that fails to return non-zero after it receives a bunch of packets.

You can test this code by sending a bunch of packets to port 8000, say with some random TouchOSC UI on a mobile device, and dragging one of the sliders so that packets are being sent often.

Sketch:

#include <Esp.h>
#include <WiFi.h>

WiFiUDP udp;

constexpr char kAPName[] = "esp32test";
constexpr char kAPPassword[] = "password";

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for Serial
  }
  Serial.println("Starting.");

  Serial.println("Starting SoftAP...");
  if (WiFi.softAP(kAPName, kAPPassword)) {
    Serial.print("    IP     : ");
    Serial.println(WiFi.softAPIP());
  } else {
    Serial.println("ERROR: Starting SoftAP!");
  }

  if (!udp.begin(8000)) {
    Serial.println("Error starting UDP server.");
  }
}

int counter = 0;

void loop() {
  int size = udp.parsePacket();
  if (size > 0) {
    Serial.printf("%d: %d\n", ++counter, size);
    udp.flush();
  }

  // Print some status every 5s
  static unsigned long lastT = 0;
  unsigned long t = millis();
  if (t - lastT >= 5000) {
    Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
    lastT = t;
  }
}

Debug Messages:

After system initialization, there are no debug messages, even at the Verbose level, except for this one after a while, and after UDP receive has already stopped returning non-zero from parsePacket():

[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 16 - AP_STADISCONNECTED

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions