diff --git a/wled00/data/index.js b/wled00/data/index.js index 168a5e2ac3..c6759f8128 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -3443,8 +3443,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 f23080135f..f55983e915 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -839,16 +839,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 29ff3be082..36502fda78 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -395,9 +395,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)