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,8 +66,18 @@ 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;
if (!bfileslist)
{
int filesstart = buffer.indexOf("Begin file list");
if (filesstart>-1)
{
Serial.print("Starting");
start_list=system_get_time();
bfileslist=true;
web_interface->fileslist.clear();
}
int ESPpos = buffer.indexOf("[ESP"); int ESPpos = buffer.indexOf("[ESP");
int Tpos = buffer.indexOf("T:"); int Tpos = buffer.indexOf("T:");
int Xpos = buffer.indexOf("X:"); int Xpos = buffer.indexOf("X:");
@ -121,6 +131,29 @@ void COMMAND::check_command(String buffer)
//Status //Status
if (Statuspos>-1)(web_interface->status_msg).add(buffer.substring(Statuspos+7).c_str()); 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);
}
}
}
}
//read a buffer in an array //read a buffer in an array
void COMMAND::read_buffer_serial(uint8_t *b, size_t len) void COMMAND::read_buffer_serial(uint8_t *b, size_t len)

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;