mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
fix Last Will (LWT) not set on MQTT Connect #2247
This commit is contained in:
@@ -207,6 +207,17 @@ bool MqttSettingsService::configureMqtt() {
|
||||
static_cast<espMqttClient *>(_mqttClient)->setClientId(_state.clientId.c_str());
|
||||
static_cast<espMqttClient *>(_mqttClient)->setKeepAlive(_state.keepAlive);
|
||||
static_cast<espMqttClient *>(_mqttClient)->setCleanSession(_state.cleanSession);
|
||||
|
||||
// create last will topic with the base prefixed. It has to be static because the client destroys the reference
|
||||
static char will_topic[FACTORY_MQTT_MAX_TOPIC_LENGTH];
|
||||
if (_state.base.isEmpty()) {
|
||||
snprintf(will_topic, sizeof(will_topic), "status");
|
||||
} else {
|
||||
snprintf(will_topic, sizeof(will_topic), "%s/status", _state.base.c_str());
|
||||
}
|
||||
setWill(will_topic);
|
||||
|
||||
|
||||
return _mqttClient->connect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user