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.

42 lines
1.6 KiB

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. #elif defined(ESP8266)
  15. root["esp_platform"] = "esp8266";
  16. root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
  17. #endif
  18. root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
  19. root["free_heap"] = ESP.getFreeHeap();
  20. root["sketch_size"] = ESP.getSketchSize();
  21. root["free_sketch_space"] = ESP.getFreeSketchSpace();
  22. root["sdk_version"] = ESP.getSdkVersion();
  23. root["flash_chip_size"] = ESP.getFlashChipSize();
  24. root["flash_chip_speed"] = ESP.getFlashChipSpeed();
  25. // TODO - Ideally this class will take an *FS and extract the file system information from there.
  26. // ESP8266 and ESP32 do not have feature parity in FS.h which currently makes that difficult.
  27. #ifdef ESP32
  28. root["fs_total"] = SPIFFS.totalBytes();
  29. root["fs_used"] = SPIFFS.usedBytes();
  30. #elif defined(ESP8266)
  31. FSInfo fs_info;
  32. SPIFFS.info(fs_info);
  33. root["fs_total"] = fs_info.totalBytes;
  34. root["fs_used"] = fs_info.usedBytes;
  35. #endif
  36. response->setLength();
  37. request->send(response);
  38. }