Last will not works
esleybonomo opened this issue · comments
Esley Bonomo commented
Hello,
I'll try to use last will but I can't.
void EventProcessor::conn(const QString &hostname, const int port, const QString &username, const QString &password, bool lastWill)
{
connect(client, &QMqttClient::stateChanged, this, &EventProcessor::stateChanged);
if (lastWill)
setLastWill(SERVICE_STATUS_TOPIC, SERVICE_STATUS_ERROR);
client->setClientId("app." + clientName + QUuid::createUuid().toString(QUuid::WithoutBraces));
client->setHostname(hostname);
client->setPort(port);
client->setUsername(username);
client->setPassword(password);
client->setCleanSession(true);
Logger::writeLog(SeverityLevels::DEBUG, "Trying connect to broker.", __FILENAME__, __func__,
"[host: " + hostname.toStdString() + " | port: " + std::to_string(port) + " | username: " + username.toStdString() + " | password: " + password.toStdString() + "]");
client->connectToHost();
}
void EventProcessor::setLastWill(const QString &topic, const QString &content)
{
QMqttLastWillProperties lastWill;
lastWill.setResponseTopic(topic);
lastWill.setContentType(content);
lastWill.setWillDelayInterval(0);
lastWill.setPayloadFormatIndicator(QMqtt::PayloadFormatIndicator::UTF8Encoded);
client->setLastWillProperties(lastWill);
}
What I'm doing wrong? Or is there a bug about it?
Matthias Dieter Wallnöfer commented
Is this really our library, since our interface for last will messages looks a bit different (https://github.com/emqx/qmqtt/blob/master/src/mqtt/qmqtt_client.h):
void setWillTopic(const QString& willTopic);
void setWillQos(const quint8 willQos);
void setWillRetain(const bool willRetain);
void setWillMessage(const QByteArray& willMessage);