Skip to content

Commit 1e05546

Browse files
authored
Merge pull request rjwats#128 from rjwats/status-improvements2
Status improvements - add file system
2 parents d68afe5 + f73c957 commit 1e05546

File tree

6 files changed

+69
-39
lines changed

6 files changed

+69
-39
lines changed

interface/src/system/SystemStatusForm.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DevicesIcon from '@material-ui/icons/Devices';
77
import MemoryIcon from '@material-ui/icons/Memory';
88
import ShowChartIcon from '@material-ui/icons/ShowChart';
99
import SdStorageIcon from '@material-ui/icons/SdStorage';
10+
import FolderIcon from '@material-ui/icons/Folder';
1011
import DataUsageIcon from '@material-ui/icons/DataUsage';
1112
import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew';
1213
import RefreshIcon from '@material-ui/icons/Refresh';
@@ -26,6 +27,11 @@ interface SystemStatusFormState {
2627

2728
type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>;
2829

30+
function formatNumber(num: number) {
31+
return new Intl.NumberFormat().format(num);
32+
}
33+
34+
2935
class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusFormState> {
3036

3137
state: SystemStatusFormState = {
@@ -67,7 +73,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
6773
<MemoryIcon />
6874
</Avatar>
6975
</ListItemAvatar>
70-
<ListItemText primary="Heap (Free / Max Alloc)" secondary={data.free_heap + ' / ' + data.max_alloc_heap + ' bytes (~' + this.approxHeapFragmentation() + '% fragmentation)'} />
76+
<ListItemText primary="Heap (Free / Max Alloc)" secondary={formatNumber(data.free_heap) + ' / ' + formatNumber(data.max_alloc_heap) + ' bytes (~' + this.approxHeapFragmentation() + '%\xa0fragmentation)'} />
7177
</ListItem>
7278
<Divider variant="inset" component="li" />
7379
<ListItem >
@@ -76,7 +82,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
7682
<DataUsageIcon />
7783
</Avatar>
7884
</ListItemAvatar>
79-
<ListItemText primary="Sketch (Size / Free)" secondary={data.sketch_size + ' / ' + data.free_sketch_space + ' bytes'} />
85+
<ListItemText primary="Sketch (Size / Free)" secondary={formatNumber(data.sketch_size) + ' / ' + formatNumber(data.free_sketch_space) + ' bytes'} />
8086
</ListItem>
8187
<Divider variant="inset" component="li" />
8288
<ListItem >
@@ -85,7 +91,16 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
8591
<SdStorageIcon />
8692
</Avatar>
8793
</ListItemAvatar>
88-
<ListItemText primary="Flash Chip (Size / Speed)" secondary={data.flash_chip_size + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
94+
<ListItemText primary="Flash Chip (Size / Speed)" secondary={formatNumber(data.flash_chip_size) + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
95+
</ListItem>
96+
<Divider variant="inset" component="li" />
97+
<ListItem >
98+
<ListItemAvatar>
99+
<Avatar>
100+
<FolderIcon />
101+
</Avatar>
102+
</ListItemAvatar>
103+
<ListItemText primary="File System (Used / Total)" secondary={formatNumber(data.fs_used) + ' / ' + formatNumber(data.fs_total) + ' bytes (' + formatNumber(data.fs_total - data.fs_used) + '\xa0bytes free)'} />
89104
</ListItem>
90105
<Divider variant="inset" component="li" />
91106
</Fragment>

interface/src/system/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface SystemStatus {
88
sdk_version: string;
99
flash_chip_size: number;
1010
flash_chip_speed: number;
11+
fs_used: number;
12+
fs_total: number;
1113
}
1214

1315
export interface OTASettings {

lib/framework/ESP8266React.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
4242
});
4343
#else
4444
// Serve static resources from /www/
45-
server->serveStatic("/js/", SPIFFS, "/www/js/");
46-
server->serveStatic("/css/", SPIFFS, "/www/css/");
47-
server->serveStatic("/fonts/", SPIFFS, "/www/fonts/");
48-
server->serveStatic("/app/", SPIFFS, "/www/app/");
49-
server->serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico");
45+
server->serveStatic("/js/", *fs, "/www/js/");
46+
server->serveStatic("/css/", *fs, "/www/css/");
47+
server->serveStatic("/fonts/", *fs, "/www/fonts/");
48+
server->serveStatic("/app/", *fs, "/www/app/");
49+
server->serveStatic("/favicon.ico", *fs, "/www/favicon.ico");
5050
// Serving all other get requests with "/www/index.htm"
5151
// OPTIONS get a straight up 200 response
5252
server->onNotFound([](AsyncWebServerRequest* request) {

lib/framework/ESP8266React.h

-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
#ifdef ESP32
77
#include <AsyncTCP.h>
8-
#include <SPIFFS.h>
98
#include <WiFi.h>
109
#elif defined(ESP8266)
1110
#include <ESP8266WiFi.h>
1211
#include <ESPAsyncTCP.h>
13-
#include <FS.h>
1412
#endif
1513

1614
#include <APSettingsService.h>

lib/framework/SystemStatus.cpp

+42-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1-
#include <SystemStatus.h>
2-
3-
SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
4-
server->on(SYSTEM_STATUS_SERVICE_PATH,
5-
HTTP_GET,
6-
securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1),
7-
AuthenticationPredicates::IS_AUTHENTICATED));
8-
}
9-
10-
void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
11-
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
12-
JsonObject root = response->getRoot();
13-
#ifdef ESP32
14-
root["esp_platform"] = "esp32";
15-
root["max_alloc_heap"] = ESP.getMaxAllocHeap();
16-
#elif defined(ESP8266)
17-
root["esp_platform"] = "esp8266";
18-
root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
19-
#endif
20-
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
21-
root["free_heap"] = ESP.getFreeHeap();
22-
root["sketch_size"] = ESP.getSketchSize();
23-
root["free_sketch_space"] = ESP.getFreeSketchSpace();
24-
root["sdk_version"] = ESP.getSdkVersion();
25-
root["flash_chip_size"] = ESP.getFlashChipSize();
26-
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
27-
response->setLength();
28-
request->send(response);
29-
}
1+
#include <SystemStatus.h>
2+
3+
SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
4+
server->on(SYSTEM_STATUS_SERVICE_PATH,
5+
HTTP_GET,
6+
securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1),
7+
AuthenticationPredicates::IS_AUTHENTICATED));
8+
}
9+
10+
void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
11+
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
12+
JsonObject root = response->getRoot();
13+
#ifdef ESP32
14+
root["esp_platform"] = "esp32";
15+
root["max_alloc_heap"] = ESP.getMaxAllocHeap();
16+
#elif defined(ESP8266)
17+
root["esp_platform"] = "esp8266";
18+
root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
19+
#endif
20+
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
21+
root["free_heap"] = ESP.getFreeHeap();
22+
root["sketch_size"] = ESP.getSketchSize();
23+
root["free_sketch_space"] = ESP.getFreeSketchSpace();
24+
root["sdk_version"] = ESP.getSdkVersion();
25+
root["flash_chip_size"] = ESP.getFlashChipSize();
26+
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
27+
28+
// TODO - Ideally this class will take an *FS and extract the file system information from there.
29+
// ESP8266 and ESP32 do not have feature parity in FS.h which currently makes that difficult.
30+
#ifdef ESP32
31+
root["fs_total"] = SPIFFS.totalBytes();
32+
root["fs_used"] = SPIFFS.usedBytes();
33+
#elif defined(ESP8266)
34+
FSInfo fs_info;
35+
SPIFFS.info(fs_info);
36+
root["fs_total"] = fs_info.totalBytes;
37+
root["fs_used"] = fs_info.usedBytes;
38+
#endif
39+
40+
response->setLength();
41+
request->send(response);
42+
}

lib/framework/SystemStatus.h

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#ifdef ESP32
55
#include <WiFi.h>
66
#include <AsyncTCP.h>
7+
#include <SPIFFS.h>
78
#elif defined(ESP8266)
89
#include <ESP8266WiFi.h>
910
#include <ESPAsyncTCP.h>
11+
#include <FS.h>
1012
#endif
1113

1214
#include <ArduinoJson.h>

0 commit comments

Comments
 (0)