From 28c8713415a5e36a8b540e3bc0fe5218d82218b4 Mon Sep 17 00:00:00 2001 From: hsaturn Date: Wed, 24 Mar 2021 21:16:31 +0100 Subject: [PATCH] Client keep_alive is now parameterized --- .gitignore | 1 + src/TinyMqtt.cpp | 4 ++-- src/TinyMqtt.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b25c15b..5bdf2ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +src/my_credentials.h diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index 5bc9dff..24d1c5c 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -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"); 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(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((char)keep_alive); message.add(clientId); diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index 7990b88..8109942 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -123,7 +123,7 @@ class MqttClient ~MqttClient(); 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 (parent!=nullptr and client==nullptr) or