fix: data output via web server on ESP32 fixed

This commit is contained in:
Yurii
2024-01-18 23:37:12 +03:00
parent 5e3751ca03
commit 99088fb723
5 changed files with 29 additions and 26 deletions

Binary file not shown.

View File

@@ -16,18 +16,21 @@ public:
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
return;
}
#else
this->webServer->send(code, contentType, "");
#endif
this->webServer->setContentLength(measureJson(content));
#else
this->webServer->setContentLength(CONTENT_LENGTH_UNKNOWN);
this->webServer->sendHeader(F("Content-Length"), String(measureJson(content)));
this->webServer->send(code, contentType, emptyString);
#endif
serializeJson(content, *this);
this->flush();
#ifdef ARDUINO_ARCH_ESP8266
this->webServer->chunkedResponseFinalize();
#else
this->webServer->sendContent("");
this->webServer->sendContent(emptyString);
#endif
}

View File

@@ -72,7 +72,8 @@ public:
return true;
}
#else
server.send(200, F("text/html"), "");
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/html", emptyString);
#endif
uint8_t* argStartPos = nullptr;
@@ -209,7 +210,7 @@ public:
#ifdef ARDUINO_ARCH_ESP8266
server.chunkedResponseFinalize();
#else
server.sendContent("");
server.sendContent(emptyString);
#endif
return true;

View File

@@ -349,19 +349,11 @@ protected:
auto apCount = WiFi.scanComplete();
if (apCount <= 0) {
if (apCount != WIFI_SCAN_RUNNING) {
WiFi.scanNetworks(true, true);
if (apCount == WIFI_SCAN_RUNNING || apCount == WIFI_SCAN_FAILED) {
this->webServer->send(202);
} else if (apCount == 0) {
this->webServer->send(200, "application/json", "[]");
} else {
this->webServer->send(500);
}
this->webServer->send(404);
return;
}
@@ -374,11 +366,11 @@ protected:
doc[i]["hidden"] = !ssid.length();
doc[i]["encryptionType"] = WiFi.encryptionType(i);
}
WiFi.scanDelete();
doc.shrinkToFit();
this->bufferedWebServer->send(200, "application/json", doc);
WiFi.scanDelete();
});
@@ -522,7 +514,7 @@ protected:
void loop() {
// web server
if (!this->stateWebServer()) {
if (!this->stateWebServer() && (network->isApEnabled() || network->isStaEnabled())) {
this->startWebServer();
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started"));

View File

@@ -171,26 +171,33 @@ function setupNetworkScanForm(formSelector, tableSelector) {
}
};
let attempts = 5;
let timer = setInterval(async () => {
let attempts = 6;
let attemptFn = async () => {
attempts--;
try {
let response = await fetch(url, { cache: 'no-cache' });
if (response.status == 200) {
clearInterval(timer);
await onSuccess(response);
} else if (attempts <= 0) {
await onFailed(response);
} else {
setTimeout(attemptFn, 5000);
}
} catch (err) {
clearInterval(timer);
if (attempts <= 0) {
onFailed(err);
} else {
setTimeout(attemptFn, 10000);
}
}, 2000);
}
};
attemptFn();
};
form.addEventListener('submit', onSubmitFn);