Skip to content

Commit a6f133f

Browse files
committed
Fix and refactor MQTT client configuration to align with ESP-IDF v5.5+ standards
1 parent 50a84d6 commit a6f133f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
MQTTClient: Changelog
22
=====================
33

4+
HEAD
5+
----
6+
7+
* Fix and refactor MQTT client configuration to align with ESP-IDF v5.5+ standards
8+
49
v1.0.1 (2025-08-14)
510
------
611

src/MQTTClient.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,25 @@ void MQTTClient::setup(void) {
196196

197197
// ESP-IDF v5.5
198198
esp_mqtt_client_config_t mqtt_cfg = {};
199+
200+
// Broker configuration
199201
mqtt_cfg.broker.address.uri = broker_url.c_str();
200-
mqtt_cfg.credentials_t.set_null_client_id = false;
201-
mqtt_cfg.verification_t.use_global_ca_store = this->enable_certificates;
202-
mqtt_cfg.credentials_t.client_id = id_name.c_str();
203-
mqtt_cfg.credentials_t.authentication_t.username = this->enable_user_and_pass ? user_name.c_str() : NULL;
204-
mqtt_cfg.credentials_t.authentication_t.password = this->enable_user_and_pass ? user_password.c_str() : NULL;
205-
mqtt_cfg.credentials_t.authentication_t.certificate = this->enable_certificates ? (const char *)client_cert_pem : NULL;
206-
mqtt_cfg.credentials_t.authentication_t.client_key_pem = this->enable_certificates ? (const char *)client_key_pem : NULL;
207-
mqtt_cfg.task_t.stack_size = task_stack_size;
202+
203+
// Credentials configuration
204+
mqtt_cfg.credentials.set_null_client_id = false;
205+
mqtt_cfg.credentials.client_id = id_name.c_str();
206+
mqtt_cfg.credentials.username = this->enable_user_and_pass ? user_name.c_str() : NULL;
207+
mqtt_cfg.credentials.authentication.password = this->enable_user_and_pass ? user_password.c_str() : NULL;
208+
209+
// Certificate configuration (updated paths)
210+
if (this->enable_certificates) {
211+
mqtt_cfg.broker.verification.use_global_ca_store = true;
212+
mqtt_cfg.credentials.authentication.certificate = (const char *)client_cert_pem;
213+
mqtt_cfg.credentials.authentication.key = (const char *)client_key_pem;
214+
}
215+
216+
// Task configuration
217+
mqtt_cfg.task.stack_size = task_stack_size;
208218

209219
ESP_LOGW(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
210220
client = esp_mqtt_client_init(&mqtt_cfg);

0 commit comments

Comments
 (0)