Add support to catch SD File list

Due to memory constraint limit to 70 entries of 30 char max =~2K
also add a time out if cannot catch end of list within 30s
/SDFILES is a JSON file with the list - UI not defined yet
This commit is contained in:
luc 2015-10-20 13:28:15 +08:00
parent 8fd0768df7
commit 01d4fc007c
4 changed files with 104 additions and 52 deletions

View File

@ -66,7 +66,7 @@ Home page :
<img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page1.png><br> <img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page1.png><br>
System Configuration Page: System Configuration Page:
<img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page2.png><br> <img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page2.png><br>
Access Point Configuation Page: Access Point Configuration Page:
<img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page3.png><br> <img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page3.png><br>
Client Configuration Page: Client Configuration Page:
<img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page4.png><br> <img src=https://raw.githubusercontent.com/luc-github/ESP8266/master/Page4.png><br>

View File

@ -66,60 +66,93 @@ void COMMAND::execute_command(int cmd,String cmd_params)
void COMMAND::check_command(String buffer) void COMMAND::check_command(String buffer)
{ {
String ESP_Command; String ESP_Command;
//look for ESP command static bool bfileslist=false;
//is there a first part ? static uint32_t start_list=0;
int ESPpos = buffer.indexOf("[ESP"); if (!bfileslist)
int Tpos = buffer.indexOf("T:"); {
int Xpos = buffer.indexOf("X:"); int filesstart = buffer.indexOf("Begin file list");
int Ypos = buffer.indexOf("Y:"); if (filesstart>-1)
int Zpos = buffer.indexOf("Z:"); {
int Speedpos = buffer.indexOf("SpeedMultiply:"); Serial.print("Starting");
int Flowpos = buffer.indexOf("FlowMultiply:"); start_list=system_get_time();
int Errorpos= buffer.indexOf("Error:"); bfileslist=true;
int Infopos= buffer.indexOf("Info:"); web_interface->fileslist.clear();
int Statuspos= buffer.indexOf("Status:");
if (ESPpos>-1)
{//is there the second part?
int ESPpos2 = buffer.indexOf("]",ESPpos);
if (ESPpos2>-1)
{ //Split in command and parameters
String cmd_part1=buffer.substring(ESPpos+4,ESPpos2);
String cmd_part2="";
//is there space for parameters?
if (ESPpos2<buffer.length())
{
cmd_part2=buffer.substring(ESPpos2+1);
}
//if command is a valid number then execute command
if(cmd_part1.toInt()!=0)execute_command(cmd_part1.toInt(),cmd_part2);
//if not is not a valid [ESPXXX] command
} }
} int ESPpos = buffer.indexOf("[ESP");
//check for temperature int Tpos = buffer.indexOf("T:");
if (Tpos>-1) int Xpos = buffer.indexOf("X:");
{ int Ypos = buffer.indexOf("Y:");
//look for valid temperature answer int Zpos = buffer.indexOf("Z:");
int slashpos = buffer.indexOf(" /",Tpos); int Speedpos = buffer.indexOf("SpeedMultiply:");
int spacepos = buffer.indexOf(" ",slashpos+1); int Flowpos = buffer.indexOf("FlowMultiply:");
//if match mask T:xxx.xx /xxx.xx int Errorpos= buffer.indexOf("Error:");
if(spacepos-Tpos < 17) int Infopos= buffer.indexOf("Info:");
int Statuspos= buffer.indexOf("Status:");
if (ESPpos>-1)
{//is there the second part?
int ESPpos2 = buffer.indexOf("]",ESPpos);
if (ESPpos2>-1)
{ //Split in command and parameters
String cmd_part1=buffer.substring(ESPpos+4,ESPpos2);
String cmd_part2="";
//is there space for parameters?
if (ESPpos2<buffer.length())
{
cmd_part2=buffer.substring(ESPpos2+1);
}
//if command is a valid number then execute command
if(cmd_part1.toInt()!=0)execute_command(cmd_part1.toInt(),cmd_part2);
//if not is not a valid [ESPXXX] command
}
}
//check for temperature
if (Tpos>-1)
{ {
web_interface->answer4M105=buffer; //do not interprete just need when requested so store it //look for valid temperature answer
web_interface->last_temp=system_get_time(); int slashpos = buffer.indexOf(" /",Tpos);
int spacepos = buffer.indexOf(" ",slashpos+1);
//if match mask T:xxx.xx /xxx.xx
if(spacepos-Tpos < 17)
{
web_interface->answer4M105=buffer; //do not interprete just need when requested so store it
web_interface->last_temp=system_get_time();
}
} }
//Position of axis
if (Xpos>-1 && Ypos>-1 && Zpos>-1)web_interface->answer4M114=buffer;
//Speed
if (Speedpos>-1)web_interface->answer4M220=buffer.substring(Speedpos+14);
//Flow
if (Flowpos>-1)web_interface->answer4M221=buffer.substring(Flowpos+13);
//Error
if (Errorpos>-1 && !(buffer.indexOf("Format error")!=-1 || buffer.indexOf("wait")==Errorpos+6) )(web_interface->error_msg).add(buffer.substring(Errorpos+6).c_str());
//Info
if (Infopos>-1)(web_interface->info_msg).add(buffer.substring(Infopos+5).c_str());
//Status
if (Statuspos>-1)(web_interface->status_msg).add(buffer.substring(Statuspos+7).c_str());
}
else
{
if ((system_get_time()-start_list)>30000000) //timeout in case of problem
{
bfileslist=false;
Serial.print("time out");
}
else
{
if (buffer.indexOf("End file list")>-1)
{
Serial.print("Ending");
bfileslist=false;
}
else
{
Serial.print(buffer);
web_interface->fileslist.add(buffer);
}
}
} }
//Position of axis
if (Xpos>-1 && Ypos>-1 && Zpos>-1)web_interface->answer4M114=buffer;
//Speed
if (Speedpos>-1)web_interface->answer4M220=buffer.substring(Speedpos+14);
//Flow
if (Flowpos>-1)web_interface->answer4M221=buffer.substring(Flowpos+13);
//Error
if (Errorpos>-1 && !(buffer.indexOf("Format error")!=-1 || buffer.indexOf("wait")==Errorpos+6) )(web_interface->error_msg).add(buffer.substring(Errorpos+6).c_str());
//Info
if (Infopos>-1)(web_interface->info_msg).add(buffer.substring(Infopos+5).c_str());
//Status
if (Statuspos>-1)(web_interface->status_msg).add(buffer.substring(Statuspos+7).c_str());
} }
//read a buffer in an array //read a buffer in an array

