Created
November 26, 2024 09:40
-
-
Save aliraza1944/a203ec418aa8fd0880b8973c72b905ee to your computer and use it in GitHub Desktop.
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 wifiReconnectionTask(void *pvParameters) | |
| { | |
| while (1){ | |
| if (wifiDisconnected){ | |
| Serial.println("Reconnecting to WiFi..."); | |
| WiFi.disconnect(false, false); // Same as WiFi.Discon | |
| int retryCount = 0; | |
| while (WiFi.status() != WL_CONNECTED && retryCount < 4) { | |
| Serial.print("Attempting to reconnect, try "); | |
| Serial.println(retryCount + 1); | |
| WiFi.begin(ssid, pass); | |
| delay(2000); // Delay for 2 seconds between retr | |
| retryCount++; | |
| } | |
| if (WiFi.status() == WL_CONNECTED) | |
| { | |
| Serial.println("Reconnected to WiFi successfully"); | |
| wifiDisconnected = false; | |
| } else { | |
| Serial.println("Failed to reconnect to WiFi after 4 attempts."); | |
| Serial.println("Retry count exceeded. Restarting the device..."); | |
| wifiDisconnected = true; | |
| esp.restart(); //check the arduino restart function. | |
| } | |
| // Add a delay to avoid flooding the serial output | |
| delay(1000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment