bertmelis / espMqttClient

MQTT 3.1.1 client library for the Espressif devices ESP8266 and ESP32 on the Arduino framework.
https://www.emelis.net/espMqttClient/
MIT License
92 stars 21 forks source link

HeapSize #132

Closed fabltd closed 6 months ago

fabltd commented 6 months ago

When using this libiary I am seeing a sizable reduction in heapsize.

Before MQTT Connection:
free heap size = 99900           min_free_heap_size = 83408 

Connected to MQTT.

 free heap size = 59188           min_free_heap_size = 45432 

Any suggestions on how to reduce this.

I am also trying to use the HTTPS OTA but this is crashes due to insufficant free heap.

Help...

Thanks

bertmelis commented 6 months ago

Did you read the issue template? Hardware? TLS?

fabltd commented 6 months ago

My appogies

ESP32-WROOM-32D yes using TLS = espMqttClientSecure mqttClient;

bertmelis commented 6 months ago

I guess it's the TLS client. The underlying "client context" is created in heap memory. Not much I can do here.

fabltd commented 6 months ago

There are some ways to reduce the TLS client memory any idea where I would set this?

bertmelis commented 6 months ago

I don't know, never explored this area.

Pablo2048 commented 6 months ago

@fabltd if you are on ESP32 there is no easy way AFAIK, because the MBEDTLS_SSL_MAX_CONTENT_LEN constant is compile time constant used in all SSL connections and came from CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN from sdkconfig.h (that is why i love BearSSL much more over mbedTLS). So the only chance I see is to reconfigure the SDK and rebuild all libraries.

proddy commented 6 months ago

BearSSL on an ESP32 has a much lighter footprint than MbedTLS (45kB vs 150kB). Tasmota has a trimmed down arduino/espressif32 core you can use that uses BearSSL. Try replacing the platform in your PIO ini with

platform = https://github.com/tasmota/platform-espressif32.git

or a specific version like

platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip