mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-11 21:09:05 +08:00
Fix timeout in web command
Add
This commit is contained in:
parent
9746a4e24f
commit
44747339dd
Binary file not shown.
@ -601,7 +601,7 @@ void handleFileList()
|
|||||||
//SPIFFS files uploader handle
|
//SPIFFS files uploader handle
|
||||||
void SPIFFSFileupload()
|
void SPIFFSFileupload()
|
||||||
{
|
{
|
||||||
static FS_FILE fsUploadFile = (FS_FILE)0;
|
static FS_FILE fsUploadFile = (FS_FILE)0;
|
||||||
static String filename;
|
static String filename;
|
||||||
//get authentication status
|
//get authentication status
|
||||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
@ -958,7 +958,6 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
String cmd = "";
|
String cmd = "";
|
||||||
int count ;
|
|
||||||
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
|
||||||
if (web_interface->web_server.hasArg("plain")) {
|
if (web_interface->web_server.hasArg("plain")) {
|
||||||
cmd = web_interface->web_server.arg("plain");
|
cmd = web_interface->web_server.arg("plain");
|
||||||
@ -1029,38 +1028,46 @@ void handle_web_command()
|
|||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
}
|
}
|
||||||
LOG("End PurgeSerial\r\n")
|
LOG("End PurgeSerial\r\n")
|
||||||
LOG("Send Command\r\n")
|
|
||||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||||
count = 0;
|
bool done = false;
|
||||||
String current_buffer;
|
String current_buffer;
|
||||||
String current_line;
|
String current_line;
|
||||||
//int pos;
|
//int pos;
|
||||||
int temp_counter = 0;
|
int temp_counter = 0;
|
||||||
String tmp;
|
String tmp;
|
||||||
bool datasent = false;
|
bool datasent = false;
|
||||||
|
uint32_t timeout = millis();
|
||||||
//pickup the list
|
//pickup the list
|
||||||
while (count < MAX_TRY) {
|
while ((millis() - timeout < 2000) && !done) {
|
||||||
//give some time between each buffer
|
//give some time between each buffer
|
||||||
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||||
count = 0;
|
LOG("Got data\r\n")
|
||||||
|
timeout = millis();
|
||||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
//read buffer
|
//read buffer
|
||||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||||
//change buffer as string
|
//change buffer as string
|
||||||
sbuf[len]='\0';
|
sbuf[len]='\0';
|
||||||
|
LOG((const char*)sbuf)
|
||||||
|
LOG("\r\n")
|
||||||
//add buffer to current one if any
|
//add buffer to current one if any
|
||||||
current_buffer += (char * ) sbuf;
|
current_buffer += (char * ) sbuf;
|
||||||
while (current_buffer.indexOf("\n") !=-1) {
|
while (current_buffer.indexOf("\n") !=-1) {
|
||||||
|
LOG("remove newline")
|
||||||
//remove the possible "\r"
|
//remove the possible "\r"
|
||||||
current_buffer.replace("\r","");
|
current_buffer.replace("\r","");
|
||||||
//pos = current_buffer.indexOf("\n");
|
|
||||||
//get line
|
//get line
|
||||||
current_line = current_buffer.substring(0,current_buffer.indexOf("\n"));
|
current_line = current_buffer.substring(0,current_buffer.indexOf("\n"));
|
||||||
//if line is command ack - just exit so save the time out period
|
//if line is command ack - just exit so save the time out period
|
||||||
if ((current_line == "ok") || (current_line == "wait")) {
|
if ((current_line == "ok") || (current_line == "wait") || (current_line.startsWith("ok") && !((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)))) {
|
||||||
count = MAX_TRY;
|
done = true;
|
||||||
LOG("Found ok\r\n")
|
buffer2send +=current_line;
|
||||||
|
LOG("new buffer: ")
|
||||||
|
LOG(buffer2send)
|
||||||
|
LOG("\r\n")
|
||||||
|
buffer2send +="\n";
|
||||||
|
LOG("Found ok or wait\r\n")
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//get the line and transmit it
|
//get the line and transmit it
|
||||||
@ -1081,6 +1088,8 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (temp_counter > 5) {
|
if (temp_counter > 5) {
|
||||||
|
LOG("Timeout X5\r\n")
|
||||||
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
||||||
@ -1090,31 +1099,41 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer2send +=current_line;
|
buffer2send +=current_line;
|
||||||
|
LOG("new buffer: ")
|
||||||
|
LOG(buffer2send)
|
||||||
|
LOG("\r\n")
|
||||||
buffer2send +="\n";
|
buffer2send +="\n";
|
||||||
}
|
}
|
||||||
if (buffer2send.length() > 1200) {
|
if (buffer2send.length() > 1200) {
|
||||||
web_interface->web_server.sendContent(buffer2send);
|
web_interface->web_server.sendContent(buffer2send);
|
||||||
|
LOG("sending: ")
|
||||||
|
LOG(buffer2send)
|
||||||
|
LOG("\r\n")
|
||||||
buffer2send = "";
|
buffer2send = "";
|
||||||
datasent = true;
|
datasent = true;
|
||||||
}
|
}
|
||||||
//current remove line from buffer
|
//current remove line from buffer
|
||||||
tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length());
|
tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length());
|
||||||
current_buffer = tmp;
|
current_buffer = tmp;
|
||||||
delay(0);
|
CONFIG::wait (0);
|
||||||
}
|
}
|
||||||
CONFIG::wait (0);
|
CONFIG::wait (0);
|
||||||
} else {
|
} else {
|
||||||
CONFIG::wait(1);
|
CONFIG::wait(1);
|
||||||
|
LOG(".")
|
||||||
}
|
}
|
||||||
//it is sending too many temp status should be heating so let's exit the loop
|
//it is sending too many temp status should be heating so let's exit the loop
|
||||||
if (temp_counter > 5) {
|
if (temp_counter > 5) {
|
||||||
count = MAX_TRY;
|
done = true;
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
LOG("Finished\r\n")
|
||||||
//to be sure connection close
|
//to be sure connection close
|
||||||
if (buffer2send.length() > 0) {
|
if (buffer2send.length() > 0) {
|
||||||
web_interface->web_server.sendContent(buffer2send);
|
web_interface->web_server.sendContent(buffer2send);
|
||||||
|
LOG("sending: ")
|
||||||
|
LOG(buffer2send)
|
||||||
|
LOG("\r\n")
|
||||||
datasent = true;
|
datasent = true;
|
||||||
}
|
}
|
||||||
if (!datasent) {
|
if (!datasent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user