diff --git a/.github/conf_esp_idf.yml b/.github/conf_esp_idf.yml index 37b9ed0e..3d1c3c0d 100644 --- a/.github/conf_esp_idf.yml +++ b/.github/conf_esp_idf.yml @@ -22,7 +22,7 @@ samsung_ac: debug_mqtt_port: 1883 debug_mqtt_username: mqtt_user debug_mqtt_password: mqtt_pass - + debug_log_messages: false debug_log_messages_raw: false diff --git a/components/samsung_ac/debug_mqtt.cpp b/components/samsung_ac/debug_mqtt.cpp index d4826feb..6fb3d48a 100644 --- a/components/samsung_ac/debug_mqtt.cpp +++ b/components/samsung_ac/debug_mqtt.cpp @@ -45,6 +45,18 @@ namespace esphome #elif defined(USE_ESP32) if (mqtt_client == nullptr) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + // For ESP-IDF v5.0 and above + std::string uri = "mqtt://" + host + ":" + std::to_string(port); + esp_mqtt_client_config_t mqtt_cfg = {}; + mqtt_cfg.broker.address.uri = uri.c_str(); + if (!username.empty()) + { + mqtt_cfg.credentials.username = username.c_str(); + mqtt_cfg.credentials.authentication.password = password.c_str(); + } +#else + // For ESP-IDF versions below v5.0 esp_mqtt_client_config_t mqtt_cfg = {}; mqtt_cfg.host = host.c_str(); mqtt_cfg.port = port; @@ -53,9 +65,11 @@ namespace esphome mqtt_cfg.username = username.c_str(); mqtt_cfg.password = password.c_str(); } +#endif mqtt_client = esp_mqtt_client_init(&mqtt_cfg); esp_mqtt_client_start(mqtt_client); } + #endif }