diff --git a/app_httpd.cpp b/app_httpd.cpp index e363d34..fb126f3 100644 --- a/app_httpd.cpp +++ b/app_httpd.cpp @@ -45,8 +45,10 @@ extern int streamPort; extern char httpURL[]; extern char streamURL[]; extern char default_index[]; +extern int8_t streamCount; extern int myRotation; extern int lampVal; +extern bool autoLamp; extern int8_t detection_enabled; extern int8_t recognition_enabled; extern bool filesystem; @@ -257,7 +259,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ esp_err_t res = ESP_OK; Serial.println("Capture Requested"); - + if (autoLamp && (lampVal != -1)) setLamp(lampVal); flashLED(75); // little flash of status LED int64_t fr_start = esp_timer_get_time(); @@ -266,6 +268,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ if (!fb) { Serial.println("Camera capture failed"); httpd_resp_send_500(req); + if (autoLamp && (lampVal != -1)) setLamp(0); return ESP_FAIL; } @@ -291,7 +294,10 @@ static esp_err_t capture_handler(httpd_req_t *req){ } esp_camera_fb_return(fb); int64_t fr_end = esp_timer_get_time(); - Serial.printf("JPG: %uB %ums\n", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start)/1000)); + if (debugData) { + Serial.printf("JPG: %uB %ums\n", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start)/1000)); + } + if (autoLamp && (lampVal != -1)) setLamp(0); return res; } @@ -300,6 +306,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ esp_camera_fb_return(fb); Serial.println("dl_matrix3du_alloc failed"); httpd_resp_send_500(req); + if (autoLamp && (lampVal != -1)) setLamp(0); return ESP_FAIL; } @@ -314,6 +321,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ dl_matrix3du_free(image_matrix); Serial.println("to rgb888 failed"); httpd_resp_send_500(req); + if (autoLamp && (lampVal != -1)) setLamp(0); return ESP_FAIL; } @@ -336,6 +344,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ dl_matrix3du_free(image_matrix); if(!s){ Serial.println("JPEG compression failed"); + if (autoLamp && (lampVal != -1)) setLamp(0); return ESP_FAIL; } @@ -343,6 +352,7 @@ static esp_err_t capture_handler(httpd_req_t *req){ if (debugData) { Serial.printf("FACE: %uB %ums %s%d\n", (uint32_t)(jchunk.len), (uint32_t)((fr_end - fr_start)/1000), detected?"DETECTED ":"", face_id); } + if (autoLamp && (lampVal != -1)) setLamp(0); return res; } @@ -361,10 +371,10 @@ static esp_err_t stream_handler(httpd_req_t *req){ int64_t fr_encode = 0; int64_t fr_ready = 0; - Serial.println("Stream requested"); - - flashLED(75); // double flash of status LED + if (autoLamp && (lampVal != -1)) setLamp(lampVal); + streamCount = 1; // at present we only have one stream handler.. + flashLED(75); // double flash of status LED delay(75); flashLED(75); @@ -375,6 +385,7 @@ static esp_err_t stream_handler(httpd_req_t *req){ res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE); if(res != ESP_OK){ + if (autoLamp && (lampVal != -1)) setLamp(0); return res; } @@ -497,6 +508,9 @@ static esp_err_t stream_handler(httpd_req_t *req){ } } + 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; } @@ -577,9 +591,23 @@ static esp_err_t cmd_handler(httpd_req_t *req){ detection_enabled = val; } } + else if(!strcmp(variable, "autolamp") && (lampVal != -1)) { + autoLamp = val; + if (autoLamp) { + if (streamCount > 0) setLamp(lampVal); + else setLamp(0); + } else { + setLamp(lampVal); + } + } else if(!strcmp(variable, "lamp") && (lampVal != -1)) { lampVal = constrain(val,0,100); - setLamp(lampVal); + if (autoLamp) { + if (streamCount > 0) setLamp(lampVal); + else setLamp(0); + } else { + setLamp(lampVal); + } } else if(!strcmp(variable, "save_face")) { if (filesystem) saveFaceDB(SPIFFS); @@ -619,6 +647,7 @@ static esp_err_t status_handler(httpd_req_t *req){ char * p = json_response; *p++ = '{'; p+=sprintf(p, "\"lamp\":%d,", lampVal); + p+=sprintf(p, "\"autolamp\":%d,", autoLamp); p+=sprintf(p, "\"framesize\":%u,", s->status.framesize); p+=sprintf(p, "\"quality\":%u,", s->status.quality); p+=sprintf(p, "\"brightness\":%d,", s->status.brightness); @@ -987,10 +1016,6 @@ void startCameraServer(int hPort, int sPort){ // Face ID list (settings + pointer to the data allocation) face_id_init(&id_list, FACE_ID_SAVE_NUMBER, ENROLL_CONFIRM_TIMES); // The size of the allocated data block; calculated in dl_lib_calloc() - id_list_alloc = FACE_ID_SAVE_NUMBER * sizeof(dl_matrix3d_t *) + sizeof(void *); - Serial.print("FACE DB SIZE: "); - Serial.println(id_list_alloc); - Serial.printf("FACE DB POINTER: %p\n", id_list.id_list); config.server_port = hPort; config.ctrl_port = hPort; diff --git a/esp32-cam-webserver.ino b/esp32-cam-webserver.ino index fc98f93..61a2cec 100644 --- a/esp32-cam-webserver.ino +++ b/esp32-cam-webserver.ino @@ -106,7 +106,6 @@ int stationCount = sizeof(stationList)/sizeof(stationList[0]); #else char default_index[] = "simple"; #endif - // DNS server const byte DNS_PORT = 53; @@ -118,6 +117,9 @@ char apName[64] = "Undefined"; char httpURL[64] = {"Undefined"}; char streamURL[64] = {"Undefined"}; +// Count number of active streams +int8_t streamCount = 0; + // This will be displayed to identify the firmware char myVer[] PROGMEM = __DATE__ " @ " __TIME__; @@ -140,6 +142,7 @@ int myRotation = CAM_ROTATION; #else int lampVal = -1; // no lamp pin assigned #endif +bool autoLamp = false; // Automatic lamp (auto on while camera running) int lampChannel = 7; // a free PWM channel (some channels used by camera) const int pwmfreq = 50000; // 50K pwm frequency @@ -281,9 +284,14 @@ void WifiSetup() { Serial.println("Static IP settings requested but not defined in config, falling back to dhcp"); #endif } + + #if defined(HOSTNAME) + WiFi.setHostname(HOSTNAME); + #endif + // Initiate network connection request WiFi.begin(stationList[bestStation].ssid, stationList[bestStation].password); - + // Wait to connect, or timeout unsigned long start = millis(); while ((millis() - start <= WIFI_WATCHDOG) && (WiFi.status() != WL_CONNECTED)) { @@ -377,7 +385,7 @@ void setup() { Serial.println("No wifi ssid details have been configured; we cannot connect to WiFi or start our own AccessPoint"); while (true) delay(1000); } - + #if defined(LED_PIN) // If we have a notification LED, set it to output pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LED_ON); @@ -515,14 +523,15 @@ void setup() { Serial.println("No Internal Filesystem, cannot save preferences or face DB"); } - /* + /* * Camera setup complete; initialise the rest of the hardware. */ // Initialise and set the lamp if (lampVal != -1) { ledcSetup(lampChannel, pwmfreq, pwmresolution); // configure LED PWM channel - setLamp(lampVal); // set default value + if (autoLamp) setLamp(0); // set default value + else setLamp(lampVal); ledcAttachPin(LAMP_PIN, lampChannel); // attach the GPIO pin to the channel } else { Serial.println("No lamp, or lamp disabled in config"); @@ -536,16 +545,23 @@ void setup() { // Now we have a network we can start the two http handlers for the UI and Stream. startCameraServer(httpPort, streamPort); - - // Construct the app and stream URLs - if (httpPort != 80) { - sprintf(httpURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], httpPort); - } else { - sprintf(httpURL, "http://%d.%d.%d.%d/", ip[0], ip[1], ip[2], ip[3]); - } + + #if defined(URL_HOSTNAME) + if (httpPort != 80) { + sprintf(httpURL, "http://%s:%d/", URL_HOSTNAME, httpPort); + } else { + sprintf(httpURL, "http://%s/", URL_HOSTNAME); + } + sprintf(streamURL, "http://%s:%d/", URL_HOSTNAME, streamPort); + #else + if (httpPort != 80) { + sprintf(httpURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], httpPort); + } else { + sprintf(httpURL, "http://%d.%d.%d.%d/", ip[0], ip[1], ip[2], ip[3]); + } + sprintf(streamURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], streamPort); + #endif Serial.printf("\nCamera Ready!\nUse '%s' to connect\n", httpURL); - // Construct the Stream URL - sprintf(streamURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], streamPort); Serial.printf("Stream viewer available at '%sview'\n", streamURL); Serial.printf("Raw stream URL is '%s'\n", streamURL); diff --git a/index_other.h b/index_other.h index cff87bd..341c48a 100644 --- a/index_other.h +++ b/index_other.h @@ -132,7 +132,7 @@ const uint8_t index_simple_html[] = R"=====( applyRotation(); } else if(el.id === "stream_url"){ streamURL = value; - streamButton.setAttribute("title", `Start the stream (${streamURL})`); + streamButton.setAttribute("title", `Start the stream :: {streamURL}`); console.log('Stream URL set to:' + value); } } @@ -190,12 +190,12 @@ const uint8_t index_simple_html[] = R"=====( }) // Put some helpful text on the 'Still' button - stillButton.setAttribute("title", `Capture a still image (${baseHost}/capture)`); + stillButton.setAttribute("title", `Capture a still image :: ${baseHost}/capture`); const stopStream = () => { window.stop(); streamButton.innerHTML = 'Start Stream'; - streamButton.setAttribute("title", `Start the stream (${streamURL})`); + streamButton.setAttribute("title", `Start the stream :: ${streamURL}`); hide(viewContainer); } @@ -203,7 +203,7 @@ const uint8_t index_simple_html[] = R"=====( view.src = streamURL; view.scrollIntoView(false); streamButton.innerHTML = 'Stop Stream'; - streamButton.setAttribute("title", `Stop the stream (${streamURL})`); + streamButton.setAttribute("title", `Stop the stream`); show(viewContainer); } diff --git a/index_ov2640.h b/index_ov2640.h index 6008f03..9d75f31 100644 --- a/index_ov2640.h +++ b/index_ov2640.h @@ -41,6 +41,14 @@ const uint8_t index_ov2640_html[] = R"=====(
Full
+ +
Full
+ +