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.

44 lines
1.6 KiB

4 years ago
  1. #include <SystemStatus.h>
  2. #ifdef ESP32
  3. #include <esp_spiffs.h>
  4. #include <SPIFFS.h>
  5. #elif defined(ESP8266)
  6. #include <FS.h>
  7. #endif
  8. SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) {
  9. server->on(SYSTEM_STATUS_SERVICE_PATH,
  10. HTTP_GET,
  11. securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1),
  12. AuthenticationPredicates::IS_AUTHENTICATED));
  13. }
  14. void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
  15. AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
  16. JsonObject root = response->getRoot();
  17. #ifdef ESP32
  18. root["esp_platform"] = "esp32";
  19. root["max_alloc_heap"] = ESP.getMaxAllocHeap();
  20. #elif defined(ESP8266)
  21. root["esp_platform"] = "esp8266";
  22. root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
  23. #endif
  24. root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
  25. root["free_heap"] = ESP.getFreeHeap();
  26. root["sketch_size"] = ESP.getSketchSize();
  27. root["free_sketch_space"] = ESP.getFreeSketchSpace();
  28. root["sdk_version"] = ESP.getSdkVersion();
  29. root["flash_chip_size"] = ESP.getFlashChipSize();
  30. root["flash_chip_speed"] = ESP.getFlashChipSpeed();
  31. #ifdef ESP32
  32. if (esp_spiffs_mounted(NULL)) {
  33. root["spiffs_used"] = SPIFFS.usedBytes();
  34. root["spiffs_size"] = SPIFFS.totalBytes();
  35. }
  36. #elif !defined(PROGMEM_WWW) //couldn't find an esp8266 alternative to esp_spiffs_mounted()
  37. root["spiffs_used"] = SPIFFS.usedBytes();
  38. root["spiffs_size"] = SPIFFS.totalBytes();
  39. #endif
  40. response->setLength();
  41. request->send(response);
  42. }