Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By Sigmax
#66764 Hi There !

I got my ESP8266 board working as a webserver. Whenever it receives a web request, I respond with:

Code: Select allvoid arranqueweb()
{
   server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   server.sendHeader("Pragma", "no-cache");
   server.sendHeader("Expires", "-1");
   //server.sendHeader("Content-Length", "-1");
   server.setContentLength(CONTENT_LENGTH_UNKNOWN);
   server.send(200, "text/html", "");
   server.sendContent("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><meta name=\"apple-mobile-web-app-capable\" content=\"yes\" /><meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\" /><style>body {font-family:arial;} </style>");
   server.sendContent("</head><body><h1>Node 1</h1>");
   server.sendContent("<h6>Node test v 0.5</h6></body></html>");
   server.client().stop();
}


When using Arduino esp8266 v2.3.0 core (http://arduino.esp8266.com/stable/packa ... index.json) my code worked *almost* ok: The only problem was on the web browser, in my computer, which after receiving the webpage generated by the code above, it kept busy (like if waiting something from the server) for 5 more seconds.

So I decided to give Arduino core v2.4.0rc1 for esp8266 a try, on the hope that this was a bug which has been solved.

After compiling my code using v2.4.0rc1, and making the same request from my computer with Google Chrome, into the ESP8266 web server, now Chrome shows my page -even faster than before, I think-, but then it keeps indefinitely in a loading state. So it is much worse.

When "inspecting" the network traffic (using Google Chrome's inspect), I can see that at first the page is 200 OK, but after a second or so of finishing loading, this change into:

Status: failed
net::ERR_INCOMPLETE_CHUNKED_ENCODING

Am I missing something ? (surely I am !)

Any help is most appreciated!

Enrique
User avatar
By gbafamily1
#66825 I suggest starting with one of the ESP8266WebServer examples and see if it works with your client. If so, modify your code to make it work like the example.

Comment 1:

Code: Select all//server.sendHeader("Content-Length", "-1");
   server.setContentLength(CONTENT_LENGTH_UNKNOWN);


I suggest commenting out both lines. If the server is not sending the correct length, do not send the Content-Length header.

Comment 2:

Define a big string constant for the web page. server.send() will send the data as well as send the Content-Length header.

Code: Select allconst char INDEX_HTML[] = R"=====(
<!DOCTYPE html>
<html>
... Your html, css, javascript goes here.
</html>
)=====" ;

server.send(200, "text/html", INDEX_HTML);
User avatar
By Reap Star
#66875 I found doing doing a sendContent(""); seemed to work to end the connection. I gather the chunked encoding scheme ends with a zero length chunk.

...
server.sendContent(" content .... ");
... <maybe more server.sendContent calls> ...
server.sendContent("");
server.client().stop();
...
Seemed to work for me