electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

Ram usage - client connect #59

Closed duarterr closed 6 years ago

duarterr commented 6 years ago

I have a fairly large project implemented with a nodeMCU. Now I want to log some data to a google spreadsheet using the library.

I'm having some trouble with the heap memory after calling "client->connect("script.google.com", 443)". My device has about 17kB free at the moment of this call but apparently this is not enough and I get an memory exception and the device restarts...

With a simple sketch I'm able to use the library with no problems, but the connect call always consume about 18~19kB of free heap. Is this a known issue and how to avoid that?

HuibGroenewegen commented 6 years ago

I also had problems with the free heap memory and finally discovered that if you use the V2.4.1 version of the ESP8266 board management definition library in Arduino ,the memory heap dissapears fast, but if you roll back to the V2.4.0 than it works ok even without a delay in the main loop. May be this is your problem.

duarterr commented 6 years ago

Update on the problem:

The heap issue is actually due to the client secure library. Secure connections require more memory and there is nothing I can do about it.

To solve the issue in my code, I used the ESP8266HTTPClient library to make the http requests to a local server and a php script to make the https redirects. It's sketchy but works very well...

HuibGroenewegen commented 6 years ago

I do not know if you you just tried my suggestion. If you compile in ESP8266 V2.4.1 the sketch crashes after about 20 cycles, but with the ESP8266 V2.4.0 it runs without memory heap problems. Yes it consumes memory but there is still about 20.000 bytes available depending on the sketch cycle time.

duarterr commented 6 years ago

Yes, I had already tried this and it reduces the memory consumption indeed. However, as I stated in the first post, I have a very large project and the ESP don't have enough heap to make a secure connection.

My solution is not elegant, but works...

I'm closing the issue as this is not a problem with the library.