0

This question already has an answer here:

I have an ESP8266 that has to run 24/7, it sends some data to server every our, everything works fine for about 2-3 days after that it crashes. Sometimes it resets sometimes it freezes. I got to the root of the problem, sending function generates a memory leak. Below the code and serial output.

Code:

Serial.print("-------------------before -----------------");
Serial.print("FlashChipSize: ");
Serial.println(ESP.getFlashChipSize());
Serial.print("FlashChipRealSize: ");
Serial.println(ESP.getFlashChipRealSize());
Serial.print("FlashChipSizeByChipId: ");
Serial.println(ESP.getFlashChipSizeByChipId());
Serial.print("FreeHeap: ");
Serial.println(ESP.getFreeHeap());
if (client.connect(serverName, 80)) {
    client.println("POST /script.php HTTP/1.1");
    client.println("Host: www.site.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println();
    client.println(data);
    Serial.println("sended");
    client.println("GET /index.html HTTP/1.1");
}
else {
    Serial.println("No conn...");
}
client.stop();
Serial.print("-------------------after-----------------");
Serial.print("FlashChipSize: ");
Serial.println(ESP.getFlashChipSize());
Serial.print("FlashChipRealSize: ");
Serial.println(ESP.getFlashChipRealSize());
Serial.print("FlashChipSizeByChipId: ");
Serial.println(ESP.getFlashChipSizeByChipId());
Serial.print("FreeHeap: ");
Serial.println(ESP.getFreeHeap());

Serial.print("-------------------done-----------------");

outputs this in serial terminal:

-------------------before -----------------
FlashChipSize: 4194304
FlashChipRealSize: 4194304
FlashChipSizeByChipId: 4194304
FreeHeap: 43288
sended
-------------------after-----------------FlashChipSize: 4194304
FlashChipRealSize: 4194304
FlashChipSizeByChipId: 4194304
FreeHeap: 41584
-------------------done-----------------0

marked as duplicate by Juraj, MatsK, VE7JRO, sempaiscuba, Community Jan 11 at 13:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    what version of the esp8266 Arduino core? this was fixed in 2.4.2 – Juraj Jan 10 at 11:58
  • the underlying socket context is released later then the stop() command. it must handle the TCP disconnection first and it does it without blocking in the stop() function – Juraj Jan 10 at 12:06
  • @Juraj You are right, memory is freed later, I will investigate this issue and update the question. Also how can I update core version it is something installed in the IDE or into ESP? – Dan Butmalai Jan 10 at 13:10
  • Juraj I edited the question, please have a look. – Dan Butmalai Jan 10 at 13:19
  • How can I free the memory from data delete(data)? – Dan Butmalai Jan 10 at 13:20

Browse other questions tagged or ask your own question.