diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-09-16 23:04:17 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-09-16 23:04:17 +0300 |
commit | 79c59138977ec4abd804e52217a4f6e5d307c65f (patch) | |
tree | dd358e839864a7a0b37306a3487314bdc5316889 /esp32-cam | |
parent | 9a736d13bf7a3f2792bfe6b4ca996cf050bbdd49 (diff) |
esp32-cam: try reconnecting to wifi when connection is lost...
Diffstat (limited to 'esp32-cam')
-rw-r--r-- | esp32-cam/CameraWebServer/CameraWebServer.ino | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/esp32-cam/CameraWebServer/CameraWebServer.ino b/esp32-cam/CameraWebServer/CameraWebServer.ino index bc95f76..ef589d9 100644 --- a/esp32-cam/CameraWebServer/CameraWebServer.ino +++ b/esp32-cam/CameraWebServer/CameraWebServer.ino @@ -35,11 +35,22 @@ // =========================== #include "wifi_password.h" +volatile float disconnected_since = 0; + void startCameraServer(); +void onWiFiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) { + disconnected_since = millis(); + WiFi.reconnect(); +} + +void onWiFiConnect(WiFiEvent_t event, WiFiEventInfo_t info) { + disconnected_since = 0; +} + void setup() { Serial.begin(115200); - Serial.setDebugOutput(true); + //Serial.setDebugOutput(true); Serial.println(); camera_config_t config; @@ -123,6 +134,9 @@ void setup() { s->set_vflip(s, 1); #endif + WiFi.onEvent(onWiFiDisconnect, ARDUINO_EVENT_WIFI_STA_DISCONNECTED); + WiFi.onEvent(onWiFiConnect, ARDUINO_EVENT_WIFI_STA_CONNECTED); + WiFi.begin(ssid, password); WiFi.setSleep(false); @@ -141,6 +155,11 @@ void setup() { } void loop() { + if (disconnected_since != 0 && (millis() - disconnected_since) > 60000) { + ESP.restart(); + return; + } + // Do nothing. Everything is done in another task by the web server delay(10000); } |