Allow setting hostname and auto-led (#75)
Implement automatic Lamp illumination only while camera is active. (#72 thanks @TodWulff ) Allow Hostname setting (#74 thanks @mrmessy ) A couple of small fixes and some unnecessary debug output removed too.
This commit is contained in:
parent
e2dfb773d7
commit
244fbb3593
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ const uint8_t index_simple_html[] = R"=====(<!doctype html>
|
|||
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"=====(<!doctype html>
|
|||
})
|
||||
|
||||
// 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"=====(<!doctype html>
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
<input type="range" id="lamp" min="0" max="100" value="0" class="default-action">
|
||||
<div class="range-max">Full</div>
|
||||
</div>
|
||||
<div class="input-group hidden" id="autolamp-group">
|
||||
<label for="autolamp">Auto Lamp</label>
|
||||
<div class="switch">
|
||||
<input id="autolamp" type="checkbox" class="default-action" title="Lamp only on when camera active">
|
||||
<label class="slider" for="autolamp"></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group" id="framesize-group">
|
||||
<label for="framesize">Resolution</label>
|
||||
<select id="framesize" class="default-action">
|
||||
|
@ -288,6 +296,7 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
const settings = document.getElementById('sidebar')
|
||||
const waitSettings = document.getElementById('wait-settings')
|
||||
const lampGroup = document.getElementById('lamp-group')
|
||||
const autolampGroup = document.getElementById('autolamp-group')
|
||||
const streamGroup = document.getElementById('stream-group')
|
||||
const camName = document.getElementById('cam_name')
|
||||
const codeVer = document.getElementById('code_ver')
|
||||
|
@ -358,8 +367,10 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
} else if(el.id === "lamp"){
|
||||
if (value == -1) {
|
||||
hide(lampGroup)
|
||||
hide(autolampGroup)
|
||||
} else {
|
||||
show(lampGroup)
|
||||
show(autolampGroup)
|
||||
}
|
||||
} else if(el.id === "cam_name"){
|
||||
camName.innerHTML = value;
|
||||
|
@ -375,10 +386,10 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
streamURL = value;
|
||||
viewerURL = value + 'view';
|
||||
stream_url.innerHTML = value;
|
||||
stream_link.setAttribute("title", "Open stream viewer (" + viewerURL + ")");
|
||||
stream_link.setAttribute("title", `Open the standalone stream viewer :: ${viewerURL}`);
|
||||
stream_link.style.textDecoration = "underline";
|
||||
stream_link.style.cursor = "pointer";
|
||||
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
|
||||
streamButton.setAttribute("title", `Start the stream :: ${streamURL}`);
|
||||
show(streamGroup)
|
||||
console.log('Stream URL set to: ' + streamURL);
|
||||
console.log('Stream Viewer URL set to: ' + viewerURL);
|
||||
|
@ -438,12 +449,12 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
})
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -451,7 +462,7 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
<input type="range" id="lamp" min="0" max="100" value="0" class="default-action">
|
||||
<div class="range-max">Full</div>
|
||||
</div>
|
||||
<div class="input-group hidden" id="autolamp-group">
|
||||
<label for="autolamp">Auto Lamp</label>
|
||||
<div class="switch">
|
||||
<input id="autolamp" type="checkbox" class="default-action" title="Lamp only on when camera active">
|
||||
<label class="slider" for="autolamp"></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group" id="framesize-group">
|
||||
<label for="framesize">Resolution</label>
|
||||
<select id="framesize" class="default-action">
|
||||
|
@ -301,6 +309,7 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
const settings = document.getElementById('sidebar')
|
||||
const waitSettings = document.getElementById('wait-settings')
|
||||
const lampGroup = document.getElementById('lamp-group')
|
||||
const autolampGroup = document.getElementById('autolamp-group')
|
||||
const streamGroup = document.getElementById('stream-group')
|
||||
const camName = document.getElementById('cam_name')
|
||||
const codeVer = document.getElementById('code_ver')
|
||||
|
@ -369,8 +378,10 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
} else if(el.id === "lamp"){
|
||||
if (value == -1) {
|
||||
hide(lampGroup)
|
||||
hide(autolampGroup)
|
||||
} else {
|
||||
show(lampGroup)
|
||||
show(autolampGroup)
|
||||
}
|
||||
} else if(el.id === "cam_name"){
|
||||
camName.innerHTML = value;
|
||||
|
@ -386,10 +397,10 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
streamURL = value;
|
||||
viewerURL = value + 'view';
|
||||
stream_url.innerHTML = value;
|
||||
stream_link.setAttribute("title", "Open stream viewer (" + viewerURL + ")");
|
||||
stream_link.setAttribute("title", `Open the standalone stream viewer :: ${viewerURL}`);
|
||||
stream_link.style.textDecoration = "underline";
|
||||
stream_link.style.cursor = "pointer";
|
||||
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
|
||||
streamButton.setAttribute("title", `Start the stream :: ${streamURL}`);
|
||||
show(streamGroup)
|
||||
console.log('Stream URL set to: ' + streamURL);
|
||||
console.log('Stream Viewer URL set to: ' + viewerURL);
|
||||
|
@ -449,12 +460,12 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
})
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -462,7 +473,7 @@ const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/* Version of upstream code */
|
||||
|
||||
char baseVersion[] = "3.0-RC1";
|
||||
char baseVersion[] = "3.0-RC2";
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
extern void flashLED(int flashtime);
|
||||
extern int myRotation; // Rotation
|
||||
extern int lampVal; // The current Lamp value
|
||||
extern int autoLamp; // Automatic lamp mode
|
||||
extern int8_t detection_enabled; // Face detection enable
|
||||
extern int8_t recognition_enabled; // Face recognition enable
|
||||
|
||||
|
@ -76,6 +77,7 @@ void loadPrefs(fs::FS &fs){
|
|||
sensor_t * s = esp_camera_sensor_get();
|
||||
// process all the settings
|
||||
lampVal = jsonExtract(prefs, "lamp").toInt();
|
||||
autoLamp = jsonExtract(prefs, "autolamp").toInt();
|
||||
s->set_framesize(s, (framesize_t)jsonExtract(prefs, "framesize").toInt());
|
||||
s->set_quality(s, jsonExtract(prefs, "quality").toInt());
|
||||
s->set_brightness(s, jsonExtract(prefs, "brightness").toInt());
|
||||
|
@ -123,6 +125,7 @@ void savePrefs(fs::FS &fs){
|
|||
char * p = json_response;
|
||||
*p++ = '{';
|
||||
p+=sprintf(p, "\"lamp\":%i,", lampVal);
|
||||
p+=sprintf(p, "\"autolamp\":%u,", 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);
|
||||
|
|
Loading…
Reference in New Issue