Skip to content

Commit e629ab0

Browse files
feat(esp32): Reconnect to the network after connection loss
1 parent 337058a commit e629ab0

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino

+22-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
const char *ssid = "**********";
4040
const char *password = "**********";
4141

42+
bool tryingToConnectWifi = true;
43+
4244
void startCameraServer();
4345
void setupLedFlash(int pin);
4446

@@ -151,6 +153,24 @@ void setup() {
151153
}
152154

153155
void loop() {
154-
// Do nothing. Everything is done in another task by the web server
155-
delay(10000);
156+
if (WiFi.status() != WL_CONNECTED) {
157+
if (!tryingToConnectWifi) {
158+
WiFi.begin(ssid, password);
159+
WiFi.setSleep(false);
160+
tryingToConnectWifi = true;
161+
}
162+
163+
Serial.println("Wifi not connected, trying to re-connect");
164+
delay(500);
165+
} else if (WiFi.status() == WL_CONNECTED) {
166+
if (tryingToConnectWifi) {
167+
startCameraServer();
168+
Serial.print("Camera Ready! Use 'http://");
169+
Serial.print(WiFi.localIP());
170+
Serial.println("' to connect");
171+
tryingToConnectWifi = false;
172+
}
173+
}
174+
175+
delay(2000);
156176
}

0 commit comments

Comments
 (0)