-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP8266 unstable POST/GET requests #3282
Comments
Doesn't matter chunk mode or not. ESP8266 doesn't return full responses to HTTP calls in two cases:
void connectToWifi() {
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/plain", "Connecting...");
WiFi.disconnect();
WiFi.begin("ssid", "password");
WiFi.waitForConnectResult();
// Never comes back as a response to AJAX call when WiFi.waitForConnectResult() is in use
server.sendContent("Done!");
server.sendContent("");
server.client().stop();
// See it in serial monitor no error occurs
Serial.println("Done!");
} Works correctly. The only case I don't get a full response is when it's called right after void getNetworks() {
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/plain", "Scanning...");
String str;
int n = WiFi.scanNetworks();
for(int i=0; i<n; i++) {
str += "\"" + WiFi.SSID(i) + "\"";
if(i < n-1) { str += ","; }
}
// When called right after WiFi.begin() fails to connect, never comes back as a response to AJAX call
server.sendContent("{\"networks\": [" + str + "] }");
server.sendContent("");
server.client().stop();
// See it in serial monitor no error occurs
Serial.println("Done!");
} Any suggestions ? |
This is related to the fact that STA will switch to the channel of the AP it is trying to connect to, and SoftAP will have to switch to the same channel. So the client (PC or smartphone connected to the SoftAP) will have to reconnect to the SoftAP on its new channel. In most cases this causes TCP connections to be reset. |
Thank you for the answer. That problem was already discussed #119. Everything is clear now. |
Basic Infos
Hardware
Hardware: WeMos D1 mini V2 ESP8266 E12
Core Version: 2.3.0
Description
Hi there,
I have a webserver running on my WeMos which provides a simple HTML page. It communicates with the board through AJAX in order to get information about WIFI. I've checked already various issues on github but I'm still a bit confused how to correctly send a response to an AJAX call.
I read about few practices like enabling chunk mode by using
setContentLength(CONTENT_LENGTH_UNKNOWN)
andsendContent()
functions in case content length is unknown and justsend()
function otherwise. Even when I follow those rules sometimes I get empty response immediately and it seems like request was all of sudden interrupted.My doubts
WiFi.begin()
orWiFi.scanNetworks()
finish their jobs or:a) do I need to implement some pooling, send multiple ajax requests and wait for a proper response ?
b) The only way is chunk mode ?
My
getNetworkStatus()
,getNetworks()
andconnectToWifi()
are pretty simple. Can you maybe point me into the right direction how to implement them correctly ?Sketch
scripts.js from home.html
The text was updated successfully, but these errors were encountered: