Skip to content

Commit 6b953d9

Browse files
authored
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
1 parent 3d33bae commit 6b953d9

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

wled00/data/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,8 +3396,8 @@ function reportUpgradeEvent(info, oldVersion) {
33963396
};
33973397

33983398
// Add optional fields if available
3399-
if (infoData.psramPresent !== undefined) upgradeData.psramPresent = infoData.psramPresent; // Whether device has PSRAM
3400-
if (infoData.psramSize !== undefined) upgradeData.psramSize = infoData.psramSize; // Total PSRAM size in MB
3399+
if (infoData.psrSz !== undefined) upgradeData.psramSize = infoData.psrSz; // Total PSRAM size in MB; can be 0
3400+
34013401
// Note: partitionSizes not currently available in /json/info endpoint
34023402

34033403
// Make AJAX call to postUpgradeEvent API

wled00/json.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,12 @@ void serializeInfo(JsonObject root)
840840
#endif
841841

842842
root[F("freeheap")] = getFreeHeapSize();
843-
#ifdef ARDUINO_ARCH_ESP32
843+
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
844844
// Report PSRAM information
845-
bool hasPsram = psramFound();
846-
root[F("psramPresent")] = hasPsram;
847-
if (hasPsram) {
848-
#if defined(BOARD_HAS_PSRAM)
849-
root[F("psram")] = ESP.getFreePsram(); // Free PSRAM in bytes (backward compatibility)
850-
#endif
851-
root[F("psramSize")] = ESP.getPsramSize() / (1024UL * 1024UL); // Total PSRAM size in MB
852-
}
845+
// Free PSRAM in bytes (backward compatibility)
846+
root[F("psram")] = ESP.getFreePsram();
847+
// Total PSRAM size in MB, round up to correct for allocator overhead
848+
root[F("psrSz")] = (ESP.getPsramSize() + (1024U * 1024U - 1)) / (1024U * 1024U);
853849
#endif
854850
root[F("uptime")] = millis()/1000 + rolloverMillis*4294967;
855851

wled00/wled.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,13 @@ void WLED::setup()
423423

424424
#if defined(BOARD_HAS_PSRAM)
425425
// if JSON buffer allocation fails requestJsonBufferLock() will always return false preventing crashes
426-
pDoc = new PSRAMDynamicJsonDocument(2 * JSON_BUFFER_SIZE);
427-
DEBUG_PRINTF_P(PSTR("JSON buffer size: %ubytes\n"), (2 * JSON_BUFFER_SIZE));
428-
DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024);
426+
if (psramFound() && ESP.getPsramSize()) {
427+
pDoc = new PSRAMDynamicJsonDocument(2 * JSON_BUFFER_SIZE);
428+
DEBUG_PRINTF_P(PSTR("JSON buffer size: %ubytes\n"), (2 * JSON_BUFFER_SIZE));
429+
DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024);
430+
} else {
431+
pDoc = new DynamicJsonDocument(JSON_BUFFER_SIZE); // Use onboard RAM instead as a fallback
432+
}
429433
#endif
430434

431435
#if defined(ARDUINO_ARCH_ESP32)

0 commit comments

Comments
 (0)