looks like 184 bytes get lost every time you post to the page ie :'http://192.168.0.6/gpio/1'
Hardware: ESP-12, wemos mini, esp-7
Core Version: 2.2.0-rc1
using the example sketch WifiWebServer added one line of code at the end of sketch
Serial.println( ESP.getFreeHeap(),DEC);
Module: wemos mini
Flash Size: ?4MB/1MB?
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: ?OTA / SERIAL?
Reset Method: ?ck / nodemcu?
/*
const char* ssid = "your-ssid";
const char* password = "your-password";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// prepare GPIO2
pinMode(2, OUTPUT);
digitalWrite(2, 0);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('r');
Serial.println(req);
client.flush();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OKrnContent-Type: text/htmlrnrnrnrnGPIO is now ";
s += (val)?"high":"low";
s += "n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
Serial.println( ESP.getFreeHeap(),DEC);
}
This memory should be reclaimed after a couple of minutes, once TCP connection exists TIME_WAIT state. Are you sure that free heap doesn't return to the original value after a few minutes?
not leek, but 20k eating this code:
`
WiFiServer server(80);
const char* ssid = "???";
const char* password = "???";
static const char eatHeap[] =
"HTTP/1.1 200 OKrnContent-Type: text/htmlrnrn"
"rn
size_t orig;
void setup()
{
WiFi.begin(ssid, password);
server.begin();
orig = ESP.getFreeHeap();
}
void loop()
{
WiFiClient client = server.available();
if (client)
{
String s;
s += eatHeap;
s += orig;
s += "/";
s += ESP.getFreeHeap();
s += "
Most helpful comment
since that pull request isnt merged yet and it will take some time to reach upstream, here's a workaround that actually cleanups the TIME_WAITS and frees memory:
update: This goes in your main file. Call tcpCleanup regulary, for example from your loop() function.