|
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 | +} |
0 commit comments