@@ -51,11 +51,16 @@ WiFiConnectionHandler::WiFiConnectionHandler(const char *_ssid, const char *_pas
51
51
void WiFiConnectionHandler::init () {
52
52
}
53
53
54
+ // INIT, CONNECTING, CONNECTED, DISCONNECTING, DISCONNECTED, CLOSED, ERROR
54
55
void WiFiConnectionHandler::addCallback (NetworkConnectionEvent const event, OnNetworkEventCallback callback){
55
56
switch (event) {
56
57
case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break ;
57
58
case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break ;
58
59
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 ;
59
64
}
60
65
}
61
66
@@ -92,7 +97,7 @@ void WiFiConnectionHandler::update() {
92
97
switch (netConnectionState) {
93
98
case NetworkConnectionState::INIT: {
94
99
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)
96
101
networkStatus = WiFi.status ();
97
102
98
103
debugMessage (DebugLevel::Info, " WiFi.status(): %d" , networkStatus);
@@ -111,7 +116,9 @@ void WiFiConnectionHandler::update() {
111
116
#else
112
117
debugMessage (DebugLevel::Error, " WiFi status ESP: %d" , WiFi.status ());
113
118
WiFi.disconnect ();
119
+ delay (300 );
114
120
networkStatus = WiFi.begin (ssid, pass);
121
+ delay (1000 );
115
122
#endif
116
123
117
124
changeConnectionState (NetworkConnectionState::CONNECTING);
@@ -121,7 +128,7 @@ void WiFiConnectionHandler::update() {
121
128
debugMessage (DebugLevel::Verbose, " ::CONNECTING" );
122
129
networkStatus = WiFi.status ();
123
130
124
- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
131
+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
125
132
126
133
if (networkStatus != WL_CONNECTED) {
127
134
networkStatus = WiFi.begin (ssid, pass);
@@ -168,7 +175,7 @@ void WiFiConnectionHandler::update() {
168
175
}
169
176
break ;
170
177
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)
172
179
WiFi.end ();
173
180
#endif
174
181
if (keepAlive) {
@@ -229,13 +236,16 @@ void WiFiConnectionHandler::changeConnectionState(NetworkConnectionState _newSta
229
236
debugMessage (DebugLevel::Verbose, " WiFi.status(): %d" , WiFi.status ());
230
237
231
238
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
+
233
243
newInterval = CHECK_INTERVAL_DISCONNECTED;
234
244
}
235
245
break ;
236
246
case NetworkConnectionState::CLOSED: {
237
247
238
- #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
248
+ #if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
239
249
WiFi.end ();
240
250
#endif
241
251
0 commit comments