wifi timeouts, small changes for sd card access
This commit is contained in:
parent
7e20aa65e1
commit
de44c789af
|
|
@ -550,16 +550,20 @@ void DirectoryNode::streamDirectoryHTML(Print &out) const {
|
||||||
out.print(F("\"><b>"));
|
out.print(F("\"><b>"));
|
||||||
out.print(name);
|
out.print(name);
|
||||||
out.println(F("</b></li>"));
|
out.println(F("</b></li>"));
|
||||||
|
delay(0); // Yield to allow network stack to send buffered data
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(0);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < mp3Files.size(); i++) {
|
for (size_t i = 0; i < mp3Files.size(); i++) {
|
||||||
out.print(F("<li data-id=\""));
|
out.print(F("<li data-id=\""));
|
||||||
out.print(ids[i]);
|
out.print(ids[i]);
|
||||||
out.print(F("\">"));
|
out.print(F("\">"));
|
||||||
out.print(mp3Files[i]);
|
out.print(mp3Files[i]);
|
||||||
out.println(F("</li>"));
|
out.println(F("</li>"));
|
||||||
|
|
||||||
|
// Yield every few items to allow the async web server to send buffered data
|
||||||
|
if (i % 5 == 4) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (DirectoryNode* child : subdirectories) {
|
for (DirectoryNode* child : subdirectories) {
|
||||||
|
|
@ -568,6 +572,7 @@ void DirectoryNode::streamDirectoryHTML(Print &out) const {
|
||||||
|
|
||||||
if (name == "/") {
|
if (name == "/") {
|
||||||
out.println(F("</ul>"));
|
out.println(F("</ul>"));
|
||||||
|
delay(0); // Final yield before completing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
src/main.cpp
11
src/main.cpp
|
|
@ -618,7 +618,9 @@ void writeSongProgress(const char *filename, uint16_t id, uint32_t seconds)
|
||||||
file.print(" ");
|
file.print(" ");
|
||||||
file.println(seconds);
|
file.println(seconds);
|
||||||
file.close();
|
file.close();
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println("Progress written: ID " + String(id) + ", s " + String(seconds));
|
Serial.println("Progress written: ID " + String(id) + ", s " + String(seconds));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1225,7 +1227,10 @@ server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
server.on("/directory", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/directory", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
webreq_enter();
|
webreq_enter();
|
||||||
request->onDisconnect([](){ webreq_exit(); });
|
request->onDisconnect([](){ webreq_exit(); sd_lock_release(); });
|
||||||
|
// Acquire SD lock to prevent concurrent modifications to directory tree
|
||||||
|
// and to prevent audio playback from interrupting the stream
|
||||||
|
sd_lock_acquire();
|
||||||
// Stream the response directly from the directory tree to avoid large temporary Strings
|
// Stream the response directly from the directory tree to avoid large temporary Strings
|
||||||
AsyncResponseStream* stream = request->beginResponseStream(txt_html_charset);
|
AsyncResponseStream* stream = request->beginResponseStream(txt_html_charset);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -1420,9 +1425,9 @@ void setup()
|
||||||
wifiManager.setRemoveDuplicateAPs(true); // Remove duplicate APs from memory
|
wifiManager.setRemoveDuplicateAPs(true); // Remove duplicate APs from memory
|
||||||
|
|
||||||
// Reduce timeouts to free memory faster
|
// Reduce timeouts to free memory faster
|
||||||
wifiManager.setTimeout(60); // Reduced from 180
|
wifiManager.setTimeout(180); // Reduced from 180
|
||||||
wifiManager.setConnectTimeout(15); // Faster connection attempts
|
wifiManager.setConnectTimeout(15); // Faster connection attempts
|
||||||
wifiManager.setConfigPortalTimeout(60); // Shorter portal timeout
|
wifiManager.setConfigPortalTimeout(90); // Shorter portal timeout
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println(F("Deactivating Brownout detector..."));
|
Serial.println(F("Deactivating Brownout detector..."));
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ setInterval(updateProgress, 500); // Update progress every second
|
||||||
var timeoutMs;
|
var timeoutMs;
|
||||||
if ((this.__url || '').indexOf('/upload') !== -1) {
|
if ((this.__url || '').indexOf('/upload') !== -1) {
|
||||||
timeoutMs = 600000; // 10 minutes for uploads
|
timeoutMs = 600000; // 10 minutes for uploads
|
||||||
|
} else if ((this.__url || '').indexOf('/directory') !== -1) {
|
||||||
|
timeoutMs = 30000; // 30 seconds for directory listing (can be large)
|
||||||
} else if (this.__method === 'GET') {
|
} else if (this.__method === 'GET') {
|
||||||
timeoutMs = 6000;
|
timeoutMs = 6000;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -497,4 +499,3 @@ function deleteFileOnServer() {
|
||||||
};
|
};
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue