mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
fix Last Will (LWT) not set on MQTT Connect #2247
This commit is contained in:
@@ -57,10 +57,6 @@ class ESP8266React {
|
||||
// special functions needed outside scope
|
||||
//
|
||||
|
||||
void setWill(const char * will_topic) {
|
||||
_mqttSettingsService.setWill(will_topic);
|
||||
}
|
||||
|
||||
// true if AP is active
|
||||
bool apStatus() {
|
||||
return _apSettingsService.getAPNetworkStatus() == APNetworkStatus::ACTIVE;
|
||||
|
||||
@@ -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