Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #include <SystemStatus.h>
  2. SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
  3. server->on(SYSTEM_STATUS_SERVICE_PATH,
  4. HTTP_GET,
  5. securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1),
  6. AuthenticationPredicates::IS_AUTHENTICATED));
  7. }
  8. void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
  9. AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
  10. JsonObject root = response->getRoot();
  11. #ifdef ESP32
  12. root["esp_platform"] = "esp32";
  13. root["max_alloc_heap"] = ESP.getMaxAllocHeap();
  14. root["psram_size"] = ESP.getPsramSize();
  15. root["free_psram"] = ESP.getFreePsram();
  16. #elif defined(ESP8266)
  17. root["esp_platform"] = "esp8266";
  18. root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
  19. root["heap_fragmentation"] = ESP.getHeapFragmentation();
  20. #endif
  21. root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
  22. root["free_heap"] = ESP.getFreeHeap();
  23. root["sketch_size"] = ESP.getSketchSize();
  24. root["free_sketch_space"] = ESP.getFreeSketchSpace();
  25. root["sdk_version"] = ESP.getSdkVersion();
  26. root["flash_chip_size"] = ESP.getFlashChipSize();
  27. root["flash_chip_speed"] = ESP.getFlashChipSpeed();
  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"] = ESPFS.totalBytes();
  32. root["fs_used"] = ESPFS.usedBytes();
  33. #elif defined(ESP8266)
  34. FSInfo fs_info;
  35. ESPFS.info(fs_info);
  36. root["fs_total"] = fs_info.totalBytes;
  37. root["fs_used"] = fs_info.usedBytes;
  38. #endif
  39. response->setLength();
  40. request->send(response);
  41. }