avoid infinite disconnect loops when RAM is low
This commit is contained in:
@@ -344,6 +344,7 @@
|
|||||||
#define ERR_OVERTEMP 30 // An attached temperature sensor has measured above threshold temperature (not implemented)
|
#define ERR_OVERTEMP 30 // An attached temperature sensor has measured above threshold temperature (not implemented)
|
||||||
#define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented)
|
#define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented)
|
||||||
#define ERR_UNDERVOLT 32 // An attached voltmeter has measured a voltage below the threshold (not implemented)
|
#define ERR_UNDERVOLT 32 // An attached voltmeter has measured a voltage below the threshold (not implemented)
|
||||||
|
#define ERR_LOW_MEM 33 // low memory (RAM)
|
||||||
|
|
||||||
// Timer mode types
|
// Timer mode types
|
||||||
#define NL_MODE_SET 0 //After nightlight time elapsed, set to target brightness
|
#define NL_MODE_SET 0 //After nightlight time elapsed, set to target brightness
|
||||||
|
|||||||
@@ -1967,6 +1967,9 @@ function readState(s,command=false)
|
|||||||
case 19:
|
case 19:
|
||||||
errstr = "A filesystem error has occured.";
|
errstr = "A filesystem error has occured.";
|
||||||
break;
|
break;
|
||||||
|
case 33:
|
||||||
|
errstr = "Warning: Low Memory (RAM).";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
showToast('Error ' + s.error + ": " + errstr, true);
|
showToast('Error ' + s.error + ": " + errstr, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1205,6 +1205,7 @@ void WLED::handleConnection()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned retryCount = 0; // WLEDMM
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
// reconnect WiFi to clear stale allocations if heap gets too low
|
// reconnect WiFi to clear stale allocations if heap gets too low
|
||||||
if (now - heapTime > 5000) { // WLEDMM: updated with better logic for small heap available by block, not total.
|
if (now - heapTime > 5000) { // WLEDMM: updated with better logic for small heap available by block, not total.
|
||||||
@@ -1214,10 +1215,16 @@ void WLED::handleConnection()
|
|||||||
uint32_t heap = heap_caps_get_largest_free_block(0x1800); // WLEDMM: This is a better metric for free heap.
|
uint32_t heap = heap_caps_get_largest_free_block(0x1800); // WLEDMM: This is a better metric for free heap.
|
||||||
#endif
|
#endif
|
||||||
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
|
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
|
||||||
USER_PRINT(F("Heap too low! (step 2, force reconnect): "));
|
if (retryCount < 5) { // WLEDMM avoid repeated disconnects
|
||||||
USER_PRINTLN(heap);
|
USER_PRINT(F("Heap too low! (step 2, force reconnect): "));
|
||||||
forceReconnect = true;
|
USER_PRINTLN(heap);
|
||||||
strip.purgeSegments(true); // remove all but one segments from memory
|
forceReconnect = true;
|
||||||
|
strip.purgeSegments(true); // remove all but one segments from memory
|
||||||
|
// WLEDMM
|
||||||
|
errorFlag = ERR_LOW_MEM;
|
||||||
|
retryCount ++;
|
||||||
|
}
|
||||||
|
errorFlag = ERR_LOW_MEM;
|
||||||
} else if (heap < MIN_HEAP_SIZE) {
|
} else if (heap < MIN_HEAP_SIZE) {
|
||||||
USER_PRINT(F("Heap too low! (step 1, flush unread UDP): "));
|
USER_PRINT(F("Heap too low! (step 1, flush unread UDP): "));
|
||||||
USER_PRINTLN(heap);
|
USER_PRINTLN(heap);
|
||||||
@@ -1226,7 +1233,10 @@ void WLED::handleConnection()
|
|||||||
rgbUdp.flush();
|
rgbUdp.flush();
|
||||||
notifier2Udp.flush();
|
notifier2Udp.flush();
|
||||||
ntpUdp.flush();
|
ntpUdp.flush();
|
||||||
}
|
// WLEDMM
|
||||||
|
errorFlag = ERR_LOW_MEM;
|
||||||
|
retryCount = 1;
|
||||||
|
} else retryCount = 0; // WLEDMM memory OK - reset counter
|
||||||
lastHeap = heap;
|
lastHeap = heap;
|
||||||
heapTime = now;
|
heapTime = now;
|
||||||
}
|
}
|
||||||
@@ -1235,15 +1245,22 @@ void WLED::handleConnection()
|
|||||||
if (now - heapTime > 5000) {
|
if (now - heapTime > 5000) {
|
||||||
uint32_t heap = ESP.getFreeHeap();
|
uint32_t heap = ESP.getFreeHeap();
|
||||||
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
|
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
|
||||||
USER_PRINT(F("Heap too low! (step 2, force reconnect): "));
|
if (retryCount < 5) { // WLEDMM avoid repeated disconnects
|
||||||
USER_PRINTLN(heap);
|
USER_PRINT(F("Heap too low! (step 2, force reconnect): "));
|
||||||
forceReconnect = true;
|
USER_PRINTLN(heap);
|
||||||
strip.purgeSegments(true); // remove all but one segments from memory
|
forceReconnect = true;
|
||||||
|
strip.purgeSegments(true); // remove all but one segments from memory
|
||||||
|
// WLEDMM
|
||||||
|
errorFlag = ERR_LOW_MEM;
|
||||||
|
}
|
||||||
} else if (heap < MIN_HEAP_SIZE) {
|
} else if (heap < MIN_HEAP_SIZE) {
|
||||||
USER_PRINT(F("Heap too low! (step 1, purge segments): "));
|
USER_PRINT(F("Heap too low! (step 1, purge segments): "));
|
||||||
USER_PRINTLN(heap);
|
USER_PRINTLN(heap);
|
||||||
strip.purgeSegments();
|
strip.purgeSegments();
|
||||||
}
|
// WLEDMM
|
||||||
|
errorFlag = ERR_LOW_MEM;
|
||||||
|
retryCount = 1;
|
||||||
|
} else retryCount = 0; // WLEDMM memory OK - reset counter
|
||||||
lastHeap = heap;
|
lastHeap = heap;
|
||||||
heapTime = now;
|
heapTime = now;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2402180
|
#define VERSION 2402230
|
||||||
|
|
||||||
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
|
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
|
||||||
#define _MoonModules_WLED_
|
#define _MoonModules_WLED_
|
||||||
|
|||||||
Reference in New Issue
Block a user