Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e1f1f2

Browse filesBrowse files
tigoesandeepmistry
authored andcommitted
Updated examples and readme.md
1 parent b6424e4 commit 5e1f1f2
Copy full SHA for 5e1f1f2

File tree

Expand file treeCollapse file tree

12 files changed

+39
-79
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+39
-79
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Derived from [Adrian McEwen's HttpClient library](https://github.com/amcewen/Htt
77
## Dependencies
88

99
- Requires a networking hardware and a library that provides transport specific `Client` instance, such as:
10+
- [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA)
1011
- [WiFi101](https://github.com/arduino-libraries/WiFi101)
1112
- [Ethernet](https://github.com/arduino-libraries/Ethernet)
1213
- [WiFi](https://github.com/arduino-libraries/WiFi)

‎examples/BasicAuthGet/BasicAuthGet.ino

Copy file name to clipboardExpand all lines: examples/BasicAuthGet/BasicAuthGet.ino
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
GET client with HTTP basic authentication for ArduinoHttpClient library
33
Connects to server once every five seconds, sends a GET request
44
5-
6-
75
created 14 Feb 2016
86
by Tom Igoe
97
modified 3 Jan 2017 to add HTTP basic authentication
108
by Sandeep Mistry
9+
modified 22 Jan 2019
10+
by Tom Igoe
1111
1212
this example is in the public domain
1313
*/
@@ -25,8 +25,6 @@ int port = 8080;
2525
WiFiClient wifi;
2626
HttpClient client = HttpClient(wifi, serverAddress, port);
2727
int status = WL_IDLE_STATUS;
28-
String response;
29-
int statusCode = 0;
3028

3129
void setup() {
3230
Serial.begin(9600);
@@ -56,8 +54,8 @@ void loop() {
5654
client.endRequest();
5755

5856
// read the status code and body of the response
59-
statusCode = client.responseStatusCode();
60-
response = client.responseBody();
57+
int statusCode = client.responseStatusCode();
58+
String response = client.responseBody();
6159

6260
Serial.print("Status code: ");
6361
Serial.println(statusCode);
@@ -66,4 +64,3 @@ void loop() {
6664
Serial.println("Wait five seconds");
6765
delay(5000);
6866
}
69-

‎examples/CustomHeader/CustomHeader.ino

Copy file name to clipboardExpand all lines: examples/CustomHeader/CustomHeader.ino
+8-13Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
22
Custom request header example for the ArduinoHttpClient
33
library. This example sends a GET and a POST request with a custom header every 5 seconds.
44
5-
note: WiFi SSID and password are stored in config.h file.
6-
If it is not present, add a new tab, call it "config.h"
7-
and add the following variables:
8-
char ssid[] = "ssid"; // your network SSID (name)
9-
char pass[] = "password"; // your network password
10-
115
based on SimpleGet example by Tom Igoe
126
header modifications by Todd Treece
7+
modified 22 Jan 2019
8+
by Tom Igoe
139
1410
this example is in the public domain
15-
*/
16-
11+
*/
12+
1713
#include <ArduinoHttpClient.h>
1814
#include <WiFi101.h>
1915

@@ -29,8 +25,6 @@ int port = 8080;
2925
WiFiClient wifi;
3026
HttpClient client = HttpClient(wifi, serverAddress, port);
3127
int status = WL_IDLE_STATUS;
32-
String response;
33-
int statusCode = 0;
3428

3529
void setup() {
3630
Serial.begin(9600);
@@ -53,16 +47,15 @@ void setup() {
5347
}
5448

5549
void loop() {
56-
5750
Serial.println("making GET request");
5851
client.beginRequest();
5952
client.get("/");
6053
client.sendHeader("X-CUSTOM-HEADER", "custom_value");
6154
client.endRequest();
6255

6356
// read the status code and body of the response
64-
statusCode = client.responseStatusCode();
65-
response = client.responseBody();
57+
int statusCode = client.responseStatusCode();
58+
String response = client.responseBody();
6659

6760
Serial.print("GET Status code: ");
6861
Serial.println(statusCode);
@@ -81,6 +74,8 @@ void loop() {
8174
client.sendHeader("X-CUSTOM-HEADER", "custom_value");
8275
client.endRequest();
8376
client.write((const byte*)postData.c_str(), postData.length());
77+
// note: the above line can also be achieved with the simpler line below:
78+
//client.print(postData);
8479

8580
// read the status code and body of the response
8681
statusCode = client.responseStatusCode();

‎examples/DweetGet/DweetGet.ino

Copy file name to clipboardExpand all lines: examples/DweetGet/DweetGet.ino
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
1010
For more on dweet.io, see https://dweet.io/play/
1111
12-
13-
1412
created 15 Feb 2016
15-
updated 16 Feb 2016
13+
updated 22 Jan 2019
1614
by Tom Igoe
1715
1816
this example is in the public domain
@@ -33,8 +31,6 @@ String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here
3331
WiFiClient wifi;
3432
HttpClient client = HttpClient(wifi, serverAddress, port);
3533
int status = WL_IDLE_STATUS;
36-
int statusCode = 0;
37-
String response;
3834

3935
void setup() {
4036
Serial.begin(9600);
@@ -66,8 +62,8 @@ void loop() {
6662
client.get(path);
6763

6864
// read the status code and body of the response
69-
statusCode = client.responseStatusCode();
70-
response = client.responseBody();
65+
int statusCode = client.responseStatusCode();
66+
String response = client.responseBody();
7167
Serial.print("Status code: ");
7268
Serial.println(statusCode);
7369
Serial.print("Response: ");

‎examples/DweetPost/DweetPost.ino

Copy file name to clipboardExpand all lines: examples/DweetPost/DweetPost.ino
+3-11Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
66
Shows how to use Strings to assemble path and body
77
8-
note: WiFi SSID and password are stored in config.h file.
9-
If it is not present, add a new tab, call it "config.h"
10-
and add the following variables:
11-
char ssid[] = "ssid"; // your network SSID (name)
12-
char pass[] = "password"; // your network password
13-
148
created 15 Feb 2016
9+
modified 22 Jan 2019
1510
by Tom Igoe
1611
1712
this example is in the public domain
@@ -31,8 +26,6 @@ int port = 80;
3126
WiFiClient wifi;
3227
HttpClient client = HttpClient(wifi, serverAddress, port);
3328
int status = WL_IDLE_STATUS;
34-
int statusCode = 0;
35-
String response;
3629

3730
void setup() {
3831
Serial.begin(9600);
@@ -59,7 +52,6 @@ void loop() {
5952
// assemble the path for the POST message:
6053
String dweetName = "scandalous-cheese-hoarder";
6154
String path = "/dweet/for/" + dweetName;
62-
6355
String contentType = "application/json";
6456

6557
// assemble the body of the POST message:
@@ -74,8 +66,8 @@ void loop() {
7466
client.post(path, contentType, postData);
7567

7668
// read the status code and body of the response
77-
statusCode = client.responseStatusCode();
78-
response = client.responseBody();
69+
int statusCode = client.responseStatusCode();
70+
String response = client.responseBody();
7971

8072
Serial.print("Status code: ");
8173
Serial.println(statusCode);

‎examples/HueBlink/HueBlink.ino

Copy file name to clipboardExpand all lines: examples/HueBlink/HueBlink.ino
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
This example shows how to concatenate Strings to assemble the
1414
PUT request and the body of the request.
1515
16-
17-
1816
modified 15 Feb 2016
1917
by Tom Igoe (tigoe) to match new API
2018
*/
@@ -97,6 +95,4 @@ void sendRequest(int light, String cmd, String value) {
9795
Serial.print("Server response: ");
9896
Serial.println(response);
9997
Serial.println();
100-
}
101-
102-
98+
}

‎examples/PostWithHeaders/PostWithHeaders.ino

Copy file name to clipboardExpand all lines: examples/PostWithHeaders/PostWithHeaders.ino
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Connects to server once every five seconds, sends a POST request
44
with custome headers and a request body
55
6-
7-
86
created 14 Feb 2016
97
by Tom Igoe
108
modified 18 Mar 2017
119
by Sandeep Mistry
10+
modified 22 Jan 2019
11+
by Tom Igoe
1212
1313
this example is in the public domain
1414
*/
@@ -29,8 +29,6 @@ int port = 8080;
2929
WiFiClient wifi;
3030
HttpClient client = HttpClient(wifi, serverAddress, port);
3131
int status = WL_IDLE_STATUS;
32-
String response;
33-
int statusCode = 0;
3432

3533
void setup() {
3634
Serial.begin(9600);
@@ -66,8 +64,8 @@ void loop() {
6664
client.endRequest();
6765

6866
// read the status code and body of the response
69-
statusCode = client.responseStatusCode();
70-
response = client.responseBody();
67+
int statusCode = client.responseStatusCode();
68+
String response = client.responseBody();
7169

7270
Serial.print("Status code: ");
7371
Serial.println(statusCode);

‎examples/SimpleDelete/SimpleDelete.ino

Copy file name to clipboardExpand all lines: examples/SimpleDelete/SimpleDelete.ino
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
Connects to server once every five seconds, sends a DELETE request
44
and a request body
55
6-
7-
86
created 14 Feb 2016
7+
modified 22 Jan 2019
98
by Tom Igoe
109
1110
this example is in the public domain
@@ -27,8 +26,6 @@ int port = 8080;
2726
WiFiClient wifi;
2827
HttpClient client = HttpClient(wifi, serverAddress, port);
2928
int status = WL_IDLE_STATUS;
30-
String response;
31-
int statusCode = 0;
3229

3330
void setup() {
3431
Serial.begin(9600);
@@ -58,8 +55,8 @@ void loop() {
5855
client.del("/", contentType, delData);
5956

6057
// read the status code and body of the response
61-
statusCode = client.responseStatusCode();
62-
response = client.responseBody();
58+
int statusCode = client.responseStatusCode();
59+
String response = client.responseBody();
6360

6461
Serial.print("Status code: ");
6562
Serial.println(statusCode);

‎examples/SimpleGet/SimpleGet.ino

Copy file name to clipboardExpand all lines: examples/SimpleGet/SimpleGet.ino
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
Simple GET client for ArduinoHttpClient library
33
Connects to server once every five seconds, sends a GET request
44
5-
6-
75
created 14 Feb 2016
6+
modified 22 Jan 2019
87
by Tom Igoe
98
109
this example is in the public domain
@@ -19,15 +18,12 @@
1918
char ssid[] = SECRET_SSID;
2019
char pass[] = SECRET_PASS;
2120

22-
2321
char serverAddress[] = "192.168.0.3"; // server address
2422
int port = 8080;
2523

2624
WiFiClient wifi;
2725
HttpClient client = HttpClient(wifi, serverAddress, port);
2826
int status = WL_IDLE_STATUS;
29-
String response;
30-
int statusCode = 0;
3127

3228
void setup() {
3329
Serial.begin(9600);
@@ -54,8 +50,8 @@ void loop() {
5450
client.get("/");
5551

5652
// read the status code and body of the response
57-
statusCode = client.responseStatusCode();
58-
response = client.responseBody();
53+
int statusCode = client.responseStatusCode();
54+
String response = client.responseBody();
5955

6056
Serial.print("Status code: ");
6157
Serial.println(statusCode);

‎examples/SimplePost/SimplePost.ino

Copy file name to clipboardExpand all lines: examples/SimplePost/SimplePost.ino
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
Connects to server once every five seconds, sends a POST request
44
and a request body
55
6-
7-
86
created 14 Feb 2016
7+
modified 22 Jan 2019
98
by Tom Igoe
109
1110
this example is in the public domain
@@ -19,15 +18,12 @@
1918
char ssid[] = SECRET_SSID;
2019
char pass[] = SECRET_PASS;
2120

22-
2321
char serverAddress[] = "192.168.0.3"; // server address
2422
int port = 8080;
2523

2624
WiFiClient wifi;
2725
HttpClient client = HttpClient(wifi, serverAddress, port);
2826
int status = WL_IDLE_STATUS;
29-
String response;
30-
int statusCode = 0;
3127

3228
void setup() {
3329
Serial.begin(9600);
@@ -57,8 +53,8 @@ void loop() {
5753
client.post("/", contentType, postData);
5854

5955
// read the status code and body of the response
60-
statusCode = client.responseStatusCode();
61-
response = client.responseBody();
56+
int statusCode = client.responseStatusCode();
57+
String response = client.responseBody();
6258

6359
Serial.print("Status code: ");
6460
Serial.println(statusCode);

‎examples/SimplePut/SimplePut.ino

Copy file name to clipboardExpand all lines: examples/SimplePut/SimplePut.ino
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
Connects to server once every five seconds, sends a PUT request
44
and a request body
55
6-
7-
86
created 14 Feb 2016
7+
modified 22 Jan 2019
98
by Tom Igoe
109
1110
this example is in the public domain
@@ -19,15 +18,12 @@
1918
char ssid[] = SECRET_SSID;
2019
char pass[] = SECRET_PASS;
2120

22-
2321
char serverAddress[] = "192.168.0.3"; // server address
2422
int port = 8080;
2523

2624
WiFiClient wifi;
2725
HttpClient client = HttpClient(wifi, serverAddress, port);
2826
int status = WL_IDLE_STATUS;
29-
String response;
30-
int statusCode = 0;
3127

3228
void setup() {
3329
Serial.begin(9600);
@@ -57,8 +53,8 @@ void loop() {
5753
client.put("/", contentType, putData);
5854

5955
// read the status code and body of the response
60-
statusCode = client.responseStatusCode();
61-
response = client.responseBody();
56+
int statusCode = client.responseStatusCode();
57+
String response = client.responseBody();
6258

6359
Serial.print("Status code: ");
6460
Serial.println(statusCode);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.