Skip to content

Commit cbf96d1

Browse files
committed
Serial processing fix
1 parent 12f5f16 commit cbf96d1

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

esp32-cam-webserver.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void handleSerial() {
147147
// Rceiving commands and data from serial. Any input, which doesnt start from '#' is ignored.
148148
if (cmd == '#' ) {
149149
String rsp = Serial.readStringUntil('\n');
150-
// TODO: feed back to client for parsing
150+
sprintf(AppHttpd.getSerialBuffer(), rsp.c_str());
151151
}
152152
}
153153
}

src/app_httpd.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ void onControl(AsyncWebServerRequest *request) {
241241
String value = request->arg("val");
242242

243243
if(variable == "cmdout") {
244-
AppHttpd.serialSendCommand(value);
244+
if(AppHttpd.isDebugMode()) {
245+
Serial.print("cmmdout=");
246+
Serial.println(value.c_str());
247+
}
248+
AppHttpd.serialSendCommand(value.c_str());
245249
request->send(200, "", "OK");
246250
return;
247251
}
@@ -447,19 +451,16 @@ void dumpSystemStatusToJson(char * buf, size_t size) {
447451

448452
buf += sprintf(buf,"\"storage_size\":%i,", storageSize());
449453
buf += sprintf(buf,"\"storage_used\":%i,", storageUsed());
450-
buf += sprintf(buf,"\"storage_units\":\"%s\"", (capacityUnits()==STORAGE_UNITS_MB?"MB":""));
454+
buf += sprintf(buf,"\"storage_units\":\"%s\",", (capacityUnits()==STORAGE_UNITS_MB?"MB":""));
455+
buf += sprintf(buf,"\"serial_buf\":\"%s\"", AppHttpd.getSerialBuffer());
451456
buf += sprintf(buf, "}");
452457
}
453458

454-
void CLAppHttpd::serialSendCommand(char *cmd) {
459+
void CLAppHttpd::serialSendCommand(const char *cmd) {
455460
Serial.print("^");
456461
Serial.println(cmd);
457462
}
458463

459-
void CLAppHttpd::serialSendCommand(String cmd) {
460-
serialSendCommand(cmd.c_str());
461-
}
462-
463464
int CLAppHttpd::loadPrefs() {
464465
jparse_ctx_t jctx;
465466
int ret = parsePrefs(&jctx);

src/app_httpd.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class CLAppHttpd : public CLAppComponent {
5454

5555
void updateSnapTimer(int frameRate);
5656

57-
void serialSendCommand(char *cmd);
58-
void serialSendCommand(String cmd);
57+
void serialSendCommand(const char * cmd);
5958

6059
int getSketchSize(){ return sketchSize;};
6160
int getSketchSpace() {return sketchSpace;};
@@ -65,13 +64,17 @@ class CLAppHttpd : public CLAppComponent {
6564

6665
char * getName() {return myName;};
6766

67+
char * getSerialBuffer() {return serialBuffer;};
68+
6869

6970
private:
7071

7172
// Name of the application used in web interface
7273
// Can be re-defined in the httpd.json file
7374
char myName[20] = CAM_NAME;
7475

76+
char serialBuffer[64];
77+
7578
AsyncWebServer *server;
7679
AsyncWebSocket *ws;
7780
uint32_t client_id = 0;

0 commit comments

Comments
 (0)