Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update MQTT client for ESP-IDF compatibility #243

Merged
merged 8 commits into from
Dec 28, 2024
2 changes: 1 addition & 1 deletion .github/conf_esp_idf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions components/samsung_ac/debug_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}

Expand Down
Loading