diff --git a/app_httpd.cpp b/app_httpd.cpp index 2606172..a268e1b 100644 --- a/app_httpd.cpp +++ b/app_httpd.cpp @@ -49,6 +49,8 @@ extern char httpURL[]; extern char streamURL[]; extern char default_index[]; extern int8_t streamCount; +extern unsigned long streamsServed; +extern unsigned long imagesServed; extern int myRotation; extern int lampVal; extern bool autoLamp; @@ -61,11 +63,6 @@ extern int sketchSize; extern int sketchSpace; extern String sketchMD5; -// Counters for connection and client debug/info -uint8_t connectedClients = 0; -unsigned long streamsServed = 0; -unsigned long imagesServed = 0; - #include "fb_gfx.h" #include "fd_forward.h" @@ -253,15 +250,12 @@ static int run_face_recognition(dl_matrix3du_t *image_matrix, box_array_t *net_b } void serialDump() { - Serial.println("\nSerial Dump."); - Serial.println("Preferences file: "); + Serial.println("\nPreferences file: "); dumpPrefs(SPIFFS); if (critERR.length() > 0) { Serial.printf("\n\nA critical error has occurred when initialising Camera Hardware, see startup megssages\n"); - Serial.printf("%s\n\n", critERR.c_str()); } // Module - Serial.println("Module:"); Serial.printf("Name: %s\n", myName); Serial.printf("Firmware: %s (base: %s)\n", myVer, baseVersion); float sketchPct = 100 * sketchSize / sketchSpace; @@ -269,41 +263,38 @@ void serialDump() { Serial.printf("MD5: %s\n", sketchMD5.c_str()); Serial.printf("ESP sdk: %s\n", ESP.getSdkVersion()); // Network - Serial.println("WiFi:"); if (accesspoint) { if (captivePortal) { - Serial.printf("Mode: AccessPoint with captive portal\n"); + Serial.printf("WiFi Mode: AccessPoint with captive portal\n"); } else { - Serial.printf("Mode: AccessPoint\n"); + Serial.printf("WiFi Mode: AccessPoint\n"); } - Serial.printf("SSID: %s\n", apName); + Serial.printf("WiFi SSID: %s\n", apName); } else { - Serial.printf("Mode: Client\n"); + Serial.printf("WiFi Mode: Client\n"); String ssidName = WiFi.SSID(); - Serial.printf("Ssid: %s\n", ssidName.c_str()); - Serial.printf("Rssi: %i\n", WiFi.RSSI()); + Serial.printf("WiFi Ssid: %s\n", ssidName.c_str()); + Serial.printf("WiFi Rssi: %i\n", WiFi.RSSI()); String bssid = WiFi.BSSIDstr(); - Serial.printf("BSSID: %s\n", bssid.c_str()); + Serial.printf("WiFi BSSID: %s\n", bssid.c_str()); } - Serial.printf("IP address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); + Serial.printf("WiFi IP address: %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); if (!accesspoint) { - Serial.printf("Netmask: %d.%d.%d.%d\n", net[0], net[1], net[2], net[3]); - Serial.printf("Gateway: %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]); + Serial.printf("WiFi Netmask: %d.%d.%d.%d\n", net[0], net[1], net[2], net[3]); + Serial.printf("WiFi Gateway: %d.%d.%d.%d\n", gw[0], gw[1], gw[2], gw[3]); } - Serial.printf("Http port: %i, Stream port: %i\n", httpPort, streamPort); + Serial.printf("WiFi Http port: %i, Stream port: %i\n", httpPort, streamPort); byte mac[6]; WiFi.macAddress(mac); - Serial.printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - + Serial.printf("WiFi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); // System - Serial.println("System:"); int64_t sec = esp_timer_get_time() / 1000000; int64_t upDays = int64_t(floor(sec/86400)); int upHours = int64_t(floor(sec/3600)) % 24; int upMin = int64_t(floor(sec/60)) % 60; int upSec = sec % 60; - Serial.printf("Up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)\n", upDays, upHours, upMin, upSec); - Serial.printf("Active connections: %i, Total streams served: %lu, Total image captures: %lu\n", connectedClients, streamsServed, imagesServed); + Serial.printf("System up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)\n", upDays, upHours, upMin, upSec); + Serial.printf("Active streams: %i, Previous streams: %lu, Images captured: %lu\n", streamCount, streamsServed, imagesServed); Serial.printf("Freq: %i MHz\n", ESP.getCpuFreqMHz()); Serial.printf("Heap: %i, free: %i, min free: %i, max block: %i\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap()); Serial.printf("Psram: %i, free: %i, min free: %i, max block: %i\n", ESP.getPsramSize(), ESP.getFreePsram(), ESP.getMinFreePsram(), ESP.getMaxAllocPsram()); @@ -311,7 +302,7 @@ void serialDump() { Serial.printf("Spiffs: %i, used: %i\n", SPIFFS.totalBytes(), SPIFFS.usedBytes()); } Serial.printf("Enrolled faces: %i (max %i)\n", id_list.count, id_list.size); - + Serial.println(); return; } @@ -370,6 +361,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ if (debugData) { Serial.printf("JPG: %uB %ums\n", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start)/1000)); } + imagesServed++; if (autoLamp && (lampVal != -1)) setLamp(0); return res; } @@ -448,7 +440,7 @@ static esp_err_t stream_handler(httpd_req_t *req){ Serial.println("Stream requested"); if (autoLamp && (lampVal != -1)) setLamp(lampVal); - streamCount = 1; // at present we only have one stream handler.. + streamCount = 1; // at present we only have one stream handler, so values are 0 or 1.. flashLED(75); // double flash of status LED delay(75); flashLED(75); @@ -460,14 +452,13 @@ static esp_err_t stream_handler(httpd_req_t *req){ res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); if(res != ESP_OK){ + streamCount = 0; if (autoLamp && (lampVal != -1)) setLamp(0); return res; } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - connectedClients = 1; - while(true){ detected = false; face_id = 0; @@ -481,6 +472,7 @@ static esp_err_t stream_handler(httpd_req_t *req){ fr_face = fr_start; fr_encode = fr_start; fr_recognize = fr_start; + if(!detection_enabled || fb->width > 400){ if(fb->format != PIXFORMAT_JPEG){ bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len); @@ -585,11 +577,9 @@ static esp_err_t stream_handler(httpd_req_t *req){ } } - connectedClients = 0; streamsServed++; - + streamCount = 0; if (autoLamp && (lampVal != -1)) setLamp(0); - streamCount = 0; // at present we only have one stream handler.. Serial.println("Stream ended"); last_frame = 0; return res; @@ -872,7 +862,7 @@ static esp_err_t dump_handler(httpd_req_t *req){ int upMin = int64_t(floor(sec/60)) % 60; int upSec = sec % 60; d+= sprintf(d,"Up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)
\n", upDays, upHours, upMin, upSec); - d+= sprintf(d,"Active connections: %i, Total streams served: %lu, Total image captures: %lu
\n", connectedClients, streamsServed, imagesServed); + d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Image captured: %lu
\n", streamCount, streamsServed, imagesServed); d+= sprintf(d,"Freq: %i MHz
\n", ESP.getCpuFreqMHz()); d+= sprintf(d,"Heap: %i, free: %i, min free: %i, max block: %i
\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap()); d+= sprintf(d,"Psram: %i, free: %i, min free: %i, max block: %i
\n", ESP.getPsramSize(), ESP.getFreePsram(), ESP.getMinFreePsram(), ESP.getMaxAllocPsram()); diff --git a/esp32-cam-webserver.ino b/esp32-cam-webserver.ino index 8b1fd7a..f5acd58 100644 --- a/esp32-cam-webserver.ino +++ b/esp32-cam-webserver.ino @@ -70,6 +70,7 @@ IPAddress gw; // Declare external function from app_httpd.cpp extern void startCameraServer(int hPort, int sPort); +extern void serialDump(); // A Name for the Camera. (set in myconfig.h) #if defined(CAM_NAME) @@ -122,8 +123,10 @@ char apName[64] = "Undefined"; char httpURL[64] = {"Undefined"}; char streamURL[64] = {"Undefined"}; -// Count number of active streams -int8_t streamCount = 0; +// Counters for info screens and debug +int8_t streamCount = 0; // Number of currently active streams +unsigned long streamsServed = 0; // Total completed streams +unsigned long imagesServed = 0; // Total image requests // This will be displayed to identify the firmware char myVer[] PROGMEM = __DATE__ " @ " __TIME__; @@ -598,8 +601,8 @@ void setup() { Serial.printf("\nCamera Ready!\nUse '%s' to connect\n", httpURL); Serial.printf("Stream viewer available at '%sview'\n", streamURL); Serial.printf("Raw stream URL is '%s'\n", streamURL); - if (debugData) Serial.println("Camera debug data is enabled (send any char to disable)"); - else Serial.println("Camera debug data is disabled (send any char to enable)"); + if (debugData) Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)"); + else Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)"); } else { Serial.printf("\nCamera unavailable due to initialisation errors.\n\n"); } @@ -638,13 +641,17 @@ void loop() { while (millis() - start < WIFI_WATCHDOG ) { delay(100); if (Serial.available()) { - // Toggle debug output on serial input - if (debugData) { - debugData = false; - Serial.println("Camera debug data is disabled (send any char to enable)"); + if (Serial.read() == 'd' ) { + serialDump(); } else { - debugData = true; - Serial.println("Camera debug data is enabled (send any char to disable)"); + // Toggle debug output on serial input + if (debugData) { + debugData = false; + Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)"); + } else { + debugData = true; + Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)"); + } } } while (Serial.available()) Serial.read(); // chomp the buffer