MQTT: LWT

This commit is contained in:
jomjol
2020-12-30 10:35:50 +01:00
parent becb886ab7
commit ae116981ef
6 changed files with 12 additions and 7 deletions

View File

@@ -67,13 +67,12 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _LWTContext, int _keepalive){
std::string _zwmessage = "connection lost";
int _lzw = _LWTContext.length();
int _lzw = _zwmessage.length();
esp_mqtt_client_config_t mqtt_cfg = {
.uri = _mqttURI.c_str(),
.client_id = _clientid.c_str(),
// .lwt_topic = _LWTContext.c_str(),
.lwt_topic = "wasserzaehler/connection",
.lwt_topic = _LWTContext.c_str(),
.lwt_msg = _zwmessage.c_str(),
.lwt_msg_len = _lzw,
.keepalive = _keepalive
@@ -88,4 +87,6 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
esp_mqtt_client_start(client);
MQTTPublish(_LWTContext, "");
}