0

I uploaded the following sketch to my ESP8266:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);
String toServe;

void serveShortString() {
    server.send(200, "text/plain", "short string!");
}

void serveLongString() {
    server.send(200, "text/plain", toServe);
}

void setup() {
    WiFi.softAP("test");

    // fill string to serve:
    toServe.reserve(3000);
    for(int i=0; i<150; i++) toServe += "1234567890123456789\n";

    server.on("/long", serveLongString);
    server.on("/short", serveShortString);
    server.begin();
}

void loop() {
    server.handleClient();
}

It serves a short message on /short and a long message (3000 chars) on /long.

The /short page works everywhere: Windows, Desktop Linux (Fedora) and Android. The /long page, on the other hand, only works on Windows and most of the time on desktop Linux. It never works on Android. I tried two phones.

I captured the network traffic on my Android phone using tPacketCapture. This is the result: enter image description here

When trying to get /short, everything works fine. When trying to get /long, only the header comes through but the content never arrives. As I said, everything works fine on Windows and (most of the time) on Desktop Linux. Any idea what's going wrong?

3
  • Sounds like you're hitting some MTU limit or fragmentation issue.
    – Majenko
    Commented Apr 28, 2018 at 14:53
  • @Majenko yeah, when the response takes up more than one TCP packet, Android only receives the first one (as seen in the capture). It works on other operating systems though.
    – Geier
    Commented Apr 28, 2018 at 15:04
  • This seems to be a problem with the core libraries, probably best to open an issue on GitHub.
    – tttapa
    Commented Apr 28, 2018 at 15:21

1 Answer 1

1

The solution is to add the following line to platformio.ini:

build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY

I noticed that the same sketch works without a problem when building with the Arduino IDE, so I checked the differences in building with platformio and the Arduino IDE.

Turns out the relevant difference is that the Arduino IDE uses lwIP 2 by default, while platformio uses 1.4, which seems to have this bug (the same bug appears when using the Arduino IDE with lwIP 1.4).

The build flag above tells platformio to use lwIP v2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.