[TEENSY 4.1] AsyncWebServer arduino library - unexpected result/bug ?

Fiskusmati

Active member
Hello.
I'm running below test code. It does produce unexpected result on my setup.
C:
#if !(defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41))
#error Only Teensy 4.1 supported
#endif

#define BUFFER_SIZE 32000
#include "QNEthernet.h"  // https://github.com/ssilverman/QNEthernet
using namespace qindesign::network;
#include <AsyncWebServer_Teensy41.h>

AsyncWebServer server(80);

void handleRoot(AsyncWebServerRequest *request) {
  char temp[BUFFER_SIZE];
  memset(temp, 0, sizeof(temp));

  strcat(temp, "<html><body>");

  for (int i = 0; i < 11559; i++) {
    strcat(temp, "0");
  }

  strcat(temp, "</body></html>");

  request->send(200, "text/html", temp);
  Serial.println(strlen(temp));
}


void setup() {
  Serial.begin(115200);

  Ethernet.begin();
  if (!Ethernet.waitForLocalIP(5000)) {
    Serial.println(F("Failed to configure Ethernet"));

    if (!Ethernet.linkStatus()) {
      Serial.println(F("Ethernet cable is not connected."));
    }

    // Stay here forever
    while (true) {
      delay(1);
    }
  } else {
    Serial.print(F("Connected! IP address:"));
    Serial.println(Ethernet.localIP());
  }

  delay(1000);


  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    handleRoot(request);
  });

  server.begin();
  Serial.print(F("HTTP EthernetWebServer is @ IP : "));
  Serial.println(Ethernet.localIP());
}

void loop() {
}

It should print out only zeros on html page. But instead it looks like that:
1701909882298.png


It seems like it is printing some random garbage in the middle, if payload length is higher or equal 11585 bytes.

Looks like this payload is split into 3 TCP packets, but on the third packet, there are unexpected bytes at the beginning of the payload:
1701910585437.png

Can anyone replicate that, or knows how to solve this issue? Thanks.
 
Last edited:
A little about AsyncWebServer_Teensy41: it doesn't really use the QNEthernet library. It does use the initialization machinery, but then uses the included lwIP stack (via the Teensy41_AsyncTCP library) and not the QNEthernet API. I wonder if fragmentation is entering into the picture because I'm not sure what AsyncTCP is doing. Could you try this experiment: Set IP_FRAG to 0 in lwipopts.h in your QNEthernet install.
 
Back
Top