I think I nailed it.
I can now recieve with my mobile device via VPN. What I did was modifying the chunked data transfer function so that it
- does only send chunks <1400 bytes
- call delay(30) after each chunk or wait for the heap memory to return.
- does no "real" chunking as part of it (announcing the size) is done by the firmware now.
I played a bit with the chunk size and think it is no coincidence that the max. working size is between 1400 and 1500. It is about the size of a TCP packet payload.
There must be some sort of race condition in the firmware.
Code: Select all
void sendWebPageChunkedData(String& log, String& data)
{
String tmp;
delay(20);
checkRAM(F("sendWebPageChunkedData"));
if (data.length() > 0)
{
statusLED(true);
log += F(" [");
log += data.length();
log += F("]");
String size;
size=String(data.length(), HEX)+"\r\n";
//do chunked transfer encoding ourselfs (WebServer doesnt support it)
#define MAXSIZECH 1300
int i = 0;
int memory = 0;
int timeout = 0;
// split into chunks of MAXSIZECH
for (int l = 0; l < (data.length() / MAXSIZECH);l++) {
tmp = data.substring(i, i+ MAXSIZECH); // prepare tmp string for passing to sendContent()
memory = ESP.getFreeHeap(); // available memory before send
timeout = 0; // init timeout
WebServer.sendContent(tmp);
i = i + MAXSIZECH;
while ((ESP.getFreeHeap() < memory)&&(timeout <50)) { // wait for memory to return or the timeout
delay(5);
timeout++;
}
}
// send remainder
tmp = data.substring(i, data.length());
timeout = 0;
memory = ESP.getFreeHeap(); // available memory befor send
WebServer.sendContent(tmp);
while ((ESP.getFreeHeap() < memory) && (timeout <50)) { // wait for memory to return
delay(5);
timeout++;
}
data = F(""); //free RAM
tmp = F("");
}
}
void sendWebPageChunkedEnd(String& log)
{
log += F(" [0]");
WebServer.sendContent("");
WebServer.client().flush();
WebServer.client().stop();
}
Instead of waiting for the memory to return, a delay of 30 ms after each sendContent() works too.
@manjh,
are you running the 2.4.0rc2 core ? Tools->info-> core version. Just asking because 2.3.0 was running fine with me too. It was 2.4.0rc2 that was causing the trouble.