Skip to content

Commit

Permalink
Debug Toggle in AP mode (#105)
Browse files Browse the repository at this point in the history
* #92 Debug Toggle in AP mode
* Re-structure how serial input and debug is handled/setup to allow for expansion
  • Loading branch information
easytarget authored May 9, 2021
1 parent 34a4d46 commit 0226536
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,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)<br>\n", upDays, upHours, upMin, upSec);
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Image captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
d+= sprintf(d,"Freq: %i MHz<br>\n", ESP.getCpuFreqMHz());
d+= sprintf(d,"Heap: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());
d+= sprintf(d,"Psram: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getPsramSize(), ESP.getFreePsram(), ESP.getMinFreePsram(), ESP.getMaxAllocPsram());
Expand Down
57 changes: 34 additions & 23 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,32 @@ const int pwmMax = pow(2,pwmresolution)-1;
// will be returned for all http requests
String critERR = "";

// Debug Data for stream and capture
#if defined(DEBUG_DEFAULT_ON)
bool debugData = true;
#else
bool debugData = false;
#endif
// Debug flag for stream and capture data
bool debugData;

void debugOn() {
debugData = true;
Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
}

void debugOff() {
debugData = false;
Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
}

// Serial input (debugging controls)
void handleSerial() {
if (Serial.available()) {
char cmd = Serial.read();
if (cmd == 'd' ) {
serialDump();
} else {
if (debugData) debugOff();
else debugOn();
}
}
while (Serial.available()) Serial.read(); // chomp the buffer
}

// Notification LED
void flashLED(int flashtime) {
Expand Down Expand Up @@ -601,8 +621,11 @@ 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 '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)");
#if defined(DEBUG_DEFAULT_ON)
debugOn();
#else
debugOff();
#endif
} else {
Serial.printf("\nCamera unavailable due to initialisation errors.\n\n");
}
Expand All @@ -621,9 +644,11 @@ void loop() {
*/
if (accesspoint) {
// Accespoint is permanently up, so just loop, servicing the captive portal as needed
// Rather than loop forever, follow the watchdog, in case we later add auto re-scan.
unsigned long start = millis();
while (millis() - start < WIFI_WATCHDOG ) {
delay(100);
handleSerial();
if (captivePortal) dnsServer.processNextRequest();
}
} else {
Expand All @@ -640,21 +665,7 @@ void loop() {
unsigned long start = millis();
while (millis() - start < WIFI_WATCHDOG ) {
delay(100);
if (Serial.available()) {
if (Serial.read() == 'd' ) {
serialDump();
} else {
// 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
handleSerial();
}
} else {
// disconnected; attempt to reconnect
Expand Down

0 comments on commit 0226536

Please sign in to comment.