diff --git a/Version.h b/Version.h index e81c373..bf5f828 100644 --- a/Version.h +++ b/Version.h @@ -1,3 +1,3 @@ #pragma once -#define nuki_hub_version "4.3" \ No newline at end of file +#define nuki_hub_version "4.4" \ No newline at end of file diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index ffbdc24..a4adb55 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -1,6 +1,5 @@ #include #include "WifiDevice.h" -#include "WiFiManager.h" #include "../PreferencesKeys.h" WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences) @@ -42,14 +41,13 @@ void WifiDevice::initialize() { WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP - WiFiManager wm; std::vector wm_menu; wm_menu.push_back("wifi"); wm_menu.push_back("exit"); - wm.setShowInfoUpdate(false); - wm.setMenu(wm_menu); - wm.setHostname(_hostname); + _wm.setShowInfoUpdate(false); + _wm.setMenu(wm_menu); + _wm.setHostname(_hostname); bool res = false; @@ -57,11 +55,11 @@ void WifiDevice::initialize() { Serial.println(F("Opening WiFi configuration portal.")); _cookie.clear(); - res = wm.startConfigPortal(); + res = _wm.startConfigPortal(); } else { - res = wm.autoConnect(); // password protected ap + res = _wm.autoConnect(); // password protected ap } if(!res) { @@ -74,9 +72,6 @@ void WifiDevice::initialize() Serial.println(WiFi.localIP().toString()); } - _wifiSSID = wm.getWiFiSSID(); - _wifiPSK = wm.getWiFiPass(); - _mqttClient->setBufferSize(_mqttMaxBufferSize); } @@ -106,15 +101,7 @@ bool WifiDevice::isConnected() bool WifiDevice::reconnect() { - WiFi.disconnect(); - WiFi.begin(_wifiSSID.c_str(), _wifiPSK.c_str()); - - unsigned long timeout = millis() + 5000; - while(!isConnected() && millis() < timeout) - { - delay(100); - } - + delay(3000); return isConnected(); } diff --git a/networkDevices/WifiDevice.h b/networkDevices/WifiDevice.h index 30d35ed..322fc85 100644 --- a/networkDevices/WifiDevice.h +++ b/networkDevices/WifiDevice.h @@ -5,6 +5,7 @@ #include #include "NetworkDevice.h" #include "../SpiffsCookie.h" +#include "WiFiManager.h" class WifiDevice : public NetworkDevice { @@ -23,14 +24,12 @@ public: virtual PubSubClient *mqttClient(); private: + WiFiManager _wm; WiFiClient* _wifiClient = nullptr; WiFiClientSecure* _wifiClientSecure = nullptr; PubSubClient* _mqttClient = nullptr; SpiffsCookie _cookie; - String _wifiSSID = ""; - String _wifiPSK = ""; - char _ca[TLS_CA_MAX_SIZE]; char _cert[TLS_CERT_MAX_SIZE]; char _key[TLS_KEY_MAX_SIZE];