From b11a3329f89448411f62f6adee17bb364663c88f Mon Sep 17 00:00:00 2001 From: technyon Date: Sat, 28 Jan 2023 21:59:35 +0100 Subject: [PATCH] fix crash when using encrypted connection --- Network.cpp | 2 +- networkDevices/WifiDevice.cpp | 4 ++-- networkDevices/WifiDevice.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Network.cpp b/Network.cpp index b2524fe..7a66eeb 100644 --- a/Network.cpp +++ b/Network.cpp @@ -264,7 +264,7 @@ bool Network::reconnect() } bool connected = _device->mqttConnected(); - unsigned long timeout = millis() + 5000; + unsigned long timeout = millis() + 3000; while(!connected && millis() < timeout) { diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index 79f52df..c6ea494 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -18,9 +18,9 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences) size_t crtLength = _preferences->getString(preference_mqtt_crt,_cert,TLS_CERT_MAX_SIZE); size_t keyLength = _preferences->getString(preference_mqtt_key,_key,TLS_KEY_MAX_SIZE); - _useEncryption = caLength > 1; + _useEncryption = caLength > 1; // length is 1 when empty - if(_useEncryption > 1) // length is 1 when empty + if(_useEncryption) { Log->println(F("MQTT over TLS.")); Log->println(_ca); diff --git a/networkDevices/WifiDevice.h b/networkDevices/WifiDevice.h index 71a5d4f..a4d724d 100644 --- a/networkDevices/WifiDevice.h +++ b/networkDevices/WifiDevice.h @@ -57,7 +57,7 @@ private: char* _path; bool _useEncryption = false; - char _ca[TLS_CA_MAX_SIZE]; - char _cert[TLS_CERT_MAX_SIZE]; - char _key[TLS_KEY_MAX_SIZE]; + char _ca[TLS_CA_MAX_SIZE] = {0}; + char _cert[TLS_CERT_MAX_SIZE] = {0}; + char _key[TLS_KEY_MAX_SIZE] = {0}; };