diff options
-rw-r--r-- | esp32-cam/CameraWebServer/CameraWebServer.ino | 21 | ||||
-rw-r--r-- | esp32-cam/CameraWebServer/app_httpd.cpp | 16 |
2 files changed, 36 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); } diff --git a/esp32-cam/CameraWebServer/app_httpd.cpp b/esp32-cam/CameraWebServer/app_httpd.cpp index 16fd7d0..b0b456c 100644 --- a/esp32-cam/CameraWebServer/app_httpd.cpp +++ b/esp32-cam/CameraWebServer/app_httpd.cpp @@ -1147,6 +1147,15 @@ static esp_err_t win_handler(httpd_req_t *req) return httpd_resp_send(req, NULL, 0); } +static esp_err_t uptime_handler(httpd_req_t *req) +{ + char buf[64]; + sprintf(buf, "{\"millis\":%d}", (int)millis()); + httpd_resp_set_type(req, "application/json"); + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + return httpd_resp_send(req, buf, strlen(buf)); +} + static esp_err_t index_handler(httpd_req_t *req) { httpd_resp_set_type(req, "text/html"); @@ -1237,6 +1246,12 @@ void startCameraServer() .handler = win_handler, .user_ctx = NULL}; + httpd_uri_t uptime_uri = { + .uri = "/uptime", + .method = HTTP_GET, + .handler = uptime_handler, + .user_ctx = NULL}; + ra_filter_init(&ra_filter, 20); #if CONFIG_ESP_FACE_RECOGNITION_ENABLED @@ -1259,6 +1274,7 @@ void startCameraServer() httpd_register_uri_handler(camera_httpd, &greg_uri); httpd_register_uri_handler(camera_httpd, &pll_uri); httpd_register_uri_handler(camera_httpd, &win_uri); + httpd_register_uri_handler(camera_httpd, &uptime_uri); } config.server_port += 1; |