mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 02:34:29 +05:00
fix: data output via web server on ESP32 fixed
This commit is contained in:
Binary file not shown.
@@ -16,18 +16,21 @@ public:
|
|||||||
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
|
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
this->webServer->send(code, contentType, "");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this->webServer->setContentLength(measureJson(content));
|
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);
|
serializeJson(content, *this);
|
||||||
this->flush();
|
this->flush();
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
this->webServer->chunkedResponseFinalize();
|
this->webServer->chunkedResponseFinalize();
|
||||||
#else
|
#else
|
||||||
this->webServer->sendContent("");
|
this->webServer->sendContent(emptyString);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
server.send(200, F("text/html"), "");
|
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
|
server.send(200, "text/html", emptyString);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t* argStartPos = nullptr;
|
uint8_t* argStartPos = nullptr;
|
||||||
@@ -209,7 +210,7 @@ public:
|
|||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
server.chunkedResponseFinalize();
|
server.chunkedResponseFinalize();
|
||||||
#else
|
#else
|
||||||
server.sendContent("");
|
server.sendContent(emptyString);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -349,19 +349,11 @@ protected:
|
|||||||
|
|
||||||
auto apCount = WiFi.scanComplete();
|
auto apCount = WiFi.scanComplete();
|
||||||
if (apCount <= 0) {
|
if (apCount <= 0) {
|
||||||
WiFi.scanNetworks(true, true);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,11 +366,11 @@ protected:
|
|||||||
doc[i]["hidden"] = !ssid.length();
|
doc[i]["hidden"] = !ssid.length();
|
||||||
doc[i]["encryptionType"] = WiFi.encryptionType(i);
|
doc[i]["encryptionType"] = WiFi.encryptionType(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.scanDelete();
|
|
||||||
doc.shrinkToFit();
|
doc.shrinkToFit();
|
||||||
|
|
||||||
this->bufferedWebServer->send(200, "application/json", doc);
|
this->bufferedWebServer->send(200, "application/json", doc);
|
||||||
|
|
||||||
|
WiFi.scanDelete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -522,7 +514,7 @@ protected:
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// web server
|
// web server
|
||||||
if (!this->stateWebServer()) {
|
if (!this->stateWebServer() && (network->isApEnabled() || network->isStaEnabled())) {
|
||||||
this->startWebServer();
|
this->startWebServer();
|
||||||
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started"));
|
Log.straceln(FPSTR(L_PORTAL_WEBSERVER), F("Started"));
|
||||||
|
|
||||||
|
|||||||
@@ -171,26 +171,33 @@ function setupNetworkScanForm(formSelector, tableSelector) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let attempts = 5;
|
let attempts = 6;
|
||||||
let timer = setInterval(async () => {
|
let attemptFn = async () => {
|
||||||
attempts--;
|
attempts--;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await fetch(url, { cache: 'no-cache' });
|
let response = await fetch(url, { cache: 'no-cache' });
|
||||||
|
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
clearInterval(timer);
|
|
||||||
await onSuccess(response);
|
await onSuccess(response);
|
||||||
|
|
||||||
} else if (attempts <= 0) {
|
} else if (attempts <= 0) {
|
||||||
await onFailed(response);
|
await onFailed(response);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(attemptFn, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
clearInterval(timer);
|
if (attempts <= 0) {
|
||||||
onFailed(err);
|
onFailed(err);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(attemptFn, 10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 2000);
|
};
|
||||||
|
attemptFn();
|
||||||
};
|
};
|
||||||
|
|
||||||
form.addEventListener('submit', onSubmitFn);
|
form.addEventListener('submit', onSubmitFn);
|
||||||
|
|||||||
Reference in New Issue
Block a user