File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed
Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments