Skip to content

Commit 6f00503

Browse files
committed
add reconnect function for STA
1 parent cee4ef3 commit 6f00503

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
284284
_useStaticIp = true;
285285
}
286286

287+
/**
288+
* will force a disconnect an then start reconnecting to AP
289+
* @return ok
290+
*/
291+
bool ESP8266WiFiClass::reconnect() {
292+
if((getMode() & WIFI_STA) != 0) {
293+
if(wifi_station_disconnect()) {
294+
return wifi_station_connect();
295+
}
296+
}
297+
return false;
298+
}
287299

288300
/**
289301
* Disconnect from the network

libraries/ESP8266WiFi/src/ESP8266WiFi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class ESP8266WiFiClass {
8080
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
8181
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
8282

83+
84+
bool reconnect();
8385
int disconnect(bool wifioff = false);
8486

8587
uint8_t waitForConnectResult();

0 commit comments

Comments
 (0)