Skip to content

Commit cd7e308

Browse files
committed
dump html fix
1 parent beab0bb commit cd7e308

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

API.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ Only for 3Mp+ camera modules:
7676

7777
#### Commands
7878
These are commands; they can be sent by calling the `/control` URI with them as
79-
the `<key>` *(a `<val>` must also be supplied, but can be any value and is ignored)*.
79+
the `<key>` parameter.
8080
```
81-
save_prefs - Saves preferences file
82-
clear_prefs - Deletes the preferences file
83-
reboot - Reboots the board
81+
* save_prefs - Saves preferences
82+
`val=cam` or not specified will save camera preferences
83+
`val=conn` will save network preferences
84+
* clear_prefs - Deletes camera the preferences
85+
`val=cam` or not specified will reset camera preferences
86+
`val=conn` will reset network preferences. Attention! after this the server will boot as access point after restart, and all
87+
connection settings will be lost.
88+
* reboot - Reboots the board
8489
```
8590

8691
## Examples

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# ESP32-CAM Example Revisited<sup>2</sup> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span title="ESP EYE">![ESP-EYE logo](data/www/logo.svg)</span>
1+
# ESP32-CAM Example Revisited<sup>2</sup> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
2+
<span title="ESP EYE">![ESP-EYE logo](data/www/logo.svg)</span>
23

34
## Taken from the ESP examples, and expanded
45
This sketch is a extension/expansion/rework of the 'official' ESP32 Camera example

data/www/dump.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h1>ESP32 Cam Webserver</h1>
125125
bodyHtml += 'Filesystem: ' + data.storage_size + data.storage_units +
126126
', used: ' + data.storage_used + data.storage_units + '<br>';
127127

128-
if(data.serial_buf.lenght == 0) {
128+
if(data.serial_buf != "") {
129129
bodyHtml += '<h2>Serial</h2>';
130130
bodyHtml += data.serial_buf;
131131
}

src/app_component.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ int CLAppComponent::readJsonIntVal(jparse_ctx_t *jctx_ptr, char* token) {
3333
return 0;
3434
}
3535

36-
void CLAppComponent::removePrefs() {
36+
int CLAppComponent::removePrefs() {
3737
char *prefs_file = getPrefsFileName(true);
3838
if (fsStorage->exists(prefs_file)) {
3939
Serial.printf("Removing %s\r\n", prefs_file);
4040
if (!fsStorage->remove(prefs_file)) {
41-
Serial.println("Error removing preferences");
41+
sprintf("Error removing %s preferences\r\n", tag);
42+
return OS_FAIL;
4243
}
4344
} else {
44-
Serial.println("No saved preferences file to remove");
45+
Serial.printf("No saved %s preferences to remove\r\n", tag);
4546
}
47+
return OS_SUCCESS;
4648
}
4749

4850
int CLAppComponent::parsePrefs(jparse_ctx_t *jctx) {

src/app_conn.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int CLAppConn::loadPrefs() {
270270

271271
int CLAppConn::savePrefs() {
272272
// TODO: add saving of WiFi prefs
273-
return OK;
273+
return OS_SUCCESS;
274274
}
275275

276276
void CLAppConn::enableOTA(bool enable) {

src/app_httpd.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ void onControl(AsyncWebServerRequest *request) {
248248
AppHttpd.serialSendCommand(value.c_str());
249249
request->send(200, "", "OK");
250250
return;
251+
}
252+
else if(variable == "save_prefs") {
253+
CLAppComponent * component = (value == "conn"?(CLAppComponent*)&AppConn:(CLAppComponent*)&AppCam);
254+
if(component->removePrefs() == OS_SUCCESS)
255+
request->send(200, "", "OK");
256+
else
257+
request->send(500, "", "Failed to save preferences");
258+
return;
259+
}
260+
else if(variable == "remove_prefs") {
261+
CLAppComponent * component = (value == "conn"?(CLAppComponent*)&AppConn:(CLAppComponent*)&AppCam);
262+
if(component->removePrefs() == OS_SUCCESS)
263+
request->send(200, "", "OK");
264+
else
265+
request->send(500, "", "Failed to reset preferences");
266+
return;
251267
}
252268

253269
int val = value.toInt();
@@ -291,12 +307,6 @@ void onControl(AsyncWebServerRequest *request) {
291307
else if(variable == "lamp" && AppCam.getLamp() != -1) {
292308
AppCam.setLamp(constrain(val,0,100));
293309
}
294-
else if(variable == "save_prefs") {
295-
AppCam.savePrefs();
296-
}
297-
else if(variable == "clear_prefs") {
298-
AppCam.removePrefs();
299-
}
300310
else if(variable == "reboot") {
301311
if (AppCam.getLamp() != -1) AppCam.setLamp(0); // kill the lamp; otherwise it can remain on during the soft-reboot
302312
esp_task_wdt_init(3,true); // schedule a a watchdog panic event for 3 seconds in the future

0 commit comments

Comments
 (0)