Skip to content

Commit 8228709

Browse files
Update CameraWebServer.ino
Updated the loop function of CameraWebServer example. Currently this software will not try to re-connect to the network if it lost once. There may be a lot of reasons - wifi router lost electricity, some noise in the radio space and much more. Now, the loop function will check for the connection, it is lost - will try to re-connect. Once re-conencted, will run the web server again.
1 parent 337058a commit 8228709

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)