mirror of https://github.com/nymea/nymea-mqtt
Fix keepalive timeout being uninitialized in client and allow setting it
parent
1cd8273c30
commit
a8037d599d
|
|
@ -48,6 +48,7 @@ int main(int argc, char *argv[]) {
|
||||||
{{"payload", "l"}, "Publish payload (requires -p).", "payload"},
|
{{"payload", "l"}, "Publish payload (requires -p).", "payload"},
|
||||||
{{"retain", "r"}, "Retain flag for publishes (default: no retaining)."},
|
{{"retain", "r"}, "Retain flag for publishes (default: no retaining)."},
|
||||||
{{"qos", "q"}, "QoS (default: 1).", "QoS", "1"},
|
{{"qos", "q"}, "QoS (default: 1).", "QoS", "1"},
|
||||||
|
{{"keepalive", "k"}, "Keep alive timeout in seconds (default: 60)", "keepalive", "60"},
|
||||||
{{"ssl", "S"}, "Use SSL for TCP connections (default: off) (Websocket connections will determine the use of SSL using the url scheme)."},
|
{{"ssl", "S"}, "Use SSL for TCP connections (default: off) (Websocket connections will determine the use of SSL using the url scheme)."},
|
||||||
{{"accept-self-signed-certificate", "A"}, "Ignore self signed certificate errors"},
|
{{"accept-self-signed-certificate", "A"}, "Ignore self signed certificate errors"},
|
||||||
{{"verbose", "v"}, "Be more verbose"}
|
{{"verbose", "v"}, "Be more verbose"}
|
||||||
|
|
@ -73,7 +74,15 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
bool retain = parser.isSet("retain");
|
bool retain = parser.isSet("retain");
|
||||||
|
|
||||||
|
int keepAlive = parser.value("keepalive").toInt(&ok);
|
||||||
|
if (!ok || keepAlive < 0 || keepAlive > 65535) {
|
||||||
|
qCritical() << "Invalid keep alive option. Must be a number from 0 to 65535.";
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
MqttClient client(parser.value("clientid"), app);
|
MqttClient client(parser.value("clientid"), app);
|
||||||
|
client.setKeepAlive(keepAlive);
|
||||||
|
|
||||||
QObject::connect(&client, &MqttClient::error, app, [&client, app](QAbstractSocket::SocketError socketError){
|
QObject::connect(&client, &MqttClient::error, app, [&client, app](QAbstractSocket::SocketError socketError){
|
||||||
qCritical() << "Connection error:" << socketError;
|
qCritical() << "Connection error:" << socketError;
|
||||||
client.setAutoReconnect(false);
|
client.setAutoReconnect(false);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public:
|
||||||
quint16 maxReconnectTimeout = 36000;
|
quint16 maxReconnectTimeout = 36000;
|
||||||
|
|
||||||
QString clientId;
|
QString clientId;
|
||||||
quint16 keepAlive;
|
quint16 keepAlive = 0;
|
||||||
QTimer keepAliveTimer;
|
QTimer keepAliveTimer;
|
||||||
QString willTopic;
|
QString willTopic;
|
||||||
QByteArray willMessage;
|
QByteArray willMessage;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue