Skip to content

Commit

Permalink
Fix: conf_esp_idf.yml test build version: recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfaruk-aran committed Dec 28, 2024
1 parent b4b64e6 commit 58f0245
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions components/samsung_ac/debug_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ 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 = {};

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
std::string uri = "mqtt://" + (!username.empty() ? username + ":" + password + "@" : "") + host + ":" + std::to_string(port);
mqtt_cfg.uri = uri.c_str();
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;
if (!username.empty())
Expand All @@ -59,10 +66,10 @@ namespace esphome
mqtt_cfg.password = password.c_str();
}
#endif

mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(mqtt_client);
}

#endif
}

Expand Down

0 comments on commit 58f0245

Please sign in to comment.