From b4d07d997fb8753da0154e02f58c38abfa46c9e4 Mon Sep 17 00:00:00 2001 From: cziter15 Date: Wed, 19 Jun 2024 16:29:56 +0200 Subject: [PATCH] Fixes --- src/ksf/comp/ksMqttConnector.cpp | 12 ++++++++++-- src/ksf/ksConstants.h | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ksf/comp/ksMqttConnector.cpp b/src/ksf/comp/ksMqttConnector.cpp index d6b1b01..f804778 100644 --- a/src/ksf/comp/ksMqttConnector.cpp +++ b/src/ksf/comp/ksMqttConnector.cpp @@ -72,12 +72,22 @@ namespace ksf::comps if (certFingerprint->setup(secureClient.get(), fingerprint)) netClientUq = std::move(secureClient); + + #if ESP32 + constexpr auto handshakeTimeoutSec{KSF_MQTT_TIMEOUT_MS/KSF_ONE_SEC_MS}; + secureClient->setHandshakeTimeout(handshakeTimeoutSec); + #endif } else { netClientUq = std::make_unique(); } + /* Set MQTT timeout. */ + netClientUq->setTimeout(KSF_MQTT_TIMEOUT_MS); +#if ESP32 + netClientUq->setConnectionTimeout(KSF_MQTT_TIMEOUT_MS); +#endif /* Whoops, it looks like fingerprint validation failed. */ if (!netClientUq) return; @@ -89,8 +99,6 @@ namespace ksf::comps this->prefix = std::move(prefix); this->broker = std::move(broker); - netClientUq->setTimeout(KSF_SEC_TO_MS(KSF_MQTT_TIMEOUT_SEC)); - /* Load MQTT port. */ ksf::from_chars(port, portNumber); } diff --git a/src/ksf/ksConstants.h b/src/ksf/ksConstants.h index e70fc2a..45719a8 100644 --- a/src/ksf/ksConstants.h +++ b/src/ksf/ksConstants.h @@ -32,9 +32,9 @@ #define KSF_MQTT_RECONNECT_DELAY_MS 5000UL #endif -#ifndef KSF_MQTT_TIMEOUT_SEC -/*! MQTT socket timeout in seconds. On ESP32 is also used as connect (blocking) timeout. */ -#define KSF_MQTT_TIMEOUT_SEC 4UL +#ifndef KSF_MQTT_TIMEOUT_MS +/*! MQTT socket timeout in milliseconds. On ESP32 is also used as connect (blocking) timeout. */ +#define KSF_MQTT_TIMEOUT_MS 4000UL #endif #ifndef KSF_WIFI_TIMEOUT_MS