View File

@ -2400,6 +2400,20 @@ void handleFileList() {
web_interface->WebServer.send(200, "application/json", jsonfile); web_interface->WebServer.send(200, "application/json", jsonfile);
} }
void handleSDFileList() {
String jsonfile = "[";
for (int i=0;i<web_interface->fileslist.size();i++)
{
if (i>0)jsonfile+=",";
jsonfile+="{\"entry\":\"";
jsonfile+=web_interface->fileslist.get(i);
jsonfile+="\"}";
}
jsonfile+="]";
web_interface->WebServer.send(200, "application/json", jsonfile);
}
//do a redirect to avoid to many query //do a redirect to avoid to many query
//and handle not registred path //and handle not registred path
void handle_not_found() void handle_not_found()
@ -2627,6 +2641,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
WebServer.on("/CMD",HTTP_ANY, handle_web_command); WebServer.on("/CMD",HTTP_ANY, handle_web_command);
WebServer.on("/RESTART",HTTP_GET, handle_restart); WebServer.on("/RESTART",HTTP_GET, handle_restart);
WebServer.on("/FILES", HTTP_ANY, handleFileList); WebServer.on("/FILES", HTTP_ANY, handleFileList);
WebServer.on("/SDFILES", HTTP_ANY, handleSDFileList);
WebServer.onFileUpload(handleFileUpload); WebServer.onFileUpload(handleFileUpload);
//Captive portal Feature //Captive portal Feature
#ifdef CAPTIVE_PORTAL_FEATURE #ifdef CAPTIVE_PORTAL_FEATURE
@ -2643,13 +2658,15 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
answer4M221="100"; answer4M221="100";
last_temp=system_get_time(); last_temp=system_get_time();
restartmodule=false; restartmodule=false;
//rolling list of 5 entries with a maximum of 50 char for each entry //rolling list of 4entries with a maximum of 50 char for each entry
error_msg.setsize(4); error_msg.setsize(4);
error_msg.setlenght(50); error_msg.setlenght(50);
info_msg.setsize(4); info_msg.setsize(4);
info_msg.setlenght(50); info_msg.setlenght(50);
status_msg.setsize(4); status_msg.setsize(4);
status_msg.setlenght(50); status_msg.setlenght(50);
fileslist.setlenght(30);//12 for filename + space + size
fileslist.setsize(70); // 70 files to limite to 2K
fsUploadFile=(fs::File)0; fsUploadFile=(fs::File)0;
} }
//Destructor //Destructor
@ -2658,6 +2675,7 @@ WEBINTERFACE_CLASS::~WEBINTERFACE_CLASS()
info_msg.clear(); info_msg.clear();
error_msg.clear(); error_msg.clear();
status_msg.clear(); status_msg.clear();
fileslist.clear();
} }
WEBINTERFACE_CLASS * web_interface; WEBINTERFACE_CLASS * web_interface;

View File

@ -45,6 +45,7 @@ class WEBINTERFACE_CLASS
String answer4M114; String answer4M114;
String answer4M220; String answer4M220;
String answer4M221; String answer4M221;
STORESTRINGS_CLASS fileslist;
uint32_t last_temp; uint32_t last_temp;
STORESTRINGS_CLASS error_msg; STORESTRINGS_CLASS error_msg;
STORESTRINGS_CLASS info_msg; STORESTRINGS_CLASS info_msg;