-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Feature/http client #1973
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 client #1973
Conversation
…() functions deprecated. Updated library version to 1.2
…estroyed before WiFiClientSecure
…Correct WiFiClient::setTimeout() to call Stream::setTimeout() with seconds converted back to milliseconds. Remove inproper checks for _insecure.
|
No, port 80 is the default port for a http connection, this is added by the client because your url starts with http.
This is the place where things go wrong
But this should not happen. This error appeared before, because _client was not inititialized to nullptr. This is corrected in PR #2097 Could you merge the latest core and next this PR and try again? Please report back if your issue was solved. If not, please create a new issue in stead of a comment in a PR |
Thank you for your response. "Could you merge the latest core and next this PR and try again?" This is still generating the issue. For now, I have rolled back to the previous release and it appears to be working. |
Do you re-install using git? Then you might read the instructions at e.g https://gist.github.com/adam-p/15413fabef6cffecd897 If you install using a zip file, it is probably easier to edit the file yourself and change it. In line 211 of file libraries/HTTPClient/src/HTTPClient.h you should change:
into:
|
Thank you very much, I edited the file and that fixed it! |
|
||
Serial.print(F("Waiting for NTP time sync: ")); | ||
time_t nowSecs = time(nullptr); | ||
while (nowSecs < 8 * 3600 * 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions:
- Why not define (or calculate) this static value outside the loop?
- Why exactly > 1.1.1970 4pm? Shouldn't it be larger than let's say 1546300800 (2019-01-01T00:00:00+00:00)? In my experience 16h is not enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelstoer do you mean 8 * 3600 * 2 with 'this static value'? If so, you shouldn't bother, the compiler will replace it with a static value.
Basically the value is quite arbitrary, any big enough value will do. time(nullptr) will return the number of seconds since the last reset, until it is overwritten by the NTP time sync. After that time(nullptr) is far bigger than the static test value and the while loop exits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time_t starts counting at the unix Epoch which you can read up about here.
If the time sync takes more than 16 hours there is a serious issue with network connectivity and time sync!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean 8 * 3600 * 2 with 'this static value'?
Errhm, yes. Sorry. I should have said "constant" when I mean "constant".
the compiler will replace it with a static value
True, the comment was more a style nitpick (and in that quit subjective I know).
@Jeroen88 @atanisoft for my second comment I was drawing from ESP8266 (i.e. NONOS SDK) experience, maybe it doesn't apply here anymore. For devices that spent most of their life in deep sleep we had to ensure that the constant value was a somewhat recent timestamp - at least from the current century. Otherwise, we might get nowSecs
values that are way off. while
loops a handful of times. Hence, it has nothing to do with "time sync takes more than 16 hours" or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelstoer I do not have any experience with deep sleep, but if time(nullptr) keeps running in deep sleep, the while() will break inmediately. I can imagine that in that case the ESP time and the real (network / NTP time) have drifted, and that you do want to have a time sync. The only thing I can think of here is to force a NTP time sync.
@atanisoft I didn't test it, but a freshly booted ESP32 could only initiate it's time after it has connected to the network, I guess? So some kind of waiting should be introduced to ensure synchronization has finished?
Add two begin() methods to HTTPClient() to pass a WiFiClientSecure client with setCACert() and/or setCertificate() and setPrivateKey() already set. Include an example BasicHttpsClient.ino to show the usage. This adaptation aligns this library with ESP8266HTTPClient. The 5 begin() methods that already existed are set deprecated and the library version is updated to 1.2.
Currently backwards compatibility is maintained, but the idea is to drop all code enclosed within #ifdef HTTPCLIENT_1_1_COMPATIBLE and #endif, when a new version of the core is released.
When using this library make sure that the passed in WiFiClientSecure 'lives' longer than the HTPPClient including it's destructor! In the example this is achieved by adding an extra scoping block { ... } for HTTPClient, to make sure it is destructed at the end of the block in stead of at the end of the function.