From 6b953d96ebab350f80c89e826723da37f5013b0b Mon Sep 17 00:00:00 2001 From: Will Miles Date: Sat, 31 Jan 2026 19:54:03 -0500 Subject: [PATCH] Fix 5168 (#5181) * Fix slop from 5168 Remove the redundant field from the info structure and report what we actually want to know. * Fix psram size estimate Shorten the name, and round up -- getPsramSize() is the usable size, not the total size (the difference is allocator overhead). * Let psram builds work without it * Remove impossible cases in psram reports --- wled00/data/index.js | 4 ++-- wled00/json.cpp | 14 +++++--------- wled00/wled.cpp | 10 +++++++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wled00/data/index.js b/wled00/data/index.js index 14bf5392..99c0087d 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -3396,8 +3396,8 @@ function reportUpgradeEvent(info, oldVersion) { }; // Add optional fields if available - if (infoData.psramPresent !== undefined) upgradeData.psramPresent = infoData.psramPresent; // Whether device has PSRAM - if (infoData.psramSize !== undefined) upgradeData.psramSize = infoData.psramSize; // Total PSRAM size in MB + if (infoData.psrSz !== undefined) upgradeData.psramSize = infoData.psrSz; // Total PSRAM size in MB; can be 0 + // Note: partitionSizes not currently available in /json/info endpoint // Make AJAX call to postUpgradeEvent API diff --git a/wled00/json.cpp b/wled00/json.cpp index 54bdd6d9..3e053708 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -840,16 +840,12 @@ void serializeInfo(JsonObject root) #endif root[F("freeheap")] = getFreeHeapSize(); - #ifdef ARDUINO_ARCH_ESP32 + #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) // Report PSRAM information - bool hasPsram = psramFound(); - root[F("psramPresent")] = hasPsram; - if (hasPsram) { - #if defined(BOARD_HAS_PSRAM) - root[F("psram")] = ESP.getFreePsram(); // Free PSRAM in bytes (backward compatibility) - #endif - root[F("psramSize")] = ESP.getPsramSize() / (1024UL * 1024UL); // Total PSRAM size in MB - } + // Free PSRAM in bytes (backward compatibility) + root[F("psram")] = ESP.getFreePsram(); + // Total PSRAM size in MB, round up to correct for allocator overhead + root[F("psrSz")] = (ESP.getPsramSize() + (1024U * 1024U - 1)) / (1024U * 1024U); #endif root[F("uptime")] = millis()/1000 + rolloverMillis*4294967; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b918866c..5b7e1f13 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -423,9 +423,13 @@ void WLED::setup() #if defined(BOARD_HAS_PSRAM) // if JSON buffer allocation fails requestJsonBufferLock() will always return false preventing crashes - pDoc = new PSRAMDynamicJsonDocument(2 * JSON_BUFFER_SIZE); - DEBUG_PRINTF_P(PSTR("JSON buffer size: %ubytes\n"), (2 * JSON_BUFFER_SIZE)); - DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024); + if (psramFound() && ESP.getPsramSize()) { + pDoc = new PSRAMDynamicJsonDocument(2 * JSON_BUFFER_SIZE); + DEBUG_PRINTF_P(PSTR("JSON buffer size: %ubytes\n"), (2 * JSON_BUFFER_SIZE)); + DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024); + } else { + pDoc = new DynamicJsonDocument(JSON_BUFFER_SIZE); // Use onboard RAM instead as a fallback + } #endif #if defined(ARDUINO_ARCH_ESP32)