🚚 Moves system metrics out of main

This commit is contained in:
Rune Harlyk
2026-01-03 17:22:04 +01:00
committed by nikguin04
parent a6e5363533
commit 39f9e47e59
3 changed files with 33 additions and 18 deletions
+6 -1
View File
@@ -5,9 +5,13 @@
#include <WiFi.h>
#include <filesystem.h>
#include <global.h>
#include "esp_timer.h"
#include <esp_timer.h>
#include <esp_heap_caps.h>
#include <esp_littlefs.h>
#include <string>
#include "platform_shared/message.pb.h"
namespace system_service {
esp_err_t handleReset(PsychicRequest *request);
esp_err_t handleRestart(PsychicRequest *request);
@@ -18,6 +22,7 @@ void reset();
void restart();
void sleep();
void status(JsonObject &root);
void getAnalytics(socket_message_AnalyticsData &analytics);
const char *resetReason(esp_reset_reason_t reason);
} // namespace system_service
+1 -10
View File
@@ -242,16 +242,7 @@ void IRAM_ATTR serviceLoopEntry(void *) {
EXECUTE_EVERY_N_MS(2000, {
socket_message_AnalyticsData analytics = socket_message_AnalyticsData_init_zero;
analytics.max_alloc_heap = ESP.getMaxAllocHeap();
analytics.psram_size = ESP.getPsramSize();
analytics.free_psram = ESP.getFreePsram();
analytics.free_heap = ESP.getFreeHeap();
analytics.total_heap = ESP.getHeapSize();
analytics.min_free_heap = ESP.getMinFreeHeap();
analytics.core_temp = temperatureRead();
analytics.fs_total = ESP_FS.totalBytes();
analytics.fs_used = ESP_FS.usedBytes();
analytics.uptime = esp_timer_get_time() / 1000;
system_service::getAnalytics(analytics);
socket.emit(analytics);
});
+26 -7
View File
@@ -79,30 +79,49 @@ void sleep() {
}
void status(JsonObject &root) {
size_t fs_total = 0, fs_used = 0;
esp_littlefs_info("spiffs", &fs_total, &fs_used);
root["esp_platform"] = ESP_PLATFORM;
root["firmware_version"] = APP_VERSION;
root["max_alloc_heap"] = ESP.getMaxAllocHeap();
root["psram_size"] = ESP.getPsramSize();
root["free_psram"] = ESP.getFreePsram();
root["max_alloc_heap"] = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
root["psram_size"] = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
root["free_psram"] = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
root["cpu_type"] = ESP.getChipModel();
root["cpu_rev"] = ESP.getChipRevision();
root["cpu_cores"] = ESP.getChipCores();
root["free_heap"] = ESP.getFreeHeap();
root["min_free_heap"] = ESP.getMinFreeHeap();
root["free_heap"] = esp_get_free_heap_size();
root["min_free_heap"] = esp_get_minimum_free_heap_size();
root["sketch_size"] = ESP.getSketchSize();
root["free_sketch_space"] = ESP.getFreeSketchSpace();
root["sdk_version"] = ESP.getSdkVersion();
root["arduino_version"] = ARDUINO_VERSION;
root["flash_chip_size"] = ESP.getFlashChipSize();
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
root["fs_total"] = ESP_FS.totalBytes();
root["fs_used"] = ESP_FS.usedBytes();
root["fs_total"] = fs_total;
root["fs_used"] = fs_used;
root["core_temp"] = temperatureRead();
root["cpu_reset_reason"] = resetReason(esp_reset_reason());
root["uptime"] = esp_timer_get_time() / 1000000;
}
void getAnalytics(socket_message_AnalyticsData &analytics) {
size_t fs_total = 0, fs_used = 0;
esp_littlefs_info("spiffs", &fs_total, &fs_used);
analytics.max_alloc_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
analytics.psram_size = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
analytics.free_psram = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
analytics.free_heap = esp_get_free_heap_size();
analytics.total_heap = heap_caps_get_total_size(MALLOC_CAP_8BIT);
analytics.min_free_heap = esp_get_minimum_free_heap_size();
analytics.core_temp = temperatureRead();
analytics.fs_total = fs_total;
analytics.fs_used = fs_used;
analytics.uptime = esp_timer_get_time() / 1000;
}
const char *resetReason(esp_reset_reason_t reason) {
switch (reason) {
case ESP_RST_UNKNOWN: return "Reset reason can not be determined";