Description
Hi
I'm using ESP8266 V2.4.2
Noticed that when I upgraded from V2.4.1 that regularly if I use the "close" connection vs "open" it fails to read HTTP headers correctly. Worked all fine on V2.4.0 and V2.4.1
Not sure what the issue it. As said - works perfectly if I use Connection: open on V2.4.2 but not "Connection: close"
The call I'm using is:
client.print(String("GET ") + url_local + " HTTP/1.1\r\n" +
"Host: " + host_local + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n"); // close connection
----------------------------- Delete below -----------------------------
If your issue is a general question, starts similar to "How do I..", is related to 3rd party libs, or is related to hardware, please discuss at a community forum like esp8266.com.
INSTRUCTIONS
If you do not follow these instructions, your issue may be dismissed.
- Follow the checklist under Basic Infos and fill in the [ ] spaces with an X.
- Fill in all the fields under Platform and Settings in IDE marked with [ ] (pick the correct option for you in each case, delete the others).
- If you haven't already done so, test your issue against current master branch (aka latest git), because it may have been already fixed.
- Describe your problem.
- If you have a STACK DUMP decode it:
https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/stack_dump.html
- Include a Minimal Complete Reproducible Example sketch that shows your issue. Do not include your entire project, or a huge piece of code.
- Include debug messages:
https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html
- Use markup (buttons above) and the Preview tab to check what the issue will look like.
- Delete these instructions from the above to the below marker lines before submitting this issue.
----------------------------- Delete above -----------------------------
Basic Infos
- This issue complies with the issue POLICY doc.I have read the documentation at readthedocs and the issue is not addressed there.I have tested that the issue is present in current master branch (aka latest git).I have searched the issue tracker for a similar issue.If there is a stack dump, I have decoded it.I have filled out all fields below.
Platform
- Hardware: [ESP-12|ESP-01|ESP-07|ESP8285 device|other]
- Core Version: [latest git hash or date]
- Development Env: [Arduino IDE|Platformio|Make|other]
- Operating System: [Windows|Ubuntu|MacOS]
Settings in IDE
- Module: [Generic ESP8266 Module|Wemos D1 mini r2|Nodemcu|other]
- Flash Mode: [qio|dio|other]
- Flash Size: [4MB/1MB]
- lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz|160MHz]
- Upload Using: [OTA|SERIAL]
- Upload Speed: [115200|other] (serial upload only)
Problem Description
Detailed problem description goes here.
MCVE Sketch
#include <Arduino.h>
void setup() {
}
void loop() {
}
Debug Messages
Debug messages go here
Activity
d-a-v commentedon Aug 18, 2018
Please provide an MCVE and give more details about its behavior.
DonKracho commentedon Aug 18, 2018
I can confirm this. I updated to 2.4.2 because I had issues to get the WIFI_AP mode to run stable. My web pages exceed the max size of 2920 bytes, therefore I send them in 3 chunks.
The header starts with: "HTTP/1.1 200 OK\n\Content-Type: text/html\n\Connection: close\n\n" followed by the page content itself.
With 2.4.2 the web page is broken (contains only parts of the last client.print() call for the body). I reverted to 2.4.0rc2 and everything is fine again without changing the sketch.
To me it looks like in 2.4.2 client.stop(); works asynchrounus and does not wait for the last client.print() to be completed.
Btw: My page uses websockets. These start very delayed with 2.4.2 in 2.4.0rc2 it is like expected.
d-a-v commentedon Aug 18, 2018
Maybe related to #5021. full MCVE is welcome.
igrr commentedon Aug 19, 2018
Could you please confirm whether calling
client.flush()
beforeclient.stop()
works around the problem?TheNitek commentedon Aug 19, 2018
Same problem here. client.flush() right before client.stop() did NOT change anything. Problem still exists.
d-a-v commentedon Aug 20, 2018
This issues looks like the other above mentioned #5021 which is a user error with a sketch that worked with previous versions (unknown reason so far) but badly handling http protocol. Browser's header was not fully read (It can be fixed by at least honoring browser by reading its full http header before closing the connection).
Without MCVE, we can't help. We need more details.
Scippi commentedon Aug 20, 2018
I've posted this short MCVE Sketch also in #5021.
As @TheNitek mentioned before client.flush() did NOT change anything.
I've used version 2.4.2.
Remove the last client.stop() to show the page in browser.
d-a-v commentedon Aug 20, 2018
Same observation as #5021
I updated your code as follow:
It's working and shows:
meaning that you read '\r\n\r' and not the final '\n'
Reading it makes the browser happy.
Yet,
DonKracho commentedon Aug 20, 2018
Hi David
you are welcome. I also prepared a small scetch stripped down to the basic needs. It opens a WiFi_STA connection. The IP given in the serial monitor keyed in into a browser adress field should show up a web page with a table with 30 rows and the text 'Web page complete.' at the end. I'm using the arduino IDE 1.8.5. The target is a generic ESP-01, but is reproduceable with other targets, like WeMos mini too.
With 2.4.0 (rc2) the page shows up fine in 2.4.2 the table is broken at coincidentally positions due to missing content.
B.t.w. I'm cleaning the client request by calling client.flush(),
devyte commentedon Aug 21, 2018
Some comments here:
d-a-v commentedon Aug 21, 2018
@DonKracho same issue (read the full header until an empty line terminated by
\r\n
before.stop()
).@ALL Why not use the integrated WebServer library ?
mars000 commentedon Aug 21, 2018
hi - being the originator of this issue I'm somewhat confused with the conclusion reached in this thread.
Is this in fact an error in V2.4.2 core ? I'm using very standard method of reading header information before I read the body.
@devyte, not 100% what you mean by "About backwards compatibility, we try to maintain it as much as possible in minor releases, but we don't keep bugs around to service apps that rely on them. In other words, if an app happens to work due to a bug in our core, and then that bug gets fixed, expect to have to update the app."
Code below. Using V2.4.2 line labelled [LINE100] sometimes returns a false BUT it works perfectly in V2.4.1
d-a-v commentedon Aug 21, 2018
@mars000
There is a MCVE request in the issue template, and you did not provided it in the first place.
Meanwhile, others with similar issue came to yours and provided their MCVE. @devyte conclusion is about their issues.
Now that you are giving part of what would be your MCVE, we can see this is a different issue.
The
::connected()
function has ideed changed, it was :It is now since #4626:
Your MCVE not beeing complete, I can't reproduce neither say more about this.
We'd love to solve any backward compatibility issue, be we can't if we are blind.
Please provide an MCVE, or give as much details as you can.
This is not clear enough
...
Well, after re-reading, if the connection is supposed to close at any time, but there are still data to read, use
@ALL please provide details of your issues, we are here to help you with the core, and we are not paid for that, help us help you !
DonKracho commentedon Aug 21, 2018
@d-a-v did you have the chance to try my scetch?
Moving the client.flush() line or inserting your suggested code line with the client.read() before the client.stop() does not solve the issue.
This is the complete http get request of a current chrome browser:
client.readStringUntil('\r'); breaks after the first line is read. If there is a '\n' depends on the client OS. To clear the entire input queue at least a client.flush() has to be done. One client.read() just reads one more char from the input and there remains a lot of input in the queue.
The Chrome browser just sends out all this stuff and really does not care if anybody is reading it! Chrome just waits for a well formed response. If this does not come in time it shows up a timeout.
The client.read() just puts a little delay before the client.stop() and therfore may solve the issue for small web pages. Intentionally I made my web page response much longer (at least it has to be larger than 1460 bytes).
In order to get my code to run 'stable' I have to put a delay of minimal 75us before the client.stop().
My conclusion: The behavior of client.print() or client.stop() has changed somewhere between 2.4.0(rc2) and 2.4.2 Either the clinet.print() does return before it is finished or client.stop() does not wait for all transmission activites to be finished.
d-a-v commentedon Aug 22, 2018
@DonKracho
client.flush()
empties the input buffer (= read full header), while in fact it waits for the output buffer to be emptied (so in your case it does nothing). I reckon this name is misleading but we follow Arduino specs.\r\n
is not OS-dependent in the HTTP protocol. Header's EOL is\r\n
for every OS. It's an inter-OS protocol, not a text file.client.read()
solving another issue is right because in that sketch, the last\n
of the final header line\r\n\r\n
was left in the incoming buffer thus not acknowledged to the browser. Res-pect-ful until the last bit we need to be with protocols.edit Once you have read all the header and written your answer, add a
client.flush()
just beforeclient.stop()
5 remaining items