Skip to content

Commit

Permalink
dump html fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abratchik committed Dec 4, 2022
1 parent beab0bb commit cd7e308
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
13 changes: 9 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<key>` *(a `<val>` must also be supplied, but can be any value and is ignored)*.
the `<key>` 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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ESP32-CAM Example Revisited<sup>2</sup> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span title="ESP EYE">![ESP-EYE logo](data/www/logo.svg)</span>
# ESP32-CAM Example Revisited<sup>2</sup> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
<span title="ESP EYE">![ESP-EYE logo](data/www/logo.svg)</span>

## Taken from the ESP examples, and expanded
This sketch is a extension/expansion/rework of the 'official' ESP32 Camera example
Expand Down
2 changes: 1 addition & 1 deletion data/www/dump.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h1>ESP32 Cam Webserver</h1>
bodyHtml += 'Filesystem: ' + data.storage_size + data.storage_units +
', used: ' + data.storage_used + data.storage_units + '<br>';

if(data.serial_buf.lenght == 0) {
if(data.serial_buf != "") {
bodyHtml += '<h2>Serial</h2>';
bodyHtml += data.serial_buf;
}
Expand Down
8 changes: 5 additions & 3 deletions src/app_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/app_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 16 additions & 6 deletions src/app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd7e308

Please sign in to comment.