Merge pull request #127 from raomin/e82/master

SPIFFS size info in System view
This commit is contained in:
rjwats 2020-05-25 10:28:55 +01:00 committed by GitHub
commit f2dcc4e1e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 33 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 formatNumber(num: number){
return new Intl.NumberFormat().format(num);
}
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={formatNumber(data.free_heap) + ' / ' + formatNumber(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 / Free)" secondary={formatNumber(data.sketch_size) + ' / ' + formatNumber(data.free_sketch_space) + ' bytes'} />
</ListItem> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
<ListItem > <ListItem >
@ -85,12 +91,20 @@ 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={formatNumber(data.flash_chip_size) + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
</ListItem> </ListItem>
<ListItem >
<ListItemAvatar>
<Avatar>
<StorageIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="SPIFFS (Used / Total | Free)" secondary={formatNumber(data.spiffs_used) + ' / ' + formatNumber(data.spiffs_size) + ' bytes | '+ formatNumber(data.spiffs_size-data.spiffs_used) + ' bytes free'} />
</ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
</Fragment> </Fragment>
); );
} }
renderRestartDialog() { renderRestartDialog() {
return ( return (

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,29 +1,36 @@
#include <SystemStatus.h> #include <SystemStatus.h>
#ifdef ESP32
SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { #include <SPIFFS.h>
server->on(SYSTEM_STATUS_SERVICE_PATH, #elif defined(ESP8266)
HTTP_GET, #include <FS.h>
securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1), #endif
AuthenticationPredicates::IS_AUTHENTICATED));
} SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
server->on(SYSTEM_STATUS_SERVICE_PATH,
void SystemStatus::systemStatus(AsyncWebServerRequest* request) { HTTP_GET,
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE); securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1),
JsonObject root = response->getRoot(); AuthenticationPredicates::IS_AUTHENTICATED));
#ifdef ESP32 }
root["esp_platform"] = "esp32";
root["max_alloc_heap"] = ESP.getMaxAllocHeap(); void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
#elif defined(ESP8266) AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
root["esp_platform"] = "esp8266"; JsonObject root = response->getRoot();
root["max_alloc_heap"] = ESP.getMaxFreeBlockSize(); #ifdef ESP32
#endif root["esp_platform"] = "esp32";
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz(); root["max_alloc_heap"] = ESP.getMaxAllocHeap();
root["free_heap"] = ESP.getFreeHeap(); #elif defined(ESP8266)
root["sketch_size"] = ESP.getSketchSize(); root["esp_platform"] = "esp8266";
root["free_sketch_space"] = ESP.getFreeSketchSpace(); root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
root["sdk_version"] = ESP.getSdkVersion(); #endif
root["flash_chip_size"] = ESP.getFlashChipSize(); root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
root["flash_chip_speed"] = ESP.getFlashChipSpeed(); root["free_heap"] = ESP.getFreeHeap();
response->setLength(); root["sketch_size"] = ESP.getSketchSize();
request->send(response); root["free_sketch_space"] = ESP.getFreeSketchSpace();
} 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);
}