add spiffs size + formatting

This commit is contained in:
Raomin 2020-05-24 23:35:32 +02:00
parent bcb1098402
commit 49910e1272
3 changed files with 35 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import DevicesIcon from '@material-ui/icons/Devices';
import MemoryIcon from '@material-ui/icons/Memory'; import MemoryIcon from '@material-ui/icons/Memory';
import ShowChartIcon from '@material-ui/icons/ShowChart'; import ShowChartIcon from '@material-ui/icons/ShowChart';
import SdStorageIcon from '@material-ui/icons/SdStorage'; import SdStorageIcon from '@material-ui/icons/SdStorage';
import StorageIcon from '@material-ui/icons/Storage';
import DataUsageIcon from '@material-ui/icons/DataUsage'; import DataUsageIcon from '@material-ui/icons/DataUsage';
import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew'; import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew';
import RefreshIcon from '@material-ui/icons/Refresh'; import RefreshIcon from '@material-ui/icons/Refresh';
@ -26,6 +27,11 @@ interface SystemStatusFormState {
type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>; type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>;
function asNum(num: number){
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusFormState> { class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusFormState> {
state: SystemStatusFormState = { state: SystemStatusFormState = {
@ -67,7 +73,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<MemoryIcon /> <MemoryIcon />
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText primary="Heap (Free / Max Alloc)" secondary={data.free_heap + ' / ' + data.max_alloc_heap + ' bytes (~' + this.approxHeapFragmentation() + '% fragmentation)'} /> <ListItemText primary="Heap (Free / Max Alloc)" secondary={asNum(data.free_heap) + ' / ' + asNum(data.max_alloc_heap) + ' bytes (~' + this.approxHeapFragmentation() + '% fragmentation)'} />
</ListItem> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
<ListItem > <ListItem >
@ -76,7 +82,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<DataUsageIcon /> <DataUsageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText primary="Sketch (Size / Free)" secondary={data.sketch_size + ' / ' + data.free_sketch_space + ' bytes'} /> <ListItemText primary="Sketch Size (used/max)" secondary={asNum(data.sketch_size) + ' / ' + asNum(data.free_sketch_space) + ' bytes'} />
</ListItem> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
<ListItem > <ListItem >
@ -85,7 +91,15 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<SdStorageIcon /> <SdStorageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText primary="Flash Chip (Size / Speed)" secondary={data.flash_chip_size + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} /> <ListItemText primary="Flash Chip (Size / Speed)" secondary={asNum(data.flash_chip_size) + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
</ListItem>
<ListItem >
<ListItemAvatar>
<Avatar>
<StorageIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="SPIFFS (Used / Total | Free)" secondary={asNum(data.spiffs_used) + ' / ' + asNum(data.spiffs_size) + ' bytes | '+ asNum(data.spiffs_size-data.spiffs_used) + ' bytes free'} />
</ListItem> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
</Fragment> </Fragment>

View File

@ -8,6 +8,8 @@ export interface SystemStatus {
sdk_version: string; sdk_version: string;
flash_chip_size: number; flash_chip_size: number;
flash_chip_speed: number; flash_chip_speed: number;
spiffs_size:number;
spiffs_used:number;
} }
export interface OTASettings { export interface OTASettings {

View File

@ -1,4 +1,10 @@
#include <SystemStatus.h> #include <SystemStatus.h>
#ifdef ESP32
#include <esp_spiffs.h>
#include <SPIFFS.h>
#elif defined(ESP8266)
#include <FS.h>
#endif
SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
server->on(SYSTEM_STATUS_SERVICE_PATH, server->on(SYSTEM_STATUS_SERVICE_PATH,
@ -24,6 +30,15 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
root["sdk_version"] = ESP.getSdkVersion(); root["sdk_version"] = ESP.getSdkVersion();
root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_size"] = ESP.getFlashChipSize();
root["flash_chip_speed"] = ESP.getFlashChipSpeed(); 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(); response->setLength();
request->send(response); request->send(response);
} }