diff --git a/esp32cam-demo.ino b/esp32cam-demo.ino
index 9385fb2..c870b9d 100644
--- a/esp32cam-demo.ino
+++ b/esp32cam-demo.ino
@@ -89,8 +89,8 @@
bool sendRGBfile = 0; // if set '/rgb' will just return raw rgb data which can be saved as a file rather than display a HTML pag
- uint16_t datarefresh = 2200; // how often to refresh data on root web page (ms)
- uint16_t imagerefresh = 5000; // how often to refresh the image on root web page (ms)
+ uint16_t dataRefresh = 2; // how often to refresh data on root web page (seconds)
+ uint16_t imagerefresh = 5; // how often to refresh the image on root web page (seconds)
const bool serialDebug = 1; // show debug info. on serial port (1=enabled, disable if using pins 1 and 3 as gpio)
@@ -432,7 +432,7 @@ bool initialiseCamera() {
config.frame_size = FRAME_SIZE_IMAGE; // Image sizes: 160x120 (QQVGA), 128x160 (QQVGA2), 176x144 (QCIF), 240x176 (HQVGA), 320x240 (QVGA),
// 400x296 (CIF), 640x480 (VGA, default), 800x600 (SVGA), 1024x768 (XGA), 1280x1024 (SXGA),
// 1600x1200 (UXGA)
- config.jpeg_quality = 15; // 0-63 lower number means higher quality
+ config.jpeg_quality = 12; // 0-63 lower number means higher quality (can cause failed image capture if set too low at higher resolutions)
config.fb_count = 1; // if more than one, i2s runs in continuous mode. Use only with JPEG
// check the esp32cam board has a psram chip installed (extra memory used for storing captured images)
@@ -467,7 +467,8 @@ bool initialiseCamera() {
// Adjust image properties (brightness etc.)
// Defaults to auto adjustments if exposure and gain are both set to zero
// - Returns TRUE if successful
-// BTW - some interesting info on exposure times here: https://github.com/raduprv/esp32-cam_ov2640-timelapse
+// More info: https://randomnerdtutorials.com/esp32-cam-ov2640-camera-settings/
+// interesting info on exposure times here: https://github.com/raduprv/esp32-cam_ov2640-timelapse
bool cameraImageSettings() {
@@ -886,31 +887,23 @@ void handleRoot() {
// Verify your HTML is valid: https://validator.w3.org/
- client.write("Sketch from: github.com/alanesq/esp32cam-demo
");
-
// ---------------------------------------------------------------------------------------------
- // info which is periodically updated usin AJAX - https://www.w3schools.com/xml/ajax_intro.asp
+ // info which is periodically updated usin AJAX - https://www.w3schools.com/xml/ajax_intro.asp
- // sd card
- if (!sdcardPresent) {
- client.println("
NO SD CARD DETECTED
"); // spans will be left empty
- } else {
- client.println("SD Card: - images stored, - MB used , - MB remaining
\n");
- }
+ // empty lines which are populated via vbscript with live data from http://x.x.x.x/data in the form of comma seperated text
+ // you can add more or remove unwanted ones as required without modifying the javascript
+ client.println("");
+ client.println("
");
+ client.println("
");
+ client.println("
");
+ client.println("
");
+ client.println("
");
- // illumination/flash led
- client.println("Illumination led brightness= - , Flash is - ");
-
- // Current real time
- client.println("
Current time: - ");
-
- // gpio pin status
- client.print("
GPIO output pin 12 is: - , GPIO input pin 13 is: - ");
-
- // image resolution
- client.println("
Image size: - ");
-
- // Javascript - to periodically update above getting info from http://x.x.x.x/data
+ // Javascript - to periodically update the above info lines from http://x.x.x.x/data
+ // This is the below javascript code compacted to save flash memory via https://www.textfixer.com/html/compress-html-compression.php
+ client.printf(R"=====( )=====", dataRefresh * 1000);
+ /*
+ // get a comma seperated list from http://x.x.x.x/data and populate the blank lines in html above
client.printf(R"=====(
- )=====", datarefresh);
+ )=====", dataRefresh * 1000);
+ */
// ---------------------------------------------------------------------------------------------
@@ -969,7 +957,7 @@ void handleRoot() {
// capture and show a jpg image
client.write("
"); // make it a link
- client.write("
"); // show image from http://x.x.x.x/jpg
+ client.write("
"); // show image from http://x.x.x.x/jpg
// javascript to refresh the image periodically
client.printf(R"=====(
@@ -982,7 +970,9 @@ void handleRoot() {
}
setInterval(function() { refreshImage(); }, %d);
- )=====", imagerefresh);
+ )=====", imagerefresh * 1000);
+
+ client.println("
Sketch Info");
// --------------------------------------------------------------------
@@ -996,11 +986,13 @@ void handleRoot() {
// ----------------------------------------------------------------
// -data web page requested i.e. http://x.x.x.x/data
// ----------------------------------------------------------------
-// suplies changing info to update root web page as comma seperated String
+// the root web page requests this periodically via Javascript in order to display updating information.
+// information in the form of comma seperated text is supplied which are then inserted in to blank lines on the web page
+// This makes it very easy to modify the data shown without having to change the javascript or root page html
void handleData(){
- // sd sdcard
+ // sd sdcard info
uint32_t SDusedSpace = 0;
uint32_t SDtotalSpace = 0;
uint32_t SDfreeSpace = 0;
@@ -1009,26 +1001,36 @@ void handleData(){
SDtotalSpace = SD_MMC.totalBytes() / (1024 * 1024);
SDfreeSpace = SDtotalSpace - SDusedSpace;
}
-
String reply = "";
- if (sdcardPresent) reply += String(imageCounter); // images stored
+
+ // sd card
+ if (!sdcardPresent) {
+ reply += "NO SD CARD DETECTED";
+ } else {
+ reply += "SD Card: " + String(SDusedSpace) + "Mb used - " + String(SDfreeSpace) + "Mb free";
+ }
reply += ",";
- if (sdcardPresent) reply += String(SDusedSpace); // space used on sd card
+
+ // illumination/flash led
+ reply += "Illumination led brightness=" + String(brightLEDbrightness);
+ reply += " Flash is "; // Note: ' ' leaves a gap
+ reply += (flashRequired) ? "Enabled" : "Off";
reply += ",";
- if (sdcardPresent) reply += String(SDfreeSpace); // space remaining on sd card
+
+ // Current real time
+ reply += "Current time: " + localTime();
reply += ",";
- reply += String(brightLEDbrightness); // illumination led brightness
+
+ // gpio pin status
+ reply += "GPIO output pin 12 is: ";
+ reply += (digitalRead(iopinB)==1) ? "ON" : "OFF";
+ reply += " GPIO input pin 13 is: ";
+ reply += (digitalRead(iopinA)==1) ? "ON" : "OFF";
reply += ",";
- reply += localTime(); // current date/time
- reply += ",";
- reply += (digitalRead(iopinB)==1) ? "ON" : "OFF"; // output gpio pin status
- reply += ",";
- reply += (digitalRead(iopinA)==1) ? "ON" : "OFF"; // output gpio pin status
- reply += ",";
- reply += (flashRequired==1) ? "ON" : "OFF"; // if flash is enabled
- reply += ",";
- reply += ImageResDetails; // if flash is enabled
- //reply += ",";
+
+ // image resolution
+ reply += "Image size: " + ImageResDetails;
+
server.send(200, "text/plane", reply); //Send millis value only to client ajax request
}