From bbd4ba8d404b7acc6f5ae63717dfe0a2a450a7f2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Mon, 17 Jan 2022 20:40:57 +0100 Subject: [PATCH] Better FTP transfer debug messages #283 --- src/hasp_filesystem.cpp | 11 +++++++-- src/main_arduino.cpp | 10 +++++--- src/sys/svc/hasp_ftp.cpp | 49 +++++++++++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/hasp_filesystem.cpp b/src/hasp_filesystem.cpp index aecee469..7b77ce8c 100644 --- a/src/hasp_filesystem.cpp +++ b/src/hasp_filesystem.cpp @@ -141,15 +141,22 @@ void filesystemUnzip(const char*, const char* filename, uint8_t source) void filesystemInfo() { // Get all information of your SPIFFS + char used[16] = ""; + char total[16] = ""; + #ifdef ESP8266 FSInfo fs_info; HASP_FS.info(fs_info); - Log.verbose(TAG_FILE, "Partition size: total: %d, used: %d", fs_info.totalBytes, fs_info.usedBytes); + Parser::format_bytes(fs_info.usedBytes(), used, sizeof(used)); + Parser::format_bytes(fs_info.totalBytes(), total, sizeof(total)); #endif #ifdef ESP32 - Log.verbose(TAG_FILE, "Partition size: total: %d, used: %d", HASP_FS.totalBytes(), HASP_FS.usedBytes()); + Parser::format_bytes(HASP_FS.usedBytes(), used, sizeof(used)); + Parser::format_bytes(HASP_FS.totalBytes(), total, sizeof(total)); #endif + + Log.verbose(TAG_FILE, "Partition size: used: %s / total: %s", total, used); } void filesystemList() diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index ab759f69..224b490e 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -98,9 +98,9 @@ void setup() httpSetup(); #endif -// #if HASP_USE_CONSOLE > 0 -// consoleSetup(); // the consoleSetup is called in debugSetup -// #endif + // #if HASP_USE_CONSOLE > 0 + // consoleSetup(); // the consoleSetup is called in debugSetup + // #endif #if HASP_USE_TELNET > 0 telnetSetup(); @@ -164,6 +164,10 @@ IRAM_ATTR void loop() /* Runs Every Second */ haspEverySecond(); // sleep timer & statusupdate +#if HASP_USE_FTP > 0 + ftpEverySecond(); +#endif + #if HASP_USE_TELNET > 0 telnetEverySecond(); #endif diff --git a/src/sys/svc/hasp_ftp.cpp b/src/sys/svc/hasp_ftp.cpp index ebaf4851..3bfb2991 100644 --- a/src/sys/svc/hasp_ftp.cpp +++ b/src/sys/svc/hasp_ftp.cpp @@ -22,8 +22,10 @@ extern hasp_http_config_t http_config; FtpServer ftpSrv; // set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial -uint16_t ftpPort = 23; -uint8_t ftpEnabled = true; // Enable telnet debug output +uint16_t ftpPort = 23; +uint8_t ftpEnabled = true; // Enable telnet debug output +size_t transferSize = 0; +const char* transferName = NULL; void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace) { @@ -35,7 +37,7 @@ void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int t LOG_VERBOSE(TAG_FTP, F(D_SERVICE_DISCONNECTED)); break; case FTP_FREE_SPACE_CHANGE: - LOG_VERBOSE(TAG_FTP, "Free space change, free %u of %u!\n", freeSpace, totalSpace); + filesystemInfo(); break; default: break; @@ -43,16 +45,31 @@ void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int t }; void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize) { + transferName = name; + transferSize = transferredSize; + switch(ftpOperation) { - case FTP_UPLOAD_START: - LOG_VERBOSE(TAG_FTP, "Start upload of file %s byte %u\n", name, transferredSize); - break; + case FTP_UPLOAD_START: { + char size[16]; + Parser::format_bytes(transferredSize, size, sizeof(size)); + LOG_VERBOSE(TAG_FTP, "Start upload of file %s (%s)", name, size); + return; + } + case FTP_DOWNLOAD_START: { + char size[16]; + Parser::format_bytes(transferredSize, size, sizeof(size)); + LOG_VERBOSE(TAG_FTP, "Start download of file %s (%s)", name, size); + return; + } case FTP_UPLOAD: - LOG_VERBOSE(TAG_FTP, "Upload of file %s byte %u\n", name, transferredSize); - break; - case FTP_TRANSFER_STOP: - LOG_VERBOSE(TAG_FTP, "Completed upload of file %s byte %u\n", name, transferredSize); + case FTP_DOWNLOAD: + return; + case FTP_TRANSFER_STOP: { + char size[16]; + Parser::format_bytes(transferredSize, size, sizeof(size)); + LOG_VERBOSE(TAG_FTP, "Completed transfer of file %s (%s)", name, size); break; + } case FTP_TRANSFER_ERROR: LOG_VERBOSE(TAG_FTP, ("Transfer error!")); break; @@ -60,6 +77,9 @@ void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsi break; } + transferName = NULL; + transferSize = 0; + /* FTP_UPLOAD_START = 0, * FTP_UPLOAD = 1, * @@ -95,6 +115,7 @@ void ftpStart() ftpSrv.begin("ftpuser", "haspadmin"); // username, password for ftp. (default 21, 50009 for PASV) #endif + LOG_VERBOSE(TAG_FTP, F(FTP_SERVER_VERSION)); LOG_INFO(TAG_FTP, F(D_SERVICE_STARTED)); } @@ -111,7 +132,13 @@ IRAM_ATTR void ftpLoop() } void ftpEverySecond(void) -{} +{ + if(!transferSize || !transferName) return; + + char size[16]; + Parser::format_bytes(transferSize, size, sizeof(size)); + LOG_VERBOSE(TAG_FTP, D_BULLET "%s (%s)", transferName, size); +} #if HASP_USE_CONFIG > 0 bool ftpGetConfig(const JsonObject& settings)