-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Feature/http update #1979
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
Feature/http update #1979
Conversation
…setLedPin() commented out because not all boards support LED_BUITLIN
…Correct WiFiClient::setTimeout() to call Stream::setTimeout() with seconds converted back to milliseconds. Remove inproper checks for _insecure.
I observed, among others, quite some timeouts on doing a secure firmware update using HTTPClient (as stated before, actually I do not write directly to a HTTPClient for an update but I use HTTPUpdate of this PR, and HTTPUpdate uses HTTPClient). I think the root cause of this lies in the fact that, in contrast to the ESP8266 WiFiClient, the ESP32 WiFiClient has a method WiFiClient::setTimeout(uint32_t seconds). This means that when HTTPClient calls _client -> setTimeout() it calls WiFiClient::setTimeout(uint32_t seconds) and not Stream::setTimeout(unsigned long timeout). Also note that the WiFiClient::setTimout() parameter is in seconds while the Stream::setTimeout() parameter is in milliseconds The consequences of these errors are:
To make things even worse, WiFiClient::setTimeout() does not call Stream::setTimeout(). This means that the timeout for the Stream is the default timeout of 1,000 ms. This again means that Stream::readBytes(), Stream::readBytesUntil(), Stream::readString() and Stream::readStringUntil() will not get the same timeout as HTTPClient(), which is normally much longer (5000 ms, and even longer). This is true for both insecure and secure connections! The next thing I observe is that PR #934 introduces a test on !_secure in HTTPClient::getStream(). It is perfectly legal to return a secure stream and reading from it, so this check is invalid. To correct all this, I made the following changes:
In this way the library functions behavior change is kept to the bare minimum necessary for correcting the errors. Still the consequence of this is that an insecure connection now gets a reasonable timeout while before it had a timeout that was 1,000 times too long (so virtually no timeout at all). Also now a secure connection gets a timeout. Finally, since reasonable timeouts on a HTTPClient are longer that 1,000 ms (the default for the Stream timeout), the Stream::readBytes(), Stream::readBytesUntil(), Stream::readString() and Stream::readStringUntil() now get more time than 1s to complete. I expect this PR will solve issue #1443. I expect that the change in this PR will lead to less timeouts and more completed downloads! |
@lbernstone @me-no-dev Any chance that these commits will be merged soon? |
Added HTTPUpdate class for downloading sketches from a server. It is somewhat similar to AWS_S3_OTA_update.ino from the libraries/Update/examples, however the adapted HTTPClient from PR #1973 is used in stead of printing HTTP headers directly to the client.
An example usage httpUpdateSecure.ino is given. This updates a firmware over a secure connection using the WiFiClientSecure class and a CA certificate. Of course a non secure WiFiClient may also be used.
The good thing is: it works. A bad thing might be that a few features that are present in the similar library for the ESP8266 are not present in this library. The reason for this is that these features rely on functions not (yet) implemented in the ESP32 libraries. However, these features are not essential to the functionality of the HTTPUpdate library. The missing features are:
The Update class is also changed:
The HTTPClient from PR #1973 is included in this PR, because HTTPUpdate depends on it