Files
EMS-ESP32/lib/espMqttClient/src/espMqttClient.cpp
T
Chris Sutcliff cdf6375c71 fix(mqtt): 8 KB MQTT task stack when TLS verifies a CA certificate
On boards with PSRAM the MQTT client runs in its own task with a 5120
byte stack. Verifying an EC certificate chain against a CA, such as
Let's Encrypt ISRG Root X2, needs about 6 KB, so the task overflowed
and the board boot looped on every connect.

The espMqttClient constructors now take the stack size, and
startClient() passes EMSESP_MQTT_STACKSIZE_CA (8192) when TLS is on
with a CA, keeping the 5120 default for insecure TLS and plain MQTT.
The client is recreated when that changes. The stack usage log
reports against the size the task was created with.
2026-10-20 12:40:59 +01:00

69 lines
1.9 KiB
C++

/*
Copyright (c) 2022 Bert Melis. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/
#include "espMqttClient.h"
#if defined(ARDUINO_ARCH_ESP32)
espMqttClient::espMqttClient(espMqttClientTypes::UseInternalTask useInternalTask)
: MqttClientSetup(useInternalTask)
, _client() {
_transport = &_client;
}
espMqttClient::espMqttClient(uint8_t priority, uint8_t core, uint32_t stackSize)
: MqttClientSetup(espMqttClientTypes::UseInternalTask::YES, priority, core, stackSize)
, _client() {
_transport = &_client;
}
espMqttClientSecure::espMqttClientSecure(espMqttClientTypes::UseInternalTask useInternalTask)
: MqttClientSetup(useInternalTask)
, _client() {
_transport = &_client;
}
espMqttClientSecure::espMqttClientSecure(uint8_t priority, uint8_t core, uint32_t stackSize)
: MqttClientSetup(espMqttClientTypes::UseInternalTask::YES, priority, core, stackSize)
, _client() {
_transport = &_client;
}
espMqttClientSecure & espMqttClientSecure::setInsecure() {
_client.client.setInsecure();
return *this;
}
espMqttClientSecure & espMqttClientSecure::setCACert(const char * rootCA) {
_client.client.setCACert(rootCA);
return *this;
}
espMqttClientSecure & espMqttClientSecure::setCertificate(const char * clientCa) {
_client.client.setCertificate(clientCa);
return *this;
}
espMqttClientSecure & espMqttClientSecure::setPrivateKey(const char * privateKey) {
_client.client.setPrivateKey(privateKey);
return *this;
}
espMqttClientSecure & espMqttClientSecure::setPreSharedKey(const char * pskIdent, const char * psKey) {
return *this;
}
#endif
#if defined(__linux__) || defined(__APPLE__)
espMqttClient::espMqttClient()
: MqttClientSetup(espMqttClientTypes::UseInternalTask::NO)
, _client() {
_transport = &_client;
}
#endif