Chat freely about anything...

User avatar
By Wouter
#80591 I'm having a major problem with an ESP8266 project, getting totally stuck.

This is a code base that used to work - I used it for smaller projects, but it's been expanding and now I ran into a problem that appears to be memory related. Not sure what it is, and I'm out of ideas of where to search. Code base is pretty big by now, a sketch of some 1,500 loc in 12 files plus libraries.

I have a web server running (ESP8266WebServer class), that part and all the other things it has to do works like a charm. It's doing what it has to do and is doing so nicely and quickly.

The problem arises when I try to open a client as well, this to allow the device to send out data to an external server for logging, as well as hosting its own pages for general controls.

This is the part of the code where it goes wrong, but ONLY if the host actually exists and the connection is made. If no connection, it times out and returns without issues.

Code: Select all  Serial.print(F("Free heap: "));
  Serial.println(ESP.getFreeHeap());

  WiFiClientSecure client;

  Serial.print(F("Free heap: "));
  Serial.println(ESP.getFreeHeap());
 
  if (!client.connect(F("www.cityhydroponics.hk"), httpsPort)) {
    hostValid = INVALID;
    Serial.println(F("Host invalid."));
    return;
  }
  hostValid = VALID;


There should be enough memory available: over 22k still free after the client has been allocated, and I've read that an https client needs some 18k.

Yet the last call on the stack is [tt]operator new[](unsigned int)[/tt] which indicates a memory issue.

Upon compilation the IDE says I have 44096 bytes available; that would imply some 19k gets allocated while running, this should be mostly the web server. I've done a lot of work over the last few days figuring this one out; making better use of PROGMEM and stripping the String class where possible (it's used by system libraries...) I got the available memory up by some 10k, but it's apparently still not enough.

The addresses in the stack trace indicate that I also have plenty of stack left, so that should also not be a problem.

Any suggestions on how to make this work?

Code: Select all1:34:17.516 -> Free heap: 28072
01:34:17.516 -> Free heap: 22464
01:34:19.868 ->
01:34:19.868 -> Abort called
01:34:19.868 ->
01:34:19.868 -> >>>stack>>>
01:34:19.868 ->
01:34:19.868 -> ctx: cont
01:34:19.901 -> sp: 3ffffab0 end: 3fffffc0 offset: 01b0
01:34:19.942 -> 3ffffc60:  c02ac026 c00ec004 3ffffc90 40217687 
01:34:19.971 -> 3ffffc70:  c09dc09c c0a1c0a0 003d003c 0035002f 
01:34:20.034 -> 3ffffc80:  00000000 3fff4e04 3ffffd70 402178ef 
01:34:20.100 -> 3ffffc90:  00000000 00000000 00000014 00000000 
01:34:20.133 -> 3ffffca0:  3fff4e2c 3fff4e04 3ffffd70 4021809d 
01:34:20.200 -> 3ffffcb0:  00000000 3ffffd10 40216060 3fffefa0 
01:34:20.233 -> 3ffffcc0:  00000000 00000000 00000000 40201d4f 
01:34:20.299 -> 3ffffcd0:  00000d50 3fff49bc 3ffffd70 4020bea5 
01:34:20.332 -> 3ffffce0:  000001bb 3ffffe24 3ffffe24 3ffffd70 
01:34:20.399 -> 3ffffcf0:  000001bb 3ffffd70 3fff4e04 3ffffd70 
01:34:20.432 -> 3ffffd00:  000001bb 3ffffd70 3fff4e04 40218232