mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 14:18:57 +08:00
Fix SD File listing incomplete as still processing
Separate M20 command from file listing to give time to get the complete file list before sending the list Change SDK function system_get_time and wifi_get_opmode to use wrapper ones and avoid to include user_interface.h if not necessary
This commit is contained in:
parent
41d319bed8
commit
3d92f78eca
@ -22,9 +22,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "webinterface.h"
|
#include "webinterface.h"
|
||||||
extern "C" {
|
|
||||||
#include "user_interface.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
String COMMAND::buffer_serial;
|
String COMMAND::buffer_serial;
|
||||||
String COMMAND::buffer_tcp;
|
String COMMAND::buffer_tcp;
|
||||||
@ -81,7 +78,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
break;
|
break;
|
||||||
case 111: {
|
case 111: {
|
||||||
String currentIP ;
|
String currentIP ;
|
||||||
if (wifi_get_opmode()==WIFI_STA) {
|
if (WiFi.getMode()==WIFI_STA) {
|
||||||
currentIP=WiFi.localIP().toString();
|
currentIP=WiFi.localIP().toString();
|
||||||
} else {
|
} else {
|
||||||
currentIP=WiFi.softAPIP().toString();
|
currentIP=WiFi.softAPIP().toString();
|
||||||
@ -141,7 +138,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
//yes it is file list starting to be displayed
|
//yes it is file list starting to be displayed
|
||||||
if (filesstart>-1) {
|
if (filesstart>-1) {
|
||||||
//init time out
|
//init time out
|
||||||
start_list=system_get_time();
|
start_list = millis();
|
||||||
//set file list started
|
//set file list started
|
||||||
bfileslist=true;
|
bfileslist=true;
|
||||||
//clear current list
|
//clear current list
|
||||||
@ -198,7 +195,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
//if match mask T:xxx.xx /xxx.xx
|
//if match mask T:xxx.xx /xxx.xx
|
||||||
if(spacepos-Tpos < 17) {
|
if(spacepos-Tpos < 17) {
|
||||||
web_interface->answer4M105=buffer; //do not interprete just need when requested so store it
|
web_interface->answer4M105=buffer; //do not interprete just need when requested so store it
|
||||||
web_interface->last_temp=system_get_time();
|
web_interface->last_temp=millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Position of axis
|
//Position of axis
|
||||||
@ -248,18 +245,24 @@ void COMMAND::check_command(String buffer)
|
|||||||
}
|
}
|
||||||
} else { //listing file is on going
|
} else { //listing file is on going
|
||||||
//check if we are too long
|
//check if we are too long
|
||||||
if ((system_get_time()-start_list)>30000000) { //timeout in case of problem
|
if ((millis()-start_list)>30000) { //timeout in case of problem
|
||||||
bfileslist=false;
|
bfileslist=false;
|
||||||
(web_interface->blockserial) = false; //release serial
|
(web_interface->blockserial) = false; //release serial
|
||||||
|
LOG("Time out\n");
|
||||||
} else {
|
} else {
|
||||||
//check if this is the end
|
//check if this is the end
|
||||||
if (buffer.indexOf("End file list")>-1) {
|
if (buffer.indexOf("End file list")>-1) {
|
||||||
bfileslist=false;
|
bfileslist=false;
|
||||||
(web_interface->blockserial) = false;
|
(web_interface->blockserial) = false;
|
||||||
|
LOG("End list\n");
|
||||||
} else {
|
} else {
|
||||||
//Serial.print(buffer);
|
//Serial.print(buffer);
|
||||||
//add list to buffer
|
//add list to buffer
|
||||||
web_interface->fileslist.add(buffer);
|
web_interface->fileslist.add(buffer);
|
||||||
|
LOG(String(web_interface->fileslist.size()));
|
||||||
|
LOG(":");
|
||||||
|
LOG(buffer);
|
||||||
|
LOG('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +318,7 @@ void COMMAND::read_buffer_serial(uint8_t b)
|
|||||||
previous_was_char=false; //next call will reset the buffer
|
previous_was_char=false; //next call will reset the buffer
|
||||||
}
|
}
|
||||||
//this is not printable but end of command check if need to handle it
|
//this is not printable but end of command check if need to handle it
|
||||||
if (b==13 ||b==10) {
|
if (b==13) {
|
||||||
//Minimum is something like M10 so 3 char
|
//Minimum is something like M10 so 3 char
|
||||||
if (buffer_serial.length()>3) {
|
if (buffer_serial.length()>3) {
|
||||||
check_command(buffer_serial);
|
check_command(buffer_serial);
|
||||||
|
@ -65,7 +65,7 @@ $INCLUDE[css2.inc]$
|
|||||||
<rect x="10" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /> <rect x="23" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
<rect x="10" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /> <rect x="23" y="10" width="7" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
||||||
<td class="btnimg" onclick="Sendcommand('M50');"><svg width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" stroke="black" stroke-width="2" fill="white" />
|
<td class="btnimg" onclick="Sendcommand('M50');"><svg width="40" height="40" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" stroke="black" stroke-width="2" fill="white" />
|
||||||
<rect x="10" y="10" width="20" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
<rect x="10" y="10" width="20" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /></svg></td>
|
||||||
<td class="btnimg" onclick="getSDfiles();"><svg width="40" height="40" viewBox="0 0 40 40"><rect x="5" y="10" width="30" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" />
|
<td class="btnimg" onclick="refreshSDfiles();"><svg width="40" height="40" viewBox="0 0 40 40"><rect x="5" y="10" width="30" height="20" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" />
|
||||||
<rect x="20" y="5" width="15" height="15" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /><text x="10" y="25" font-family="Verdana" font-size="14" fill="white">SD</text></svg></td>
|
<rect x="20" y="5" width="15" height="15" rx="2" ry="2" style="fill:rgb(0,0,0);stroke-width:1;stroke:rgb(0,0,0)" /><text x="10" y="25" font-family="Verdana" font-size="14" fill="white">SD</text></svg></td>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
<td id="SDLIST"></td></tr></table></td></tr>
|
<td id="SDLIST"></td></tr></table></td></tr>
|
||||||
@ -351,13 +351,21 @@ Sendcommand("M23 " + filename);
|
|||||||
delay(100);
|
delay(100);
|
||||||
Sendcommand("M24");}
|
Sendcommand("M24");}
|
||||||
}
|
}
|
||||||
|
var retry = 0;
|
||||||
function refreshfilelist(jsonresponse){
|
function refreshfilelist(jsonresponse){
|
||||||
|
|
||||||
var list2display="<table><tr><td><select class=\"form-control\" id=\"sdfilelist\">";
|
var list2display="<table><tr><td><select class=\"form-control\" id=\"sdfilelist\">";
|
||||||
var content="";
|
var content="";
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < jsonresponse.length; i++){
|
if (jsonresponse.status != "Ok"){
|
||||||
content =jsonresponse[i].entry;
|
delay(1000);
|
||||||
|
retry = retry +1;
|
||||||
|
if (retry < 6) getSDfiles();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
retry = 0;
|
||||||
|
for (i = 0; i < jsonresponse.file.length; i++){
|
||||||
|
content =jsonresponse.file[i].entry;
|
||||||
var tcontent=content.split(" ");
|
var tcontent=content.split(" ");
|
||||||
if ((tcontent.length==2) || (tcontent.length==1 && tcontent[0].indexOf("/")==-1)){
|
if ((tcontent.length==2) || (tcontent.length==1 && tcontent[0].indexOf("/")==-1)){
|
||||||
list2display+="<OPTION value=\"";
|
list2display+="<OPTION value=\"";
|
||||||
@ -381,10 +389,15 @@ list2display+="</td></tr></table>";
|
|||||||
document.getElementById("SDLIST").innerHTML=list2display;
|
document.getElementById("SDLIST").innerHTML=list2display;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSDfiles(){
|
function refreshSDfiles(){
|
||||||
document.getElementById("SDLIST").innerHTML="";
|
document.getElementById("SDLIST").innerHTML="";
|
||||||
Sendcommand("M20");
|
Sendcommand("M20");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
retry = 0;
|
||||||
|
getSDfiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSDfiles(){
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
var url = "/SDFILES";
|
var url = "/SDFILES";
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
@ -555,7 +555,7 @@ void GetIpWeb(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
|||||||
String stmp;
|
String stmp;
|
||||||
|
|
||||||
KeysList.add(FPSTR(KEY_IP));
|
KeysList.add(FPSTR(KEY_IP));
|
||||||
if (wifi_get_opmode() == WIFI_STA ) {
|
if (WiFi.getMode() == WIFI_STA ) {
|
||||||
stmp = WiFi.localIP().toString();
|
stmp = WiFi.localIP().toString();
|
||||||
} else {
|
} else {
|
||||||
stmp = WiFi.softAPIP().toString();
|
stmp = WiFi.softAPIP().toString();
|
||||||
@ -575,11 +575,11 @@ void GetIpWeb(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList)
|
||||||
{
|
{
|
||||||
if (wifi_get_opmode() == WIFI_STA ) {
|
if (WiFi.getMode() == WIFI_STA ) {
|
||||||
KeysList.add(FPSTR(KEY_MODE));
|
KeysList.add(FPSTR(KEY_MODE));
|
||||||
ValuesList.add(FPSTR(VALUE_STA));
|
ValuesList.add(FPSTR(VALUE_STA));
|
||||||
} else {
|
} else {
|
||||||
if (wifi_get_opmode() == WIFI_AP ) {
|
if (WiFi.getMode() == WIFI_AP ) {
|
||||||
KeysList.add(FPSTR(KEY_MODE));
|
KeysList.add(FPSTR(KEY_MODE));
|
||||||
ValuesList.add(FPSTR(VALUE_AP));
|
ValuesList.add(FPSTR(VALUE_AP));
|
||||||
} else {
|
} else {
|
||||||
@ -733,7 +733,7 @@ void handle_web_interface_home()
|
|||||||
GetIpWeb(KeysList, ValuesList);
|
GetIpWeb(KeysList, ValuesList);
|
||||||
|
|
||||||
//Hostname
|
//Hostname
|
||||||
if (wifi_get_opmode()==WIFI_STA ) {
|
if (WiFi.getMode()==WIFI_STA ) {
|
||||||
KeysList.add(FPSTR(KEY_MODE));
|
KeysList.add(FPSTR(KEY_MODE));
|
||||||
ValuesList.add(FPSTR(VALUE_STA));
|
ValuesList.add(FPSTR(VALUE_STA));
|
||||||
KeysList.add(FPSTR(KEY_HOSTNAME));
|
KeysList.add(FPSTR(KEY_HOSTNAME));
|
||||||
@ -745,7 +745,7 @@ void handle_web_interface_home()
|
|||||||
ValuesList.add(FPSTR(KEY_NOT_APPLICABLE_4_AP));
|
ValuesList.add(FPSTR(KEY_NOT_APPLICABLE_4_AP));
|
||||||
KeysList.add(FPSTR(KEY_HOSTNAME_VISIBLE));
|
KeysList.add(FPSTR(KEY_HOSTNAME_VISIBLE));
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN));
|
||||||
if (wifi_get_opmode()==WIFI_AP ) {
|
if (WiFi.getMode()==WIFI_AP ) {
|
||||||
KeysList.add(FPSTR(KEY_MODE));
|
KeysList.add(FPSTR(KEY_MODE));
|
||||||
ValuesList.add(FPSTR(VALUE_AP));
|
ValuesList.add(FPSTR(VALUE_AP));
|
||||||
} else {
|
} else {
|
||||||
@ -801,7 +801,7 @@ void handle_web_interface_home()
|
|||||||
|
|
||||||
//Captive portal Feature
|
//Captive portal Feature
|
||||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||||
if (wifi_get_opmode()==WIFI_AP) {
|
if (WiFi.getMode()==WIFI_AP) {
|
||||||
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS));
|
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS));
|
||||||
ValuesList.add(FPSTR(VALUE_ENABLED));
|
ValuesList.add(FPSTR(VALUE_ENABLED));
|
||||||
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE));
|
KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE));
|
||||||
@ -847,7 +847,7 @@ void handle_web_interface_home()
|
|||||||
GetPorts(KeysList, ValuesList);
|
GetPorts(KeysList, ValuesList);
|
||||||
|
|
||||||
//AP part
|
//AP part
|
||||||
if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) {
|
if (WiFi.getMode()==WIFI_AP || WiFi.getMode()==WIFI_AP_STA) {
|
||||||
int client_counter=0;
|
int client_counter=0;
|
||||||
struct station_info * station;
|
struct station_info * station;
|
||||||
//AP is enabled
|
//AP is enabled
|
||||||
@ -969,7 +969,7 @@ void handle_web_interface_home()
|
|||||||
ValuesList.add(FPSTR(VALUE_NO_IP));
|
ValuesList.add(FPSTR(VALUE_NO_IP));
|
||||||
}
|
}
|
||||||
//STA part
|
//STA part
|
||||||
if (wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA) {
|
if (WiFi.getMode()==WIFI_STA || WiFi.getMode()==WIFI_AP_STA) {
|
||||||
//STA is enabled
|
//STA is enabled
|
||||||
KeysList.add(FPSTR(KEY_STA_STATUS_ENABLED));
|
KeysList.add(FPSTR(KEY_STA_STATUS_ENABLED));
|
||||||
ValuesList.add(FPSTR(VALUE_ENABLED));
|
ValuesList.add(FPSTR(VALUE_ENABLED));
|
||||||
@ -1920,7 +1920,7 @@ void handle_web_interface_configSTA()
|
|||||||
//do we need to do a scan and display it ?
|
//do we need to do a scan and display it ?
|
||||||
if (!msg_alert_success) {
|
if (!msg_alert_success) {
|
||||||
//if in AP mode switch to mixed mode to be able to scan
|
//if in AP mode switch to mixed mode to be able to scan
|
||||||
if (wifi_get_opmode()!=WIFI_STA ) {
|
if (WiFi.getMode()!=WIFI_STA ) {
|
||||||
WiFi.mode(WIFI_AP_STA);
|
WiFi.mode(WIFI_AP_STA);
|
||||||
revertSTA=true;
|
revertSTA=true;
|
||||||
}
|
}
|
||||||
@ -2224,13 +2224,13 @@ void handle_web_interface_status()
|
|||||||
//int temperature,target;
|
//int temperature,target;
|
||||||
|
|
||||||
//request temperature only if no feedback
|
//request temperature only if no feedback
|
||||||
if ((system_get_time()-web_interface->last_temp)>2000000) {
|
if ((millis()-web_interface->last_temp)>120000) {
|
||||||
Serial.println(F("M105"));
|
Serial.println(F("M105"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((system_get_time()-web_interface->last_temp)<3200000) {
|
if ((millis()-web_interface->last_temp)<180000) {
|
||||||
value="Connected";
|
value="Connected";
|
||||||
} else if ((system_get_time()-web_interface->last_temp)<32000000) {
|
} else if ((millis()-web_interface->last_temp)<200000) {
|
||||||
value="Busy";
|
value="Busy";
|
||||||
} else {
|
} else {
|
||||||
value="Offline";
|
value="Offline";
|
||||||
@ -2792,25 +2792,33 @@ void handleSDFileList()
|
|||||||
if (!web_interface->is_authenticated()) {
|
if (!web_interface->is_authenticated()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(web_interface->WebServer.hasArg("action")) {
|
String jsonfile = "{\"status\":\"" ;
|
||||||
if(web_interface->WebServer.arg("action")=="delete" && web_interface->WebServer.hasArg("filename")) {
|
//if action is processing do not build list
|
||||||
String filename;
|
if ((web_interface->blockserial)){
|
||||||
web_interface->urldecode(filename,web_interface->WebServer.arg("filename").c_str());
|
LOG("Wait, blocking\n");
|
||||||
filename = "M30 " + filename;
|
jsonfile+="processing\"}";
|
||||||
//TODO:need a MACRO or helper for this test
|
|
||||||
if((web_interface->blockserial) == false)Serial.println(filename);
|
|
||||||
}
|
}
|
||||||
}
|
else{
|
||||||
String jsonfile = "[";
|
jsonfile+="Ok\",\"file\":[";
|
||||||
|
LOG("No Blocking \n");
|
||||||
|
LOG("JSON File\n");
|
||||||
|
LOG(String(web_interface->fileslist.size()));
|
||||||
|
LOG(" entries\n");
|
||||||
for (int i=0; i<web_interface->fileslist.size(); i++) {
|
for (int i=0; i<web_interface->fileslist.size(); i++) {
|
||||||
if (i>0) {
|
if (i>0) {
|
||||||
jsonfile+=",";
|
jsonfile+=",";
|
||||||
}
|
}
|
||||||
jsonfile+="{\"entry\":\"";
|
jsonfile+="{\"entry\":\"";
|
||||||
jsonfile+=web_interface->fileslist.get(i);
|
jsonfile+=web_interface->fileslist.get(i);
|
||||||
|
LOG(String(i+1));
|
||||||
|
LOG(web_interface->fileslist.get(i));
|
||||||
|
LOG("\n");
|
||||||
jsonfile+="\"}";
|
jsonfile+="\"}";
|
||||||
}
|
}
|
||||||
jsonfile+="]";
|
jsonfile+="]}";
|
||||||
|
LOG("JSON done\n");
|
||||||
|
}
|
||||||
|
|
||||||
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
||||||
web_interface->WebServer.send(200, "application/json", jsonfile);
|
web_interface->WebServer.send(200, "application/json", jsonfile);
|
||||||
web_interface->blockserial = false;
|
web_interface->blockserial = false;
|
||||||
@ -2862,7 +2870,7 @@ void handle_not_found()
|
|||||||
//if not template use default page
|
//if not template use default page
|
||||||
contentType=FPSTR(PAGE_404);
|
contentType=FPSTR(PAGE_404);
|
||||||
String stmp;
|
String stmp;
|
||||||
if (wifi_get_opmode()==WIFI_STA ) {
|
if (WiFi.getMode()==WIFI_STA ) {
|
||||||
stmp=WiFi.localIP().toString();
|
stmp=WiFi.localIP().toString();
|
||||||
} else {
|
} else {
|
||||||
stmp=WiFi.softAPIP().toString();
|
stmp=WiFi.softAPIP().toString();
|
||||||
@ -3152,7 +3160,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
|||||||
answer4M220="100";
|
answer4M220="100";
|
||||||
answer4M221="100";
|
answer4M221="100";
|
||||||
blockserial = false;
|
blockserial = false;
|
||||||
last_temp=system_get_time();
|
last_temp = millis();
|
||||||
restartmodule=false;
|
restartmodule=false;
|
||||||
//rolling list of 4entries 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);
|
||||||
@ -3161,7 +3169,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
|||||||
info_msg.setlength(50);
|
info_msg.setlength(50);
|
||||||
status_msg.setsize(4);
|
status_msg.setsize(4);
|
||||||
status_msg.setlength(50);
|
status_msg.setlength(50);
|
||||||
fileslist.setlength(30);//12 for filename + space + size
|
fileslist.setlength(100);//12 for filename + space + size
|
||||||
fileslist.setsize(70); // 70 files to limite to 2K
|
fileslist.setsize(70); // 70 files to limite to 2K
|
||||||
fsUploadFile=(fs::File)0;
|
fsUploadFile=(fs::File)0;
|
||||||
_head=NULL;
|
_head=NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user