Skip to content

Commit

Permalink
A whole bunch of tweaks and little fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
easytarget committed Oct 7, 2020
1 parent 6d5ae2e commit 7d29e36
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 78 deletions.
9 changes: 3 additions & 6 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern int httpPort;
extern int streamPort;
extern char httpURL[];
extern char streamURL[];
extern char default_index[];
extern int myRotation;
extern int lampVal;
extern int8_t detection_enabled;
Expand Down Expand Up @@ -850,12 +851,8 @@ static esp_err_t index_handler(httpd_req_t *req){
free(buf);
} else {
// no target specified; default.
#if defined(DEFAULT_INDEX_FULL)
strcpy(view,"full");
#else
strcpy(view,"simple");
#endif
// If a captive portal page is created, we can use it here
strcpy(view,default_index);
// If captive portal is active send that instead
if (captivePortal) {
strcpy(view,"portal");
}
Expand Down
132 changes: 76 additions & 56 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ int stationCount = sizeof(stationList)/sizeof(stationList[0]);
int firstStation = 0;
#endif

// Select bvetween full and simple index as the default.
#if defined(DEFAULT_INDEX_FULL)
char default_index[] = "full";
#else
char default_index[] = "simple";
#endif


// DNS server
const byte DNS_PORT = 53;
DNSServer dnsServer;
Expand Down Expand Up @@ -182,20 +190,32 @@ void WifiSetup() {
flashLED(300);
delay(100);
flashLED(300);

Serial.println("Starting WiFi");
Serial.print("Known external SSIDs: ");
if (stationCount > firstStation) {
for (int i=firstStation; i < stationCount; i++) Serial.printf(" '%s'", stationList[i].ssid);
} else {
Serial.print("None");
}
Serial.println();
byte mac[6];
WiFi.macAddress(mac);
Serial.printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

int bestStation = -1;
long bestRSSI = -1024;
Serial.printf("Scanning local Wifi Networks\n");
int stationsFound = WiFi.scanNetworks();
Serial.printf("%i networks found\n", stationsFound);
if (stationsFound > 0) {
for (int i = 0; i < stationsFound; ++i) {
// Print SSID and RSSI for each network found
String thisSSID = WiFi.SSID(i);
int thisRSSI = WiFi.RSSI(i);
Serial.printf("%3i : %s (%i)", i + 1, thisSSID.c_str(), thisRSSI);
// Scan our list of known external stations, if any
if (stationCount > firstStation) {
long bestRSSI = -1024;
if (stationCount > firstStation) {
// We have a list to scan
Serial.printf("Scanning local Wifi Networks\n");
int stationsFound = WiFi.scanNetworks();
Serial.printf("%i networks found\n", stationsFound);
if (stationsFound > 0) {
for (int i = 0; i < stationsFound; ++i) {
// Print SSID and RSSI for each network found
String thisSSID = WiFi.SSID(i);
int thisRSSI = WiFi.RSSI(i);
Serial.printf("%3i : %s (%i)", i + 1, thisSSID.c_str(), thisRSSI);
// Scan our list of known external stations
for (int sta = firstStation; sta < stationCount; sta++) {
if (strcmp(stationList[sta].ssid, thisSSID.c_str()) == 0) {
Serial.print(" - Known!");
Expand All @@ -206,16 +226,25 @@ void WifiSetup() {
}
}
}
Serial.println();
}
Serial.println();
}
} else {
// No list to scan, therefore we are an accesspoint
accesspoint = true;
}

if (bestStation == -1) {
Serial.println("\nNo known networks found");
#if defined(WIFI_AP_ENABLE)
// Failover to accesspoint mode if no known networks are visible
accesspoint = true;
#endif
if (!accesspoint) {
#if defined(WIFI_AP_ENABLE)
Serial.println("No known networks found, entering AccessPoint fallback mode");
accesspoint = true;
#else
Serial.println("No known networks found");
#endif
} else {
Serial.println("AccessPoint mode selected in config");
}
} else {
Serial.printf("Connecting to Wifi Network: %s\n", stationList[bestStation].ssid);
if (stationList[bestStation].dhcp == false) {
Expand Down Expand Up @@ -272,8 +301,9 @@ void WifiSetup() {
WiFi.disconnect(); // (resets the WiFi scan)
}
}

if (accesspoint && (WiFi.status() != WL_CONNECTED)) {
// The accesspoint has been enabled
// The accesspoint has been enabled, and we have not connected to any existing networks
#if defined(AP_CHAN)
Serial.println("Setting up Fixed Channel AccessPoint");
Serial.print(" SSID : ");
Expand Down Expand Up @@ -432,32 +462,35 @@ void setup() {
/*
* Add any other defaults you want to apply at startup here:
* uncomment the line and set the value as desired (see the comments)
*
* these are defined in the esp headers here:
* https://github.com/espressif/esp32-camera/blob/master/driver/include/sensor.h#L149
*/

//s->set_framesize(s, FRAMESIZE_SVGA); // FRAMESIZE_[QQVGA|HQVGA|QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA|QXGA(ov3660)]);
//s->set_quality(s, val); // 10 to 63
//s->set_brightness(s, 0); // -2 to 2
//s->set_contrast(s, 0); // -2 to 2
//s->set_saturation(s, 0); // -2 to 2
//s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
//s->set_whitebal(s, 1); // 0 = disable , 1 = enable
//s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
//s->set_wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
//s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
//s->set_aec2(s, 0); // 0 = disable , 1 = enable
//s->set_ae_level(s, 0); // -2 to 2
//s->set_aec_value(s, 300); // 0 to 1200
//s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
//s->set_agc_gain(s, 0); // 0 to 30
//s->set_quality(s, val); // 10 to 63
//s->set_brightness(s, 0); // -2 to 2
//s->set_contrast(s, 0); // -2 to 2
//s->set_saturation(s, 0); // -2 to 2
//s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
//s->set_whitebal(s, 1); // aka 'awb' in the UI; 0 = disable , 1 = enable
//s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
//s->set_wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
//s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
//s->set_aec2(s, 0); // 0 = disable , 1 = enable
//s->set_ae_level(s, 0); // -2 to 2
//s->set_aec_value(s, 300); // 0 to 1200
//s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
//s->set_agc_gain(s, 0); // 0 to 30
//s->set_gainceiling(s, (gainceiling_t)0); // 0 to 6
//s->set_bpc(s, 0); // 0 = disable , 1 = enable
//s->set_wpc(s, 1); // 0 = disable , 1 = enable
//s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
//s->set_lenc(s, 1); // 0 = disable , 1 = enable
//s->set_hmirror(s, 0); // 0 = disable , 1 = enable
//s->set_vflip(s, 0); // 0 = disable , 1 = enable
//s->set_dcw(s, 1); // 0 = disable , 1 = enable
//s->set_colorbar(s, 0); // 0 = disable , 1 = enable
//s->set_bpc(s, 0); // 0 = disable , 1 = enable
//s->set_wpc(s, 1); // 0 = disable , 1 = enable
//s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
//s->set_lenc(s, 1); // 0 = disable , 1 = enable
//s->set_hmirror(s, 0); // 0 = disable , 1 = enable
//s->set_vflip(s, 0); // 0 = disable , 1 = enable
//s->set_dcw(s, 1); // 0 = disable , 1 = enable
//s->set_colorbar(s, 0); // 0 = disable , 1 = enable

// We now have camera with default init
// check for saved preferences and apply them
Expand All @@ -483,19 +516,6 @@ void setup() {
Serial.println("No lamp, or lamp disabled in config");
}

// We need a working Wifi before we can start the http handlers
Serial.println("Starting WiFi");
Serial.print("Known external SSIDs: ");
if (firstStation < stationCount) {
for (int i=firstStation; i < stationCount; i++) Serial.printf(" '%s'", stationList[i].ssid);
} else {
Serial.print("None");
}
Serial.println();
byte mac[6];
WiFi.macAddress(mac);
Serial.printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

// Having got this far; start Wifi and loop until we are connected or have started an AccessPoint
while ((WiFi.status() != WL_CONNECTED) && !accesspoint) {
WifiSetup();
Expand All @@ -517,7 +537,7 @@ void setup() {
Serial.printf("Stream viewer available at '%sview'\n", streamURL);
Serial.printf("Raw stream URL is '%s'\n", streamURL);

// Used when dumpung status; slow functions, so do them here during startup
// Used when dumping status; these are slow functions, so just do them once during startup
sketchSize = ESP.getSketchSize();
sketchSpace = ESP.getFreeSketchSpace();
sketchMD5 = ESP.getSketchMD5();
Expand Down
6 changes: 4 additions & 2 deletions index_other.h
Original file line number Diff line number Diff line change
Expand Up @@ -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", `You can also browse to '${streamURL}' for a raw stream`);
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
console.log('Stream URL set to:' + value);
}
}
Expand Down Expand Up @@ -190,18 +190,20 @@ const uint8_t index_simple_html[] = R"=====(<!doctype html>
})
// Put some helpful text on the 'Still' button
stillButton.setAttribute("title", `You can also browse to '${baseHost}/capture' for standalone images`);
stillButton.setAttribute("title", `Capture a still image (${baseHost}/capture)`);
const stopStream = () => {
window.stop();
streamButton.innerHTML = 'Start Stream';
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
hide(viewContainer);
}
const startStream = () => {
view.src = streamURL;
view.scrollIntoView(false);
streamButton.innerHTML = 'Stop Stream';
streamButton.setAttribute("title", `Stop the stream (${streamURL})`);
show(viewContainer);
}
Expand Down
6 changes: 4 additions & 2 deletions index_ov2640.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
stream_link.setAttribute("title", "Open stream viewer (" + viewerURL + ")");
stream_link.style.textDecoration = "underline";
stream_link.style.cursor = "pointer";
streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`);
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
show(streamGroup)
console.log('Stream URL set to: ' + streamURL);
console.log('Stream Viewer URL set to: ' + viewerURL);
Expand Down Expand Up @@ -438,18 +438,20 @@ const uint8_t index_ov2640_html[] = R"=====(<!doctype html>
})

// Put some helpful text on the 'Still' button
stillButton.setAttribute("title", `You can also browse to '${baseHost}/capture' for standalone images`);
stillButton.setAttribute("title", `Capture a still image (${baseHost}/capture)`);

const stopStream = () => {
window.stop();
streamButton.innerHTML = 'Start Stream';
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
hide(viewContainer);
}

const startStream = () => {
view.src = streamURL;
view.scrollIntoView(false);
streamButton.innerHTML = 'Stop Stream';
streamButton.setAttribute("title", `Stop the stream (${streamURL})`);
show(viewContainer);
}

Expand Down
21 changes: 11 additions & 10 deletions index_ov3660.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* primary HTML for the OV3660 camera module
*/

const uint8_t index_ov3660_html[] = R"=====(
<!doctype html>
const uint8_t index_ov3660_html[] = R"=====(<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -232,7 +231,7 @@ const uint8_t index_ov3660_html[] = R"=====(
</div>
</div>
<div class="input-group" id="colorbar-group">
<label for="colorbar">Color Bar</label>
<label for="colorbar">Test Pattern</label>
<div class="switch">
<input id="colorbar" type="checkbox" class="default-action">
<label class="slider" for="colorbar"></label>
Expand Down Expand Up @@ -267,7 +266,8 @@ const uint8_t index_ov3660_html[] = R"=====(
<button id="clear_prefs" title="Erase saved Preferences on camera module">Erase</button>
</div>
<div class="input-group" id="cam_name-group">
<label for="cam_name">Name:</label>
<label for="cam_name">
<a href="/dump" title="System Info" target="_blank">Name</a></label>
<div id="cam_name" class="default-action"></div>
</div>
<div class="input-group" id="code_ver-group">
Expand All @@ -277,7 +277,7 @@ const uint8_t index_ov3660_html[] = R"=====(
<div id="code_ver" class="default-action"></div>
</div>
<div class="input-group hidden" id="stream-group">
<label for="stream_url" id="stream_link">Stream URL</label>
<label for="stream_url" id="stream_link">Stream</label>
<div id="stream_url" class="default-action">Unknown</div>
</div>
</nav>
Expand Down Expand Up @@ -389,7 +389,7 @@ const uint8_t index_ov3660_html[] = R"=====(
stream_link.setAttribute("title", "Open stream viewer (" + viewerURL + ")");
stream_link.style.textDecoration = "underline";
stream_link.style.cursor = "pointer";
streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`);
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
show(streamGroup)
console.log('Stream URL set to: ' + streamURL);
console.log('Stream Viewer URL set to: ' + viewerURL);
Expand Down Expand Up @@ -449,18 +449,20 @@ const uint8_t index_ov3660_html[] = R"=====(
})

// Put some helpful text on the 'Still' button
stillButton.setAttribute("title", `You can also browse to '${baseHost}/capture' for standalone images`);
stillButton.setAttribute("title", `Capture a still image (${baseHost}/capture)`);

const stopStream = () => {
window.stop();
streamButton.innerHTML = 'Start Stream';
streamButton.setAttribute("title", `Start the stream (${streamURL})`);
hide(viewContainer);
}

const startStream = () => {
view.src = streamURL;
view.scrollIntoView(false);
streamButton.innerHTML = 'Stop Stream';
streamButton.setAttribute("title", `Stop the stream (${streamURL})`);
show(viewContainer);
}

Expand Down Expand Up @@ -596,7 +598,7 @@ const uint8_t index_ov3660_html[] = R"=====(
}

swapButton.onclick = () => {
window.open('/view','_self');
window.open('/?view=simple','_self');
}

// saveFaceButton.onclick = () => {
Expand Down Expand Up @@ -633,7 +635,6 @@ const uint8_t index_ov3660_html[] = R"=====(

})
</script>
</html>
)=====";
</html>)=====";

size_t index_ov3660_html_len = sizeof(index_ov3660_html)-1;
4 changes: 2 additions & 2 deletions myconfig.sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct station {
{"ssid2", "pass2", true},
{"ssid3", "pass3", false}};
* The first entry in the stationList[] is special, if WIFI_AP_ENABLE has been uncommented (below)
* The first entry (ssid1, above) in the stationList[] is special, if WIFI_AP_ENABLE has been uncommented
* it will be used for the AccessPoint ssid and password.
*
* The 'dhcp' setting controls wether the station uses static IP settings (if in doubt leave 'true')
Expand All @@ -36,7 +36,7 @@ struct station {
struct station {
const char ssid[64]; // ssid (max 64 chars)
const char password[64]; // password (max 64 chars)
const bool dhcp; // dhcp
const bool dhcp; // use dhcp?
} stationList[] = {{"my_ssid","my_password", true}};


Expand Down

0 comments on commit 7d29e36

Please sign in to comment.