From ac017554444eac6311efbece14140ea7f0170199 Mon Sep 17 00:00:00 2001 From: jevansmith <66101462+jesmith-all@users.noreply.github.com> Date: Mon, 9 Aug 2021 12:29:01 -0400 Subject: [PATCH 1/3] Add optional argument (user) to WifiConnectionHandler and related conditional to substitute Wifi.beginEnterprise method() when modified from default value. --- src/Arduino_WiFiConnectionHandler.cpp | 17 ++++++++++++++--- src/Arduino_WiFiConnectionHandler.h | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index e1a1f12d..97567afd 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -27,10 +27,11 @@ CTOR/DTOR ******************************************************************************/ -WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive) +WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pass, char const * user, bool const keep_alive) : ConnectionHandler{keep_alive} , _ssid{ssid} , _pass{pass} +, _user{user} { } @@ -85,7 +86,12 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); - WiFi.begin(_ssid, _pass); + if (_user != "default"){ + WiFi.beginEnterprise(_ssid, _user, _pass); + } + else{ + WiFi.begin(_ssid, _pass); + } delay(1000); #endif /* #if !defined(BOARD_ESP8266) && !defined(ESP32) */ @@ -97,7 +103,12 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(BOARD_ESP8266) && !defined(ESP32) if (WiFi.status() != WL_CONNECTED) { - WiFi.begin(_ssid, _pass); + if (_user != "default"){ + WiFi.beginEnterprise(_ssid, _user, _pass); + } + else{ + WiFi.begin(_ssid, _pass); + } } #endif /* ifndef BOARD_ESP8266 */ diff --git a/src/Arduino_WiFiConnectionHandler.h b/src/Arduino_WiFiConnectionHandler.h index 56670793..a771df35 100644 --- a/src/Arduino_WiFiConnectionHandler.h +++ b/src/Arduino_WiFiConnectionHandler.h @@ -34,7 +34,7 @@ class WiFiConnectionHandler : public ConnectionHandler { public: - WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive = true); + WiFiConnectionHandler(char const * ssid, char const * pass, char const * user = "default", bool const keep_alive = true); virtual unsigned long getTime() override; @@ -54,6 +54,7 @@ class WiFiConnectionHandler : public ConnectionHandler char const * _ssid; char const * _pass; + char const * _user; WiFiUDP _wifi_udp; WiFiClient _wifi_client; From ffb2399d40ce060afac17fa2cfca82111b593907 Mon Sep 17 00:00:00 2001 From: jevansmith <66101462+jesmith-all@users.noreply.github.com> Date: Mon, 9 Aug 2021 13:14:15 -0400 Subject: [PATCH 2/3] user strcmp() --- src/Arduino_WiFiConnectionHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 97567afd..3926d8eb 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -86,7 +86,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); - if (_user != "default"){ + if (strcmp(_user,"default")){ WiFi.beginEnterprise(_ssid, _user, _pass); } else{ @@ -103,7 +103,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(BOARD_ESP8266) && !defined(ESP32) if (WiFi.status() != WL_CONNECTED) { - if (_user != "default"){ + if (strcmp(_user,"default")){ WiFi.beginEnterprise(_ssid, _user, _pass); } else{ From bd68824e727d46ba9a65215abcc90567b86478e0 Mon Sep 17 00:00:00 2001 From: jevansmith <66101462+jesmith-all@users.noreply.github.com> Date: Mon, 9 Aug 2021 13:52:09 -0400 Subject: [PATCH 3/3] add preprocessor directives --- src/Arduino_WiFiConnectionHandler.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 3926d8eb..a24e737b 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -86,12 +86,17 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ +defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) if (strcmp(_user,"default")){ WiFi.beginEnterprise(_ssid, _user, _pass); } else{ WiFi.begin(_ssid, _pass); } +#else + WiFi.begin(_ssid, _pass); +#endif delay(1000); #endif /* #if !defined(BOARD_ESP8266) && !defined(ESP32) */ @@ -101,8 +106,9 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { #if !defined(BOARD_ESP8266) && !defined(ESP32) - if (WiFi.status() != WL_CONNECTED) - { +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ +defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) + if (WiFi.status() != WL_CONNECTED){ if (strcmp(_user,"default")){ WiFi.beginEnterprise(_ssid, _user, _pass); } @@ -110,6 +116,11 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() WiFi.begin(_ssid, _pass); } } +#else + if (WiFi.status() != WL_CONNECTED){ + WiFi.begin(_ssid, _pass); + } +#endif #endif /* ifndef BOARD_ESP8266 */ if (WiFi.status() != NETWORK_CONNECTED)