Merge branch '0_15' into multiwifi

This commit is contained in:
Blaz Kristan
2024-02-01 16:49:55 +01:00
20 changed files with 497 additions and 196 deletions

View File

@@ -34,6 +34,8 @@ void WLED::reset()
void WLED::loop()
{
static uint32_t lastHeap = UINT32_MAX;
static unsigned long heapTime = 0;
#ifdef WLED_DEBUG
static unsigned long lastRun = 0;
unsigned long loopMillis = millis();
@@ -151,6 +153,21 @@ void WLED::loop()
createEditHandler(false);
}
// reconnect WiFi to clear stale allocations if heap gets too low
if (millis() - heapTime > 15000) {
uint32_t heap = ESP.getFreeHeap();
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
DEBUG_PRINT(F("Heap too low! ")); DEBUG_PRINTLN(heap);
forceReconnect = true;
strip.resetSegments(); // remove all but one segments from memory
} else if (heap < MIN_HEAP_SIZE) {
DEBUG_PRINTLN(F("Heap low, purging segments."));
strip.purgeSegments();
}
lastHeap = heap;
heapTime = millis();
}
//LED settings have been saved, re-init busses
//This code block causes severe FPS drop on ESP32 with the original "if (busConfigs[0] != nullptr)" conditional. Investigate!
if (doInitBusses) {
@@ -386,7 +403,7 @@ void WLED::setup()
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
//DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
#ifdef WLED_DEBUG
#if defined(WLED_DEBUG) && !defined(WLED_DEBUG_HOST)
pinManager.allocatePin(hardwareTX, true, PinOwner::DebugOut); // TX (GPIO1 on ESP32) reserved for debug output
#endif
#ifdef WLED_ENABLE_DMX //reserve GPIO2 as hardcoded DMX pin
@@ -891,8 +908,6 @@ void WLED::handleConnection()
{
static bool scanDone = true;
static byte stacO = 0;
static uint32_t lastHeap = UINT32_MAX;
static unsigned long heapTime = 0;
unsigned long now = millis();
const bool wifiConfigured = WLED_WIFI_CONFIGURED;
@@ -911,21 +926,6 @@ void WLED::handleConnection()
return;
}
// reconnect WiFi to clear stale allocations if heap gets too low
if (now - heapTime > 5000) {
uint32_t heap = ESP.getFreeHeap();
if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) {
DEBUG_PRINT(F("Heap too low! "));
DEBUG_PRINTLN(heap);
forceReconnect = true;
strip.resetSegments();
} else if (heap < MIN_HEAP_SIZE) {
strip.purgeSegments();
}
lastHeap = heap;
heapTime = now;
}
byte stac = 0;
if (apActive) {
#ifdef ESP8266
@@ -974,8 +974,19 @@ void WLED::handleConnection()
initConnection();
}
if (!apActive && now - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) {
DEBUG_PRINTLN(F("Not connected AP."));
initAP();
if (!(apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT)) {
DEBUG_PRINTLN(F("Not connected AP."));
initAP(); // start AP only within first 5min
}
}
if (apActive && apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT && stac == 0) { // disconnect AP after 5min if no clients connected
// if AP was enabled more than 10min after boot or if client was connected more than 10min after boot do not disconnect AP mode
if (now < 2*WLED_AP_TIMEOUT) {
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;
DEBUG_PRINTLN(F("Temporary AP disabled."));
}
}
} else if (!interfacesInited) { //newly connected
DEBUG_PRINTLN();
@@ -996,7 +1007,7 @@ void WLED::handleConnection()
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;
DEBUG_PRINTLN(F("Access point disabled (handle)."));
DEBUG_PRINTLN(F("Access point disabled (connected)."));
}
}
}