Client keep_alive is now parameterized

This commit is contained in:
hsaturn
2021-03-24 21:16:31 +01:00
parent 70cf8137de
commit 28c8713415
3 changed files with 4 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*~ *~
src/my_credentials.h

View File

@@ -59,7 +59,7 @@ void MqttClient::close()
} }
} }
void MqttClient::connect(std::string broker, uint16_t port) void MqttClient::connect(std::string broker, uint16_t port, uint16_t ka)
{ {
debug("cnx: closing"); debug("cnx: closing");
close(); close();
@@ -74,7 +74,7 @@ void MqttClient::connect(std::string broker, uint16_t port)
message.add(0x4); // Mqtt protocol version 3.1.1 message.add(0x4); // Mqtt protocol version 3.1.1
message.add(0x0); // Connect flags TODO user / name message.add(0x0); // Connect flags TODO user / name
keep_alive = 1; // TODO not configurable keep_alive = ka; // TODO not configurable
message.add(0x00); // keep_alive message.add(0x00); // keep_alive
message.add((char)keep_alive); message.add((char)keep_alive);
message.add(clientId); message.add(clientId);

View File

@@ -123,7 +123,7 @@ class MqttClient
~MqttClient(); ~MqttClient();
void connect(MqttBroker* parent); void connect(MqttBroker* parent);
void connect(std::string broker, uint16_t port); void connect(std::string broker, uint16_t port, uint16_t ka=10);
bool connected() { return bool connected() { return
(parent!=nullptr and client==nullptr) or (parent!=nullptr and client==nullptr) or