Open php4fan opened 10 months ago
I tested on several versions. It broke somewhere between:
3.0.2 Works
3.1.0 Broken
This might be #8237, can you try and change wificlient
to http.getStream()
:
size_t avl = wificlient.available();
gotbytes = wificlient.readBytes(httpbuf, ((avl>sizeof(httpbuf))?sizeof(httpbuf):avl));
to
size_t avl = http.getStream().available();
gotbytes = http.getStream().readBytes(httpbuf, ((avl>sizeof(httpbuf))?sizeof(httpbuf):avl));
This might be #8237, can you try and change
wificlient
tohttp.getStream()
:
Right, clone() copies client ctx but does not share it. Have to remove its self-deletion first (see delete this;
), to persist it across objects. iirc I gave up writing adaptor b/c we have to re-write client & secure-client anyway (...at some point :)
Indeed, the workaround works.
Also this works:
//...
httpcode=http.GET();
WiFiClient httpstream = http.getStream(); // <<<<<<<<<<
//...
//....
size_t avl = httpstream.available();
gotbytes = httpstream.readBytes(// .....
but only as long as getStream()
is called after http.GET()
.
I had actually tried some variation of this (without knowing why, but suspecting that getStream
"did something weird"), but crucially I had put the getStream()
call before http.GET()
and when it made no difference I was like "of course it doesn't, what a crazy idea 🙄".
You can also try with this
toSend = min(1000, stillToSend); // 1000 depending on how much time you can spend in Stream::sendSize()
stillToSend -= http.getStream().sendSize(file, toSend); // file is a Stream
I've tried the workaround with getStream()
, and it works for me too.
But it's 100x time slower to download!!
The workaround is backward compatible, but it's still fast on 3.0.2.
Basic Infos
Platform
Settings in IDE
Problem Description
In 2019 I wrote a sketch that downloads text from a url using HTTPClient. I uploaded it to a few boards and it has been working flawlessly, and still is.
Now I updated Arduino and the ESP8266 core to the latest version, re-compiled my code (I needed to change a call to
HTTPClient::begin()
because of BC-breaking changes in the API) and uploaded it to one of the boards), and now the download systematically gets stuck after downloading the http headers, waiting forever for the next bytes to become available.The hardware is the same, the network is the same, the server I'm downloading from is the same, my code hasn't changed one bit (except again for the
HTTPClient::begin()
call). Literally the only thing that has changed is I switched to the latest version of Arduino IDE, the core and the libraries.Code that used to work (that was well tested and has been working without issue for 4 years on a dozen of devices on different wifi networks) is now broken after the update.
Unfortunately I hadn't updated the libraries in the last 4 years, so I don't know when in the last 4 years the bug appeared.
I'm sorry I don't have the time to create a minimal but full working example, and I cannot share the full code because it's too complex. I'll share the part of the code that does the http download.
MCVE Sketch
Debug Messages
The output from the code above is: