@@ -51,11 +51,16 @@ WiFiConnectionHandler::WiFiConnectionHandler(const char *_ssid, const char *_pas
5151void WiFiConnectionHandler::init () {
5252}
5353
54+ // INIT, CONNECTING, CONNECTED, DISCONNECTING, DISCONNECTED, CLOSED, ERROR
5455void WiFiConnectionHandler::addCallback (NetworkConnectionEvent const event, OnNetworkEventCallback callback){
5556 switch (event) {
5657 case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break ;
5758 case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break ;
5859 case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break ;
60+ case NetworkConnectionEvent::INIT: ; break ;
61+ case NetworkConnectionEvent::CONNECTING: ; break ;
62+ case NetworkConnectionEvent::DISCONNECTING: ; break ;
63+ case NetworkConnectionEvent::CLOSED: ; break ;
5964 }
6065}
6166
@@ -92,7 +97,7 @@ void WiFiConnectionHandler::update() {
9297 switch (netConnectionState) {
9398 case NetworkConnectionState::INIT: {
9499 debugMessage (DebugLevel::Verbose, " ::INIT" );
95- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
100+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
96101 networkStatus = WiFi.status ();
97102
98103 debugMessage (DebugLevel::Info, " WiFi.status(): %d" , networkStatus);
@@ -111,7 +116,9 @@ void WiFiConnectionHandler::update() {
111116#else
112117 debugMessage (DebugLevel::Error, " WiFi status ESP: %d" , WiFi.status ());
113118 WiFi.disconnect ();
119+ delay (300 );
114120 networkStatus = WiFi.begin (ssid, pass);
121+ delay (1000 );
115122#endif
116123
117124 changeConnectionState (NetworkConnectionState::CONNECTING);
@@ -121,7 +128,7 @@ void WiFiConnectionHandler::update() {
121128 debugMessage (DebugLevel::Verbose, " ::CONNECTING" );
122129 networkStatus = WiFi.status ();
123130
124- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
131+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
125132
126133 if (networkStatus != WL_CONNECTED) {
127134 networkStatus = WiFi.begin (ssid, pass);
@@ -168,7 +175,7 @@ void WiFiConnectionHandler::update() {
168175 }
169176 break ;
170177 case NetworkConnectionState::DISCONNECTED: {
171- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
178+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
172179 WiFi.end ();
173180#endif
174181 if (keepAlive) {
@@ -229,13 +236,16 @@ void WiFiConnectionHandler::changeConnectionState(NetworkConnectionState _newSta
229236 debugMessage (DebugLevel::Verbose, " WiFi.status(): %d" , WiFi.status ());
230237
231238 debugMessage (DebugLevel::Error, " Connection to \" %s\" lost." , ssid);
232- debugMessage (DebugLevel::Error, " Attempting reconnection" );
239+ if (keepAlive){
240+ debugMessage (DebugLevel::Error, " Attempting reconnection" );
241+ }
242+
233243 newInterval = CHECK_INTERVAL_DISCONNECTED;
234244 }
235245 break ;
236246 case NetworkConnectionState::CLOSED: {
237247
238- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
248+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
239249 WiFi.end ();
240250 #endif
241251
0 commit comments