diff --git a/esp3d/src/core/espcmd/ESP420.cpp b/esp3d/src/core/espcmd/ESP420.cpp index 765511a4..d46b00c4 100644 --- a/esp3d/src/core/espcmd/ESP420.cpp +++ b/esp3d/src/core/espcmd/ESP420.cpp @@ -1232,11 +1232,13 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type, output->printLN(""); } #endif //ESP_DEBUG_FEATURE - + //Target Firmware if (!plain) { output->print (",{\"id\":\"targetfw"); - } else output->print ("Target Fw"); + } else { + output->print ("Target Fw"); + } if (!plain) { output->print ("\",\"value\":\""); } else { diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 5bd46fef..9d0d4de7 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a48" +#define FW_VERSION "3.0.0.a49" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/http/handles/handle-SD-files.cpp b/esp3d/src/modules/http/handles/handle-SD-files.cpp index 6c281ad2..87560211 100644 --- a/esp3d/src/modules/http/handles/handle-SD-files.cpp +++ b/esp3d/src/modules/http/handles/handle-SD-files.cpp @@ -198,7 +198,11 @@ void HTTP_Server::handleSDFileList () buffer2send += "],\"path\":\"" + path + "\","; if (ESP_SD::totalBytes()>0) { - buffer2send += "\"occupation\":\"" + String(100.0*ESP_SD::usedBytes()/ESP_SD::totalBytes()) + "\","; + float occupation = 100.0*ESP_SD::usedBytes()/ESP_SD::totalBytes(); + if ((occupation < 1) && (ESP_SD::usedBytes()>0)) { + occupation=1; + } + buffer2send += "\"occupation\":\"" + String((int)round(occupation)) + "\","; } else { status = "SD Error"; buffer2send += "\"occupation\":\"0\","; diff --git a/esp3d/src/modules/http/handles/handle-filenotfound.cpp b/esp3d/src/modules/http/handles/handle-filenotfound.cpp index b294bd66..5c252fac 100644 --- a/esp3d/src/modules/http/handles/handle-filenotfound.cpp +++ b/esp3d/src/modules/http/handles/handle-filenotfound.cpp @@ -28,6 +28,9 @@ #endif //ARDUINO_ARCH_ESP8266 #include "../../filesystem/esp_filesystem.h" #include "../../authentication/authentication_service.h" +#if defined(SD_DEVICE) +#include "../../filesystem/esp_sd.h" +#endif //SD_DEVICE //Handle not registred path on FS neither SD /////////////////////// void HTTP_Server:: handle_not_found() @@ -52,6 +55,23 @@ void HTTP_Server:: handle_not_found() } #endif //#if defined (FILESYSTEM_FEATURE) +#if defined (SD_DEVICE) + if (path.startsWith("/sd/")) { + path = path.substring(3); + pathWithGz = path + ".gz"; + if(ESP_SD::exists(pathWithGz.c_str()) || ESP_SD::exists(path.c_str())) { + if(ESP_SD::exists(pathWithGz.c_str())) { + _webserver->sendHeader("Content-Encoding", "gzip"); + path = pathWithGz; + } + if(!StreamSDFile(path.c_str(),contentType.c_str())) { + log_esp3d("Stream `%s` failed", path.c_str()); + } + return; + } + } +#endif //#if defined (SD_DEVICE) + #ifdef FILESYSTEM_FEATURE //check local page path = "/404.htm"; @@ -71,32 +91,5 @@ void HTTP_Server:: handle_not_found() //let's keep simple just send minimum _webserver->send(404); - /* - - #ifdef ENABLE_SD_CARD - if ((path.substring(0,4) == "/SD/")) { - //remove /SD - path = path.substring(3); - if(SD.exists((char *)pathWithGz.c_str()) || SD.exists((char *)path.c_str())) { - if(SD.exists((char *)pathWithGz.c_str())) { - path = pathWithGz; - } - File datafile = SD.open((char *)path.c_str()); - if (datafile) { - if( _webserver->streamFile(datafile, contentType) == datafile.size()) { - datafile.close(); - COMMANDS::wait(0); - return; - } else{ - datafile.close(); - } - } - } - String content = "cannot find "; - content+=path; - _webserver->send(404,"text/plain",content.c_str()); - return; - } else - #endif*/ } #endif //HTTP_FEATURE diff --git a/esp3d/src/modules/http/handles/upload-SD-files.cpp b/esp3d/src/modules/http/handles/upload-SD-files.cpp index b3ef0ce8..0f842228 100644 --- a/esp3d/src/modules/http/handles/upload-SD-files.cpp +++ b/esp3d/src/modules/http/handles/upload-SD-files.cpp @@ -131,10 +131,6 @@ void HTTP_Server::SDFileupload () _upload_status=UPLOAD_STATUS_FAILED; pushError(ESP_ERROR_FILE_CLOSE, "File close failed"); } - Serial.print(filesize); - Serial.print(" B in "); - Serial.print((millis()-timecheck) / 1000); - Serial.println(" sec"); //Upload cancelled } else { if (_upload_status == UPLOAD_STATUS_ONGOING) { diff --git a/esp3d/src/modules/http/http_server.cpp b/esp3d/src/modules/http/http_server.cpp index 2a14d811..979c3fce 100644 --- a/esp3d/src/modules/http/http_server.cpp +++ b/esp3d/src/modules/http/http_server.cpp @@ -33,7 +33,10 @@ #include "../../core/settings_esp3d.h" #include "../filesystem/esp_filesystem.h" #include "../websocket/websocket_server.h" +#if defined(SD_DEVICE) +#include "../filesystem/esp_sd.h" +#endif //SD_DEVICE bool HTTP_Server::_started = false; uint16_t HTTP_Server::_port = 0; WEBSERVER * HTTP_Server::_webserver = nullptr; @@ -97,7 +100,7 @@ bool HTTP_Server::StreamFSFile(const char* filename, const char * contentType) _webserver->setContentLength(totalFileSize); _webserver->send(200, contentType, ""); uint8_t buf[1024]; - while (!done) { + while (!done && _webserver->client().connected()) { Hal::wait(0); int v = datafile.read(buf,1024); if ((v == -1) || (v == 0)) { @@ -117,6 +120,41 @@ bool HTTP_Server::StreamFSFile(const char* filename, const char * contentType) return true; } +#if defined (SD_DEVICE) +bool HTTP_Server::StreamSDFile(const char* filename, const char * contentType) +{ + ESP_SDFile datafile = ESP_SD::open(filename); + if (!datafile) { + return false; + } + size_t totalFileSize = datafile.size(); + size_t i = 0; + bool done = false; + _webserver->setContentLength(totalFileSize); + _webserver->send(200, contentType, ""); + uint8_t buf[1024]; + while (!done && _webserver->client().connected()) { + Hal::wait(0); + int v = datafile.read(buf,1024); + if ((v == -1) || (v == 0)) { + done = true; + } else { + _webserver->client().write(buf,v); + Serial.print("."); + i+=v; + } + if (i >= totalFileSize) { + done = true; + } + } + datafile.close(); + if ( i != totalFileSize) { + return false; + } + return true; +} +#endif //SD_DEVICE + void HTTP_Server::pushError(int code, const char * st, bool web_error, uint16_t timeout) { if (websocket_terminal_server.started() && st) { diff --git a/esp3d/src/modules/http/http_server.h b/esp3d/src/modules/http/http_server.h index 7b620887..3c989068 100644 --- a/esp3d/src/modules/http/http_server.h +++ b/esp3d/src/modules/http/http_server.h @@ -90,6 +90,7 @@ private: #ifdef SD_DEVICE static void SDFileupload (); static void handleSDFileList (); + static bool StreamSDFile(const char* filename, const char * contentType); #endif //SD_DEVICE };