fix imports

use FSInfo struct for esp8266
This commit is contained in:
Rick Watson 2020-05-25 11:00:42 +01:00
parent f2dcc4e1e9
commit aa04cfd80c
4 changed files with 19 additions and 12 deletions

View File

@ -27,7 +27,7 @@ interface SystemStatusFormState {
type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>; type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>;
function formatNumber(num: number){ function formatNumber(num: number) {
return new Intl.NumberFormat().format(num); return new Intl.NumberFormat().format(num);
} }
@ -93,13 +93,14 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
</ListItemAvatar> </ListItemAvatar>
<ListItemText primary="Flash Chip (Size / Speed)" secondary={formatNumber(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>
<Divider variant="inset" component="li" />
<ListItem > <ListItem >
<ListItemAvatar> <ListItemAvatar>
<Avatar> <Avatar>
<StorageIcon /> <StorageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </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'} /> <ListItemText primary="SPIFFS (Used / Total)" secondary={formatNumber(data.spiffs_used) + ' / ' + formatNumber(data.spiffs_total) + ' bytes (' + formatNumber(data.spiffs_total - data.spiffs_used) + ' bytes free)'} />
</ListItem> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
</Fragment> </Fragment>

View File

@ -8,8 +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;
spiffs_used:number; spiffs_total: number;
} }
export interface OTASettings { export interface OTASettings {

View File

@ -1,9 +1,4 @@
#include <SystemStatus.h> #include <SystemStatus.h>
#ifdef ESP32
#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,
@ -29,8 +24,17 @@ 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
root["spiffs_total"] = SPIFFS.totalBytes();
root["spiffs_used"] = SPIFFS.usedBytes(); 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(); response->setLength();
request->send(response); request->send(response);
} }

View File

@ -4,9 +4,11 @@
#ifdef ESP32 #ifdef ESP32
#include <WiFi.h> #include <WiFi.h>
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <SPIFFS.h>
#elif defined(ESP8266) #elif defined(ESP8266)
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#include <FS.h>
#endif #endif
#include <ArduinoJson.h> #include <ArduinoJson.h>