From 7fcb0bdbee780b1bb26689b7c7281e2cb12df297 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Thu, 28 May 2020 13:42:18 +0200 Subject: [PATCH] Fix FS timestamp not working Fix FS commands with incomplete root Fix slow time set at start if no need time server Update debug message in Flash FS Fix FATFS / LittleFS bugs --- esp3d/src/core/espcmd/ESP720.cpp | 8 +- esp3d/src/include/version.h | 2 +- .../filesystem/flash/fat_esp32_filesystem.cpp | 110 +++++++----------- .../flash/littlefs_esp8266_filesystem .cpp | 56 ++++----- .../flash/spiffs_esp32_filesystem.cpp | 33 ++++-- .../flash/spiffs_esp8266_filesystem.cpp | 38 +++--- .../src/modules/http/handles/handle-files.cpp | 11 +- .../src/modules/http/handles/upload-files.cpp | 4 + esp3d/src/modules/time/time_server.cpp | 11 +- 9 files changed, 131 insertions(+), 142 deletions(-) diff --git a/esp3d/src/core/espcmd/ESP720.cpp b/esp3d/src/core/espcmd/ESP720.cpp index 1d41f001..3aae4b85 100644 --- a/esp3d/src/core/espcmd/ESP720.cpp +++ b/esp3d/src/core/espcmd/ESP720.cpp @@ -24,6 +24,10 @@ #include "../settings_esp3d.h" #include "../../modules/authentication/authentication_service.h" #include "../../modules/filesystem/esp_filesystem.h" +#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#include "../../modules/time/time_server.h" +#endif //FILESYSTEM_TIMESTAMP_FEATURE + //List ESP Filesystem //[ESP720] pwd= bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) @@ -75,9 +79,7 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, output->print(ESP_FileSystem::formatBytes(sub.size()).c_str()); output->print(" \t"); #ifdef FILESYSTEM_TIMESTAMP_FEATURE - time_t t = sub.getLastWrite(); - struct tm * tmstruct = localtime(&t); - output->printf("%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + output->print(timeserver.current_time(sub.getLastWrite())); output->print(" \t"); #endif //FILESYSTEM_TIMESTAMP_FEATURE output->printLN(""); diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 7863489a..cc4df291 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.a40" +#define FW_VERSION "3.0.0.a41" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp index 535a7cd8..ac75266f 100644 --- a/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/fat_esp32_filesystem.cpp @@ -70,26 +70,26 @@ bool ESP_FileSystem::format() ESP_File ESP_FileSystem::open(const char* path, uint8_t mode) { + log_esp3d("open %s", path); //do some check if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) { + log_esp3d("reject %s", path); return ESP_File(); } // path must start by '/' if (path[0] != '/') { + log_esp3d("%s is invalid path", path); return ESP_File(); } - if (mode != ESP_FILE_READ) { - //check container exists - String p = path; - p.remove(p.lastIndexOf('/') +1); - if (!exists(p.c_str())) { - log_esp3d("Error opening: %s", path); - return ESP_File(); - } - } File tmp = FFat.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND); - ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); - return esptmp; + if(tmp) { + ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); + log_esp3d("%s is a %s", path,tmp.isDirectory()?"Dir":"File"); + return esptmp; + } else { + log_esp3d("open %s failed", path); + return ESP_File(); + } } bool ESP_FileSystem::exists(const char* path) @@ -105,6 +105,7 @@ bool ESP_FileSystem::exists(const char* path) if (root) { res = root.isDirectory(); } + root.close(); } return res; } @@ -116,17 +117,35 @@ bool ESP_FileSystem::remove(const char *path) bool ESP_FileSystem::mkdir(const char *path) { - return FFat.mkdir(path); + String p = path; + if(p[0]!='/') { + p="/"+p; + } + if (p[p.length()-1] == '/') { + if (p!="/") { + p.remove(p.length()-1); + } + } + return FFat.mkdir(p); } bool ESP_FileSystem::rmdir(const char *path) { - if (!exists(path)) { + String p = path; + if(p[0]!='/') { + p="/"+p; + } + if (p[p.length()-1] == '/') { + if (p!="/") { + p.remove(p.length()-1); + } + } + + if (!exists(p.c_str())) { return false; } bool res = true; GenLinkedList pathlist; - String p = path; pathlist.push(p); while (pathlist.count() > 0) { File dir = FFat.open(pathlist.getLast().c_str()); @@ -178,6 +197,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _iswritemode = iswritemode; _size = 0; if (!handle) { + log_esp3d("No handle"); return ; } bool set =false; @@ -186,29 +206,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path tFile_handle[i] = *((File*)handle); //filename _filename = tFile_handle[i].name(); - - //if root - if (_filename == "/") { - _filename = "/."; - } - if (_isdir) { - if (_filename[_filename.length()-1] != '.') { - if (_filename[_filename.length()-2] != '/') { - _filename+="/"; - } - _filename+="."; - } - } //name - if (_filename == "/.") { + if (_filename == "/") { _name = "/"; } else { _name = _filename; - if (_name.endsWith("/.")) { - _name.remove( _name.length() - 2,2); - _isfakedir = true; - _isdir = true; - } if (_name[0] == '/') { _name.remove( 0, 1); } @@ -222,16 +224,21 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path //time _lastwrite = tFile_handle[i].getLastWrite(); _index = i; - //log_esp3d("Opening File at index %d",_index); + log_esp3d("Opening File at index %d",_index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } + if(!set) { + log_esp3d("No handle available"); + } } void ESP_File::close() { if (_index != -1) { - //log_esp3d("Closing File at index %d", _index); + log_esp3d("Closing File at index %d", _index); tFile_handle[_index].close(); //reopen if mode = write //udate size + date @@ -244,7 +251,6 @@ void ESP_File::close() } } tFile_handle[_index] = File(); - //log_esp3d("Closing File at index %d",_index); _index = -1; } } @@ -252,7 +258,7 @@ void ESP_File::close() ESP_File ESP_File::openNextFile() { if ((_index == -1) || !_isdir) { - log_esp3d("openNextFile failed"); + log_esp3d("openNextFile %d failed", _index); return ESP_File(); } File tmp = tFile_handle[_index].openNextFile(); @@ -260,35 +266,7 @@ ESP_File ESP_File::openNextFile() log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile"); ESP_File esptmp(&tmp, tmp.isDirectory()); esptmp.close(); - String sub = esptmp.filename(); - sub.remove(0,_filename.length()-1); - int pos = sub.indexOf("/"); - if (pos!=-1) { - //is subdir - sub = sub.substring(0,pos); - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); - String tag = "*" + sub + "*"; - //test if already in directory list - if (_dirlist.indexOf(tag) == -1) {//not in list so add it and return the info - _dirlist+= tag; - String fname = _filename.substring(0,_filename.length()-1) + sub + "/."; - //log_esp3d("Found dir name: %s filename:%s", sub.c_str(), fname.c_str()); - esptmp = ESP_File(sub.c_str(), fname.c_str()); - return esptmp; - } else { //already in list so ignore it - //log_esp3d("Dir name: %s already in list", sub.c_str()); - tmp = tFile_handle[_index].openNextFile(); - } - } else { //is file - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); - if (sub == ".") { - //log_esp3d("Dir tag, ignore it"); - tmp = tFile_handle[_index].openNextFile(); - } else { - return esptmp; - } - } - + return esptmp; } return ESP_File(); } diff --git a/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp b/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp index 26e20eab..7c7516d7 100644 --- a/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp +++ b/esp3d/src/modules/filesystem/flash/littlefs_esp8266_filesystem .cpp @@ -120,7 +120,12 @@ bool ESP_FileSystem::exists(const char* path) bool ESP_FileSystem::remove(const char *path) { - return LittleFS.remove(path); + String p = path; + if(p[0]!='/') { + p="/"+p; + } + log_esp3d("delete %s", p.c_str()); + return LittleFS.remove(p); } bool ESP_FileSystem::mkdir(const char *path) @@ -132,6 +137,9 @@ bool ESP_FileSystem::mkdir(const char *path) spath.remove(spath.length()-1); } } + if (spath[0]!='/') { + spath = "/"+spath; + } return LittleFS.mkdir(spath.c_str()); } @@ -205,6 +213,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _iswritemode = iswritemode; _size = 0; if (!handle) { + log_esp3d("No handle"); return ; } bool set =false; @@ -220,7 +229,6 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path if (!((_filename[_filename.length()-1] == '/') || (_filename == "/"))) { _filename+="/"; } - //log_esp3d("Filename: %s", _filename.c_str()); //Name if (_filename == "/") { _name = "/"; @@ -228,7 +236,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _name.remove( 0, _name.lastIndexOf('/')+1); } } - //log_esp3d("Name: %s index: %d", _name.c_str(), _index); + log_esp3d("Dir: %s index: %d", _name.c_str(), _index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } @@ -239,33 +249,17 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path if (!tFile_handle[i]) { tFile_handle[i] = *((File*)handle); //filename - _filename = tFile_handle[i].name(); - if (_isdir) { - if (!((_filename[_filename.length()-1] == '/') || (_filename == "/"))) { - _filename+="/"; - } - } + _filename = tFile_handle[i].fullName(); //name - if (_filename == "/") { - _name = "/"; - } else { - _name = _filename; - if (_name[0] == '/') { - _name.remove( 0, 1); - } - int pos = _name.lastIndexOf('/'); - if (pos != -1) { - _name.remove( 0, pos+1); - } - } + _name = tFile_handle[i].name(); //size _size = tFile_handle[i].size(); //time - //TODO - not yet implemented in esp core - //_lastwrite = tFile_handle[i].getLastWrite(); - _lastwrite = 0; + _lastwrite = tFile_handle[i].getLastWrite(); _index = i; - //log_esp3d("Opening File at index %d",_index); + log_esp3d("Opening File at index %d",_index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } @@ -275,26 +269,26 @@ void ESP_File::close() { if (_index != -1) { if (_isdir) { - //log_esp3d("Closing Dir at index %d", _index); + log_esp3d("Closing Dir at index %d", _index); tDir_handle[_index] = Dir(); _index = -1; return; } - //log_esp3d("Closing File at index %d", _index); + log_esp3d("Closing File at index %d", _index); + log_esp3d("Size is %d", tFile_handle[_index].size()); tFile_handle[_index].close(); //reopen if mode = write //udate size + date if (_iswritemode && !_isdir) { + log_esp3d("Updating Size of %s",_filename.c_str()); File ftmp = LittleFS.open(_filename.c_str(), "r"); if (ftmp) { _size = ftmp.size(); - //TODO - not yet implemented in esp core - //_lastwrite = ftmp.getLastWrite(); - _lastwrite = 0; + log_esp3d("Updating Size to %d", ftmp.size()); + _lastwrite = ftmp.getLastWrite(); ftmp.close(); } } - //log_esp3d("Closing File at index %d",_index); _index = -1; } } diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp index 50a2c853..7d2a6701 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp @@ -78,8 +78,14 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode) } //TODO add support if path = /DIR1/ <- with last / File tmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND); - ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); - return esptmp; + if(tmp) { + ESP_File esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path); + log_esp3d("%s is a %s", path,tmp.isDirectory()?"Dir":"File"); + return esptmp; + } else { + log_esp3d("open %s failed", path); + return ESP_File(); + } } bool ESP_FileSystem::exists(const char* path) @@ -103,7 +109,7 @@ bool ESP_FileSystem::exists(const char* path) newpath+="/"; } newpath+="."; - //log_esp3d("Check %s", newpath.c_str()); + log_esp3d("Check %s", newpath.c_str()); res = SPIFFS.exists(newpath); if (!res) { ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ); @@ -123,7 +129,11 @@ bool ESP_FileSystem::exists(const char* path) bool ESP_FileSystem::remove(const char *path) { - return SPIFFS.remove(path); + String p = path; + if(p[0]!='/') { + p="/"+p; + } + return SPIFFS.remove(p); } bool ESP_FileSystem::mkdir(const char *path) @@ -134,7 +144,7 @@ bool ESP_FileSystem::mkdir(const char *path) p+="/"; } p+="."; - //log_esp3d("Dir create : %s", p.c_str()); + log_esp3d("Dir create : %s", p.c_str()); ESP_File f = open(p.c_str(), ESP_FILE_WRITE); if (f) { f.close(); @@ -148,6 +158,9 @@ bool ESP_FileSystem::rmdir(const char *path) { String spath = path; spath.trim(); + if(spath[0]!='/') { + spath="/"+spath; + } if (spath[spath.length()-1] == '/') { if (spath!="/") { spath.remove(spath.length()-1); @@ -158,7 +171,7 @@ bool ESP_FileSystem::rmdir(const char *path) if (ftmp) { File pfile = ftmp.openNextFile(); while (pfile) { - //log_esp3d("File: %s",pfile.name()); + log_esp3d("File: %s",pfile.name()); if (!SPIFFS.remove(pfile.name())) { pfile.close(); return false; @@ -193,6 +206,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _iswritemode = iswritemode; _size = 0; if (!handle) { + log_esp3d("No handle"); return ; } bool set =false; @@ -237,7 +251,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path //time _lastwrite = tFile_handle[i].getLastWrite(); _index = i; - //log_esp3d("Opening File at index %d",_index); + log_esp3d("Opening File at index %d",_index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } @@ -246,7 +262,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path void ESP_File::close() { if (_index != -1) { - //log_esp3d("Closing File at index %d", _index); + log_esp3d("Closing File at index %d", _index); tFile_handle[_index].close(); //reopen if mode = write //udate size + date @@ -259,7 +275,6 @@ void ESP_File::close() } } tFile_handle[_index] = File(); - //log_esp3d("Closing File at index %d",_index); _index = -1; } } diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp index ea5968c8..7bf35162 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp @@ -82,13 +82,14 @@ ESP_File ESP_FileSystem::open(const char* path, uint8_t mode) } File ftmp = SPIFFS.open(path, (mode == ESP_FILE_READ)?"r":(mode == ESP_FILE_WRITE)?"w":"a"); if(ftmp) { - //log_esp3d("Success openening: %s", path); + log_esp3d("Success openening file: %s", path); ESP_File esptmp(&ftmp, false,(mode == ESP_FILE_READ)?false:true, path); return esptmp; } (void)mode; Dir dtmp = SPIFFS.openDir(path); ESP_File esptmp(&dtmp, true, false, path); + log_esp3d("Success openening dir: %s", path); return esptmp; } @@ -113,7 +114,7 @@ bool ESP_FileSystem::exists(const char* path) newpath+="/"; } newpath+="."; - //log_esp3d("Check %s", newpath.c_str()); + log_esp3d("Check %s", newpath.c_str()); res = SPIFFS.exists(newpath); if (!res) { ESP_File f = ESP_FileSystem::open(path, ESP_FILE_READ); @@ -133,7 +134,11 @@ bool ESP_FileSystem::exists(const char* path) bool ESP_FileSystem::remove(const char *path) { - return SPIFFS.remove(path); + String p = path; + if(p[0]!='/') { + p="/"+p; + } + return SPIFFS.remove(p); } bool ESP_FileSystem::mkdir(const char *path) @@ -144,7 +149,7 @@ bool ESP_FileSystem::mkdir(const char *path) p+="/"; } p+="."; - //log_esp3d("Dir create : %s", p.c_str()); + log_esp3d("Dir create : %s", p.c_str()); ESP_File f = open(p.c_str(), ESP_FILE_WRITE); if (f) { f.close(); @@ -157,6 +162,7 @@ bool ESP_FileSystem::mkdir(const char *path) bool ESP_FileSystem::rmdir(const char *path) { Dir dtmp = SPIFFS.openDir(path); + log_esp3d("Deleting : %s",path); while (dtmp.next()) { if (!SPIFFS.remove(dtmp.fileName().c_str())) { return false; @@ -186,6 +192,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _iswritemode = iswritemode; _size = 0; if (!handle) { + log_esp3d("No handle"); return ; } bool set =false; @@ -206,7 +213,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path } _filename+="."; } - //log_esp3d("Filename: %s", _filename.c_str()); + log_esp3d("Filename: %s", _filename.c_str()); //Name if (_filename == "/.") { _name = "/"; @@ -220,7 +227,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path _name.remove( 0, _name.lastIndexOf('/')+1); } } - //log_esp3d("Name: %s index: %d", _name.c_str(), _index); + log_esp3d("Dir: %s index: %d", _name.c_str(), _index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } @@ -265,11 +274,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path //size _size = tFile_handle[i].size(); //time - //TODO - not yet implemented in esp core - //_lastwrite = tFile_handle[i].getLastWrite(); - _lastwrite = 0; + _lastwrite = tFile_handle[i].getLastWrite(); _index = i; - //log_esp3d("Opening File at index %d",_index); + log_esp3d("Opening File at index %d",_index); + log_esp3d("name: %s", _name.c_str()); + log_esp3d("filename: %s", _filename.c_str()); set = true; } } @@ -279,12 +288,12 @@ void ESP_File::close() { if (_index != -1) { if (_isdir && !_isfakedir) { - //log_esp3d("Closing Dir at index %d", _index); + log_esp3d("Closing Dir at index %d", _index); tDir_handle[_index] = Dir(); _index = -1; return; } - //log_esp3d("Closing File at index %d", _index); + log_esp3d("Closing File at index %d", _index); tFile_handle[_index].close(); //reopen if mode = write //udate size + date @@ -292,13 +301,10 @@ void ESP_File::close() File ftmp = SPIFFS.open(_filename.c_str(), "r"); if (ftmp) { _size = ftmp.size(); - //TODO - Not yet available in esp core - //_lastwrite = ftmp.getLastWrite(); - _lastwrite = 0; + _lastwrite = ftmp.getLastWrite(); ftmp.close(); } } - //log_esp3d("Closing File at index %d",_index); _index = -1; } } diff --git a/esp3d/src/modules/http/handles/handle-files.cpp b/esp3d/src/modules/http/handles/handle-files.cpp index 77fc86f8..6d4c6fd9 100644 --- a/esp3d/src/modules/http/handles/handle-files.cpp +++ b/esp3d/src/modules/http/handles/handle-files.cpp @@ -28,6 +28,9 @@ #endif //ARDUINO_ARCH_ESP8266 #include "../../filesystem/esp_filesystem.h" #include "../../authentication/authentication_service.h" +#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#include "../../time/time_server.h" +#endif //FILESYSTEM_TIMESTAMP_FEATURE //Filesystem //Filesystem files list and file commands void HTTP_Server::handleFSFileList () @@ -111,7 +114,7 @@ void HTTP_Server::handleFSFileList () //create a directory if (_webserver->arg ("action") == "createdir" && _webserver->hasArg ("filename") ) { String filename; - filename = path + _webserver->arg ("filename") + "/."; + filename = path + _webserver->arg ("filename"); String shortname = _webserver->arg ("filename"); shortname.replace ("/", ""); filename.replace ("//", "/"); @@ -161,11 +164,7 @@ void HTTP_Server::handleFSFileList () } #ifdef FILESYSTEM_TIMESTAMP_FEATURE buffer2send+="\",\"time\":\""; - time_t t = sub.getLastWrite(); - struct tm * tmstruct = localtime(&t); - char str[20]; //buffer should be 20 - sprintf(str,"%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); - buffer2send+=str; + buffer2send+=timeserver.current_time(sub.getLastWrite()); #endif //FILESYSTEM_TIMESTAMP_FEATURE buffer2send+="\"}"; if (buffer2send.length() > 1100) { diff --git a/esp3d/src/modules/http/handles/upload-files.cpp b/esp3d/src/modules/http/handles/upload-files.cpp index b3ca7726..92cdf06a 100644 --- a/esp3d/src/modules/http/handles/upload-files.cpp +++ b/esp3d/src/modules/http/handles/upload-files.cpp @@ -99,6 +99,7 @@ void HTTP_Server::FSFileupload () } //Upload end } else if(upload.status == UPLOAD_FILE_END) { + log_esp3d("upload end"); //check if file is still open if(fsUploadFile) { //close it @@ -109,7 +110,9 @@ void HTTP_Server::FSFileupload () uint32_t filesize = fsUploadFile.size(); _upload_status = UPLOAD_STATUS_SUCCESSFUL; if (_webserver->hasArg (sizeargname.c_str()) ) { + log_esp3d("Size check: %s vs %s", _webserver->arg (sizeargname.c_str()).c_str(), String(filesize).c_str()); if (_webserver->arg (sizeargname.c_str()) != String(filesize)) { + log_esp3d("Size Error"); _upload_status = UPLOAD_STATUS_FAILED; pushError(ESP_ERROR_SIZE, "File upload failed"); } @@ -119,6 +122,7 @@ void HTTP_Server::FSFileupload () } } else { //we have a problem set flag UPLOAD_STATUS_FAILED + log_esp3d("Close Error"); _upload_status=UPLOAD_STATUS_FAILED; pushError(ESP_ERROR_FILE_CLOSE, "File close failed"); } diff --git a/esp3d/src/modules/time/time_server.cpp b/esp3d/src/modules/time/time_server.cpp index d4077455..40965195 100644 --- a/esp3d/src/modules/time/time_server.cpp +++ b/esp3d/src/modules/time/time_server.cpp @@ -88,7 +88,7 @@ bool TimeServer::begin() } #endif //ETH_FEATURE if (!is_internet_time()) { - return false; + return true; } s1 = Settings_ESP3D::read_string (ESP_TIME_SERVER1); s2 = Settings_ESP3D::read_string (ESP_TIME_SERVER2); @@ -125,13 +125,6 @@ const char * TimeServer::current_time(time_t t) time(&now); localtime_r(&now, &tmstruct); } else { - /* struct tm * tmstructtmp = localtime(&t); - tmstruct.tm_year = tmstructtmp->tm_year; - tmstruct.tm_mon = tmstructtmp->tm_mon; - tmstruct.tm_mday = tmstructtmp->tm_mday; - tmstruct.tm_hour = tmstructtmp->tm_hour; - tmstruct.tm_min = tmstructtmp->tm_min; - tmstruct.tm_sec = tmstructtmp->tm_sec;*/ localtime_r(&t, &tmstruct); } stmp = String((tmstruct.tm_year)+1900) + "-"; @@ -231,8 +224,6 @@ bool TimeServer::setTime(const char* stime) return false; } tmstruct.tm_isdst = 0; //ignore dst - //reset servers, time zone and dst - configTime (0, 0,"", "", ""); tmstruct.tm_sec = substmp.toInt(); time_val.tv_sec = mktime (&tmstruct); if(settimeofday(&time_val,0) == -1) {