Skip to content

Commit 0226536

Browse files
authored
Debug Toggle in AP mode (#105)
* #92 Debug Toggle in AP mode * Re-structure how serial input and debug is handled/setup to allow for expansion
1 parent 34a4d46 commit 0226536

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

app_httpd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static esp_err_t dump_handler(httpd_req_t *req){
862862
int upMin = int64_t(floor(sec/60)) % 60;
863863
int upSec = sec % 60;
864864
d+= sprintf(d,"Up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)<br>\n", upDays, upHours, upMin, upSec);
865-
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Image captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
865+
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
866866
d+= sprintf(d,"Freq: %i MHz<br>\n", ESP.getCpuFreqMHz());
867867
d+= sprintf(d,"Heap: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());
868868
d+= sprintf(d,"Psram: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getPsramSize(), ESP.getFreePsram(), ESP.getMinFreePsram(), ESP.getMaxAllocPsram());

esp32-cam-webserver.ino

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,32 @@ const int pwmMax = pow(2,pwmresolution)-1;
179179
// will be returned for all http requests
180180
String critERR = "";
181181

182-
// Debug Data for stream and capture
183-
#if defined(DEBUG_DEFAULT_ON)
184-
bool debugData = true;
185-
#else
186-
bool debugData = false;
187-
#endif
182+
// Debug flag for stream and capture data
183+
bool debugData;
184+
185+
void debugOn() {
186+
debugData = true;
187+
Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
188+
}
189+
190+
void debugOff() {
191+
debugData = false;
192+
Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
193+
}
194+
195+
// Serial input (debugging controls)
196+
void handleSerial() {
197+
if (Serial.available()) {
198+
char cmd = Serial.read();
199+
if (cmd == 'd' ) {
200+
serialDump();
201+
} else {
202+
if (debugData) debugOff();
203+
else debugOn();
204+
}
205+
}
206+
while (Serial.available()) Serial.read(); // chomp the buffer
207+
}
188208

189209
// Notification LED
190210
void flashLED(int flashtime) {
@@ -601,8 +621,11 @@ void setup() {
601621
Serial.printf("\nCamera Ready!\nUse '%s' to connect\n", httpURL);
602622
Serial.printf("Stream viewer available at '%sview'\n", streamURL);
603623
Serial.printf("Raw stream URL is '%s'\n", streamURL);
604-
if (debugData) Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
605-
else Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
624+
#if defined(DEBUG_DEFAULT_ON)
625+
debugOn();
626+
#else
627+
debugOff();
628+
#endif
606629
} else {
607630
Serial.printf("\nCamera unavailable due to initialisation errors.\n\n");
608631
}
@@ -621,9 +644,11 @@ void loop() {
621644
*/
622645
if (accesspoint) {
623646
// Accespoint is permanently up, so just loop, servicing the captive portal as needed
647+
// Rather than loop forever, follow the watchdog, in case we later add auto re-scan.
624648
unsigned long start = millis();
625649
while (millis() - start < WIFI_WATCHDOG ) {
626650
delay(100);
651+
handleSerial();
627652
if (captivePortal) dnsServer.processNextRequest();
628653
}
629654
} else {
@@ -640,21 +665,7 @@ void loop() {
640665
unsigned long start = millis();
641666
while (millis() - start < WIFI_WATCHDOG ) {
642667
delay(100);
643-
if (Serial.available()) {
644-
if (Serial.read() == 'd' ) {
645-
serialDump();
646-
} else {
647-
// Toggle debug output on serial input
648-
if (debugData) {
649-
debugData = false;
650-
Serial.println("Camera debug data is disabled (send 'd' for status dump, or any other char to enable debug)");
651-
} else {
652-
debugData = true;
653-
Serial.println("Camera debug data is enabled (send 'd' for status dump, or any other char to disable debug)");
654-
}
655-
}
656-
}
657-
while (Serial.available()) Serial.read(); // chomp the buffer
668+
handleSerial();
658669
}
659670
} else {
660671
// disconnected; attempt to reconnect

0 commit comments

Comments
 (0)