From cd7e3080676b711681610a219fc8b3fa4713dec0 Mon Sep 17 00:00:00 2001 From: abratchik Date: Sun, 4 Dec 2022 09:04:19 +0400 Subject: [PATCH] dump html fix --- API.md | 13 +++++++++---- README.md | 3 ++- data/www/dump.html | 2 +- src/app_component.cpp | 8 +++++--- src/app_conn.cpp | 2 +- src/app_httpd.cpp | 22 ++++++++++++++++------ 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/API.md b/API.md index 6fa1db7..148afad 100644 --- a/API.md +++ b/API.md @@ -76,11 +76,16 @@ Only for 3Mp+ camera modules: #### Commands These are commands; they can be sent by calling the `/control` URI with them as -the `` *(a `` must also be supplied, but can be any value and is ignored)*. +the `` parameter. ``` -save_prefs - Saves preferences file -clear_prefs - Deletes the preferences file -reboot - Reboots the board +* save_prefs - Saves preferences + `val=cam` or not specified will save camera preferences + `val=conn` will save network preferences +* clear_prefs - Deletes camera the preferences + `val=cam` or not specified will reset camera preferences + `val=conn` will reset network preferences. Attention! after this the server will boot as access point after restart, and all + connection settings will be lost. +* reboot - Reboots the board ``` ## Examples diff --git a/README.md b/README.md index 7b2f21f..225f8e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# ESP32-CAM Example Revisited2        ![ESP-EYE logo](data/www/logo.svg) +# ESP32-CAM Example Revisited2        +![ESP-EYE logo](data/www/logo.svg) ## Taken from the ESP examples, and expanded This sketch is a extension/expansion/rework of the 'official' ESP32 Camera example diff --git a/data/www/dump.html b/data/www/dump.html index e908908..c61fba2 100644 --- a/data/www/dump.html +++ b/data/www/dump.html @@ -125,7 +125,7 @@

ESP32 Cam Webserver

bodyHtml += 'Filesystem: ' + data.storage_size + data.storage_units + ', used: ' + data.storage_used + data.storage_units + '
'; - if(data.serial_buf.lenght == 0) { + if(data.serial_buf != "") { bodyHtml += '

Serial

'; bodyHtml += data.serial_buf; } diff --git a/src/app_component.cpp b/src/app_component.cpp index c877945..1234a4f 100644 --- a/src/app_component.cpp +++ b/src/app_component.cpp @@ -33,16 +33,18 @@ int CLAppComponent::readJsonIntVal(jparse_ctx_t *jctx_ptr, char* token) { return 0; } -void CLAppComponent::removePrefs() { +int CLAppComponent::removePrefs() { char *prefs_file = getPrefsFileName(true); if (fsStorage->exists(prefs_file)) { Serial.printf("Removing %s\r\n", prefs_file); if (!fsStorage->remove(prefs_file)) { - Serial.println("Error removing preferences"); + sprintf("Error removing %s preferences\r\n", tag); + return OS_FAIL; } } else { - Serial.println("No saved preferences file to remove"); + Serial.printf("No saved %s preferences to remove\r\n", tag); } + return OS_SUCCESS; } int CLAppComponent::parsePrefs(jparse_ctx_t *jctx) { diff --git a/src/app_conn.cpp b/src/app_conn.cpp index 78bf4e4..3232873 100644 --- a/src/app_conn.cpp +++ b/src/app_conn.cpp @@ -270,7 +270,7 @@ int CLAppConn::loadPrefs() { int CLAppConn::savePrefs() { // TODO: add saving of WiFi prefs - return OK; + return OS_SUCCESS; } void CLAppConn::enableOTA(bool enable) { diff --git a/src/app_httpd.cpp b/src/app_httpd.cpp index 8792b30..a468bba 100644 --- a/src/app_httpd.cpp +++ b/src/app_httpd.cpp @@ -248,6 +248,22 @@ void onControl(AsyncWebServerRequest *request) { AppHttpd.serialSendCommand(value.c_str()); request->send(200, "", "OK"); return; + } + else if(variable == "save_prefs") { + CLAppComponent * component = (value == "conn"?(CLAppComponent*)&AppConn:(CLAppComponent*)&AppCam); + if(component->removePrefs() == OS_SUCCESS) + request->send(200, "", "OK"); + else + request->send(500, "", "Failed to save preferences"); + return; + } + else if(variable == "remove_prefs") { + CLAppComponent * component = (value == "conn"?(CLAppComponent*)&AppConn:(CLAppComponent*)&AppCam); + if(component->removePrefs() == OS_SUCCESS) + request->send(200, "", "OK"); + else + request->send(500, "", "Failed to reset preferences"); + return; } int val = value.toInt(); @@ -291,12 +307,6 @@ void onControl(AsyncWebServerRequest *request) { else if(variable == "lamp" && AppCam.getLamp() != -1) { AppCam.setLamp(constrain(val,0,100)); } - else if(variable == "save_prefs") { - AppCam.savePrefs(); - } - else if(variable == "clear_prefs") { - AppCam.removePrefs(); - } else if(variable == "reboot") { if (AppCam.getLamp() != -1) AppCam.setLamp(0); // kill the lamp; otherwise it can remain on during the soft-reboot esp_task_wdt_init(3,true); // schedule a a watchdog panic event for 3 seconds in the future