-
Notifications
You must be signed in to change notification settings - Fork 13.3k
bugfix2/ESP8266HTTPClient #6476
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bf1f107
Because of git problems, start from a new fork and create a new PR. T…
6e80ffd
Style update to pass Travis
2cad10b
Merge branch 'master' into bugfix2/ESP8266HTTPClient
d-a-v a1f275f
Update ReuseConnectionV2.ino
d-a-v 1107d2c
Merge branch 'master' into bugfix2/ESP8266HTTPClient
d-a-v c7a19f5
fix + enforce testing http code
d-a-v c4e0cbe
Merge branch 'master' into bugfix2/ESP8266HTTPClient
d-a-v f947b86
Close connection before ::connecting on HTTP/1.0
earlephilhower e92905e
Adjust example per request
earlephilhower d708587
Fix astyle
earlephilhower 3782845
Clean up final pass notice
earlephilhower e62e6a0
Fix example syntax error
earlephilhower a3a545d
Merge branch 'master' into bugfix2/ESP8266HTTPClient
devyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
libraries/ESP8266HTTPClient/examples/ReuseConnectionV2/ReuseConnectionV2.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
reuseConnectionV2.ino | ||
|
||
Created on: 22.11.2015 | ||
|
||
This example reuses the http connection and also restores the connection if the connection is lost | ||
*/ | ||
|
||
|
||
#include <ESP8266WiFi.h> | ||
#include <ESP8266WiFiMulti.h> | ||
#include <ESP8266HTTPClient.h> | ||
|
||
#ifndef STASSID | ||
#define STASSID "your-ssid" | ||
#define STAPSK "your-password" | ||
#endif | ||
|
||
ESP8266WiFiMulti WiFiMulti; | ||
|
||
HTTPClient http; | ||
WiFiClient client; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
// Serial.setDebugOutput(true); | ||
|
||
Serial.println(); | ||
Serial.println(); | ||
Serial.println("Connecting to WiFi..."); | ||
|
||
WiFi.mode(WIFI_STA); | ||
WiFiMulti.addAP(STASSID, STAPSK); | ||
|
||
// wait for WiFi connection | ||
while ((WiFiMulti.run() != WL_CONNECTED)) { | ||
Serial.write('.'); | ||
delay(500); | ||
} | ||
Serial.println(" connected to WiFi"); | ||
|
||
// allow reuse (if server supports it) | ||
http.setReuse(true); | ||
|
||
|
||
http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html"); | ||
//http.begin(client, "jigsaw.w3.org", 80, "/HTTP/connection.html"); | ||
} | ||
|
||
void loop() { | ||
for (int i = 0; i < 10; i++) { | ||
Serial.printf("Reuse connection example, GET url for the %d time\n", i + 1); | ||
int httpCode = http.GET(); | ||
if (httpCode > 0) { | ||
Serial.printf("[HTTP] GET... code: %d\n", httpCode); | ||
|
||
// file found at server | ||
if (httpCode == HTTP_CODE_OK) { | ||
http.writeToStream(&Serial); | ||
} | ||
} else { | ||
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); | ||
// Something went wrong with the connection, try to reconnect | ||
http.end(); | ||
http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html"); | ||
//http.begin(client, "jigsaw.w3.org", 80, "/HTTP/connection.html"); | ||
} | ||
|
||
Serial.println("\n\n\nWait 5 second...\n"); | ||
delay(5000); | ||
} | ||
|
||
http.end(); | ||
|
||
Serial.println("Done testing, now wait forever"); | ||
for (;;) { | ||
earlephilhower marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delay(100); // Wait forever | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.