Created
September 5, 2020 18:36
-
-
Save anecdata/a6cd2ed6693760bcf4166943cad939cf to your computer and use it in GitHub Desktop.
Arduino ESP32 Wi-Fi Connect function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void customWiFiConnect(ssid, pass) { | |
int WiFiStatusNum; | |
unsigned long start; | |
WiFiStatusNum = getWiFiStatus(); | |
if ( WiFiStatusNum != WL_CONNECTED ) { | |
Serial.println("Restarting WiFi..."); | |
WiFi.begin(ssid, pass); | |
start = millis(); | |
while ( WiFiStatusNum != WL_CONNECTED ) { | |
if (millis() - start > 300000) { // 5 min | |
Serial.println("Restarting ESP..."); | |
ESP.restart(); | |
} | |
else if (millis() - start > 60000) { // 1 min | |
Serial.println("Restarting WiFi..."); | |
WiFi.begin(ssid, pass); | |
} | |
WiFiStatusNum = getWiFiStatus(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fix void; add getWiFiStatus()