From ce8929fd39947800ef3a79f89a15ac8ce7e080e4 Mon Sep 17 00:00:00 2001 From: Raomin Date: Fri, 22 May 2020 02:06:13 +0200 Subject: [PATCH 1/7] add spiffs size + formatting --- interface/src/system/SystemStatusForm.tsx | 22 ++++++++++++++++++---- interface/src/system/types.ts | 2 ++ lib/framework/SystemStatus.cpp | 7 +++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 7c3f431..25cf1f1 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -7,6 +7,7 @@ import DevicesIcon from '@material-ui/icons/Devices'; import MemoryIcon from '@material-ui/icons/Memory'; import ShowChartIcon from '@material-ui/icons/ShowChart'; import SdStorageIcon from '@material-ui/icons/SdStorage'; +import StorageIcon from '@material-ui/icons/Storage'; import DataUsageIcon from '@material-ui/icons/DataUsage'; import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew'; import RefreshIcon from '@material-ui/icons/Refresh'; @@ -26,6 +27,11 @@ interface SystemStatusFormState { type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps; +function asNum(num: number){ + return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); +} + + class SystemStatusForm extends Component { state: SystemStatusFormState = { @@ -67,7 +73,7 @@ class SystemStatusForm extends Component - + @@ -76,7 +82,7 @@ class SystemStatusForm extends Component - + @@ -85,12 +91,20 @@ class SystemStatusForm extends Component - + + + + + + + + + ); - } + } renderRestartDialog() { return ( diff --git a/interface/src/system/types.ts b/interface/src/system/types.ts index 323f947..c1c3bc0 100644 --- a/interface/src/system/types.ts +++ b/interface/src/system/types.ts @@ -8,6 +8,8 @@ export interface SystemStatus { sdk_version: string; flash_chip_size: number; flash_chip_speed: number; + spiffs_size:number; + spiffs_used:number; } export interface OTASettings { diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index cda53c9..bb3d20b 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -1,4 +1,9 @@ #include +#ifdef ESP32 +#include +#elif defined(ESP8266) +#include +#endif SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { server->on(SYSTEM_STATUS_SERVICE_PATH, @@ -24,6 +29,8 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["sdk_version"] = ESP.getSdkVersion(); root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); + root["spiffs_used"] = SPIFFS.usedBytes(); + root["spiffs_size"] = SPIFFS.totalBytes(); response->setLength(); request->send(response); } From 49910e1272aca966c88889ff43937f64462b7581 Mon Sep 17 00:00:00 2001 From: Raomin Date: Sun, 24 May 2020 23:35:32 +0200 Subject: [PATCH 2/7] add spiffs size + formatting --- interface/src/system/SystemStatusForm.tsx | 22 ++++++++++++++++++---- interface/src/system/types.ts | 2 ++ lib/framework/SystemStatus.cpp | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 7c3f431..25cf1f1 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -7,6 +7,7 @@ import DevicesIcon from '@material-ui/icons/Devices'; import MemoryIcon from '@material-ui/icons/Memory'; import ShowChartIcon from '@material-ui/icons/ShowChart'; import SdStorageIcon from '@material-ui/icons/SdStorage'; +import StorageIcon from '@material-ui/icons/Storage'; import DataUsageIcon from '@material-ui/icons/DataUsage'; import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew'; import RefreshIcon from '@material-ui/icons/Refresh'; @@ -26,6 +27,11 @@ interface SystemStatusFormState { type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps; +function asNum(num: number){ + return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); +} + + class SystemStatusForm extends Component { state: SystemStatusFormState = { @@ -67,7 +73,7 @@ class SystemStatusForm extends Component - + @@ -76,7 +82,7 @@ class SystemStatusForm extends Component - + @@ -85,12 +91,20 @@ class SystemStatusForm extends Component - + + + + + + + + + ); - } + } renderRestartDialog() { return ( diff --git a/interface/src/system/types.ts b/interface/src/system/types.ts index 323f947..c1c3bc0 100644 --- a/interface/src/system/types.ts +++ b/interface/src/system/types.ts @@ -8,6 +8,8 @@ export interface SystemStatus { sdk_version: string; flash_chip_size: number; flash_chip_speed: number; + spiffs_size:number; + spiffs_used:number; } export interface OTASettings { diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index cda53c9..699e0a7 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -1,4 +1,10 @@ #include +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) +#include +#endif SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { server->on(SYSTEM_STATUS_SERVICE_PATH, @@ -24,6 +30,15 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["sdk_version"] = ESP.getSdkVersion(); root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); +#ifdef ESP32 + if (esp_spiffs_mounted(NULL)) { + root["spiffs_used"] = SPIFFS.usedBytes(); + root["spiffs_size"] = SPIFFS.totalBytes(); + } +#elif !defined(PROGMEM_WWW) //couldn't find an esp8266 alternative to esp_spiffs_mounted() + root["spiffs_used"] = SPIFFS.usedBytes(); + root["spiffs_size"] = SPIFFS.totalBytes(); +#endif response->setLength(); request->send(response); } From 6510a72789f9b3e5754c23ca90788292e21f71c3 Mon Sep 17 00:00:00 2001 From: Raomin Date: Mon, 25 May 2020 01:41:45 +0200 Subject: [PATCH 3/7] apply PR comments --- interface/src/system/SystemStatusForm.tsx | 12 ++++++------ lib/framework/SystemStatus.cpp | 12 ++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 25cf1f1..88fc7aa 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -27,8 +27,8 @@ interface SystemStatusFormState { type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps; -function asNum(num: number){ - return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); +function formatNumber(num: number){ + return new Intl.NumberFormat().format(num); } @@ -73,7 +73,7 @@ class SystemStatusForm extends Component - + @@ -82,7 +82,7 @@ class SystemStatusForm extends Component - + @@ -91,7 +91,7 @@ class SystemStatusForm extends Component - + @@ -99,7 +99,7 @@ class SystemStatusForm extends Component - + diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index f126e7b..0750184 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -1,6 +1,5 @@ #include #ifdef ESP32 -#include #include #elif defined(ESP8266) #include @@ -30,15 +29,8 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["sdk_version"] = ESP.getSdkVersion(); root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); -#ifdef ESP32 - if (esp_spiffs_mounted(NULL)) { - root["spiffs_used"] = SPIFFS.usedBytes(); - root["spiffs_size"] = SPIFFS.totalBytes(); - } -#elif !defined(PROGMEM_WWW) //couldn't find an esp8266 alternative to esp_spiffs_mounted() - root["spiffs_used"] = SPIFFS.usedBytes(); - root["spiffs_size"] = SPIFFS.totalBytes(); -#endif + root["spiffs_used"] = SPIFFS.usedBytes(); + root["spiffs_size"] = SPIFFS.totalBytes(); response->setLength(); request->send(response); } From aa04cfd80cfa86bda63084defc100b19b022da77 Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Mon, 25 May 2020 11:00:42 +0100 Subject: [PATCH 4/7] fix imports use FSInfo struct for esp8266 --- interface/src/system/SystemStatusForm.tsx | 9 +++++---- interface/src/system/types.ts | 4 ++-- lib/framework/SystemStatus.cpp | 16 ++++++++++------ lib/framework/SystemStatus.h | 2 ++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 88fc7aa..fadf1e7 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -27,7 +27,7 @@ interface SystemStatusFormState { type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps; -function formatNumber(num: number){ +function formatNumber(num: number) { return new Intl.NumberFormat().format(num); } @@ -93,18 +93,19 @@ class SystemStatusForm extends Component + - - + + ); - } + } renderRestartDialog() { return ( diff --git a/interface/src/system/types.ts b/interface/src/system/types.ts index c1c3bc0..336ba65 100644 --- a/interface/src/system/types.ts +++ b/interface/src/system/types.ts @@ -8,8 +8,8 @@ export interface SystemStatus { sdk_version: string; flash_chip_size: number; flash_chip_speed: number; - spiffs_size:number; - spiffs_used:number; + spiffs_used: number; + spiffs_total: number; } export interface OTASettings { diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index 0750184..71b9a9b 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -1,9 +1,4 @@ #include -#ifdef ESP32 -#include -#elif defined(ESP8266) -#include -#endif SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { server->on(SYSTEM_STATUS_SERVICE_PATH, @@ -29,8 +24,17 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["sdk_version"] = ESP.getSdkVersion(); root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); + +#ifdef ESP32 + root["spiffs_total"] = SPIFFS.totalBytes(); root["spiffs_used"] = SPIFFS.usedBytes(); - root["spiffs_size"] = SPIFFS.totalBytes(); +#elif defined(ESP8266) + FSInfo fs_info; + SPIFFS.info(fs_info); + root["spiffs_total"] = fs_info.totalBytes; + root["spiffs_used"] = fs_info.usedBytes; +#endif + response->setLength(); request->send(response); } diff --git a/lib/framework/SystemStatus.h b/lib/framework/SystemStatus.h index aa44623..397869b 100644 --- a/lib/framework/SystemStatus.h +++ b/lib/framework/SystemStatus.h @@ -4,9 +4,11 @@ #ifdef ESP32 #include #include +#include #elif defined(ESP8266) #include #include +#include #endif #include From 98f49fd02442ff0177690ba22c8b92d15e1f5e19 Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Mon, 25 May 2020 11:04:13 +0100 Subject: [PATCH 5/7] use "fs" instead of "spiffs" as spiffs is implementation specific --- interface/src/system/SystemStatusForm.tsx | 6 +++--- interface/src/system/types.ts | 4 ++-- lib/framework/SystemStatus.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index fadf1e7..0b9d09d 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -7,7 +7,7 @@ import DevicesIcon from '@material-ui/icons/Devices'; import MemoryIcon from '@material-ui/icons/Memory'; import ShowChartIcon from '@material-ui/icons/ShowChart'; import SdStorageIcon from '@material-ui/icons/SdStorage'; -import StorageIcon from '@material-ui/icons/Storage'; +import FolderIcon from '@material-ui/icons/Folder'; import DataUsageIcon from '@material-ui/icons/DataUsage'; import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew'; import RefreshIcon from '@material-ui/icons/Refresh'; @@ -97,10 +97,10 @@ class SystemStatusForm extends Component - + - + diff --git a/interface/src/system/types.ts b/interface/src/system/types.ts index 336ba65..bbd9362 100644 --- a/interface/src/system/types.ts +++ b/interface/src/system/types.ts @@ -8,8 +8,8 @@ export interface SystemStatus { sdk_version: string; flash_chip_size: number; flash_chip_speed: number; - spiffs_used: number; - spiffs_total: number; + fs_used: number; + fs_total: number; } export interface OTASettings { diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index 71b9a9b..13b15ee 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -26,13 +26,13 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["flash_chip_speed"] = ESP.getFlashChipSpeed(); #ifdef ESP32 - root["spiffs_total"] = SPIFFS.totalBytes(); - root["spiffs_used"] = SPIFFS.usedBytes(); + root["fs_total"] = SPIFFS.totalBytes(); + root["fs_used"] = SPIFFS.usedBytes(); #elif defined(ESP8266) FSInfo fs_info; SPIFFS.info(fs_info); - root["spiffs_total"] = fs_info.totalBytes; - root["spiffs_used"] = fs_info.usedBytes; + root["fs_total"] = fs_info.totalBytes; + root["fs_used"] = fs_info.usedBytes; #endif response->setLength(); From b4f3fbe8231bb49acfca7574c150aa6902bd4ff2 Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Mon, 25 May 2020 11:30:13 +0100 Subject: [PATCH 6/7] Remove SPIFFS reference from ESP8266 react, use FS pointer instead --- interface/src/system/SystemStatusForm.tsx | 4 ++-- lib/framework/ESP8266React.cpp | 10 +++++----- lib/framework/ESP8266React.h | 2 -- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 0b9d09d..eb83ae9 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -73,7 +73,7 @@ class SystemStatusForm extends Component - + @@ -100,7 +100,7 @@ class SystemStatusForm extends Component - + diff --git a/lib/framework/ESP8266React.cpp b/lib/framework/ESP8266React.cpp index b03a7d1..6ddcf9f 100644 --- a/lib/framework/ESP8266React.cpp +++ b/lib/framework/ESP8266React.cpp @@ -42,11 +42,11 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) : }); #else // Serve static resources from /www/ - server->serveStatic("/js/", SPIFFS, "/www/js/"); - server->serveStatic("/css/", SPIFFS, "/www/css/"); - server->serveStatic("/fonts/", SPIFFS, "/www/fonts/"); - server->serveStatic("/app/", SPIFFS, "/www/app/"); - server->serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico"); + server->serveStatic("/js/", *fs, "/www/js/"); + server->serveStatic("/css/", *fs, "/www/css/"); + server->serveStatic("/fonts/", *fs, "/www/fonts/"); + server->serveStatic("/app/", *fs, "/www/app/"); + server->serveStatic("/favicon.ico", *fs, "/www/favicon.ico"); // Serving all other get requests with "/www/index.htm" // OPTIONS get a straight up 200 response server->onNotFound([](AsyncWebServerRequest* request) { diff --git a/lib/framework/ESP8266React.h b/lib/framework/ESP8266React.h index a4d95f3..3509f0a 100644 --- a/lib/framework/ESP8266React.h +++ b/lib/framework/ESP8266React.h @@ -5,12 +5,10 @@ #ifdef ESP32 #include -#include #include #elif defined(ESP8266) #include #include -#include #endif #include From f73c9574775d75f6aa572b16fe296b2f3a0e6aec Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Mon, 25 May 2020 11:35:03 +0100 Subject: [PATCH 7/7] add TODO --- lib/framework/SystemStatus.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index 13b15ee..28d987a 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -25,6 +25,8 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_speed"] = ESP.getFlashChipSpeed(); +// TODO - Ideally this class will take an *FS and extract the file system information from there. +// ESP8266 and ESP32 do not have feature parity in FS.h which currently makes that difficult. #ifdef ESP32 root["fs_total"] = SPIFFS.totalBytes(); root["fs_used"] = SPIFFS.usedBytes();