Skip to content

Commit

Permalink
Merge pull request #243 from omerfaruk-aran/fix/mqtt-espidf-compatibi…
Browse files Browse the repository at this point in the history
…lity

Fix: Update MQTT client for ESP-IDF compatibility
  • Loading branch information
omerfaruk-aran authored Dec 28, 2024
2 parents ea38459 + 602eec3 commit 95783dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 95783dc

Please sign in to comment.