Skip to content

Commit b942b93

Browse files
authored
Merge pull request #11786 from JakubAndrysek/http-client/refactor-serial
refactor(http-client): Replace USE_SERIAL with direct Serial
2 parents 42a95ed + bc656a1 commit b942b93

File tree

4 files changed

+44
-52
lines changed

4 files changed

+44
-52
lines changed

libraries/HTTPClient/examples/Authorization/Authorization.ino

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212

1313
#include <HTTPClient.h>
1414

15-
#define USE_SERIAL Serial
16-
1715
WiFiMulti wifiMulti;
1816

1917
void setup() {
2018

21-
USE_SERIAL.begin(115200);
19+
Serial.begin(115200);
2220

23-
USE_SERIAL.println();
24-
USE_SERIAL.println();
25-
USE_SERIAL.println();
21+
Serial.println();
22+
Serial.println();
23+
Serial.println();
2624

2725
for (uint8_t t = 4; t > 0; t--) {
28-
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
29-
USE_SERIAL.flush();
26+
Serial.printf("[SETUP] WAIT %d...\n", t);
27+
Serial.flush();
3028
delay(1000);
3129
}
3230

@@ -39,7 +37,7 @@ void loop() {
3937

4038
HTTPClient http;
4139

42-
USE_SERIAL.print("[HTTP] begin...\n");
40+
Serial.print("[HTTP] begin...\n");
4341
// configure traged server and url
4442

4543
http.begin("http://user:[email protected]/test.html");
@@ -54,22 +52,22 @@ void loop() {
5452
http.setAuthorization("dXNlcjpwYXN3b3Jk");
5553
*/
5654

57-
USE_SERIAL.print("[HTTP] GET...\n");
55+
Serial.print("[HTTP] GET...\n");
5856
// start connection and send HTTP header
5957
int httpCode = http.GET();
6058

6159
// httpCode will be negative on error
6260
if (httpCode > 0) {
6361
// HTTP header has been send and Server response header has been handled
64-
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
62+
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
6563

6664
// file found at server
6765
if (httpCode == HTTP_CODE_OK) {
6866
String payload = http.getString();
69-
USE_SERIAL.println(payload);
67+
Serial.println(payload);
7068
}
7169
} else {
72-
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
70+
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
7371
}
7472

7573
http.end();

libraries/HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include <HTTPClient.h>
1414

15-
#define USE_SERIAL Serial
16-
1715
WiFiMulti wifiMulti;
1816

1917
/*
@@ -49,15 +47,15 @@ const char* ca = \
4947

5048
void setup() {
5149

52-
USE_SERIAL.begin(115200);
50+
Serial.begin(115200);
5351

54-
USE_SERIAL.println();
55-
USE_SERIAL.println();
56-
USE_SERIAL.println();
52+
Serial.println();
53+
Serial.println();
54+
Serial.println();
5755

5856
for (uint8_t t = 4; t > 0; t--) {
59-
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
60-
USE_SERIAL.flush();
57+
Serial.printf("[SETUP] WAIT %d...\n", t);
58+
Serial.flush();
6159
delay(1000);
6260
}
6361

@@ -70,27 +68,27 @@ void loop() {
7068

7169
HTTPClient http;
7270

73-
USE_SERIAL.print("[HTTP] begin...\n");
71+
Serial.print("[HTTP] begin...\n");
7472
// configure traged server and url
7573
//http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
7674
http.begin("http://example.com/index.html"); //HTTP
7775

78-
USE_SERIAL.print("[HTTP] GET...\n");
76+
Serial.print("[HTTP] GET...\n");
7977
// start connection and send HTTP header
8078
int httpCode = http.GET();
8179

8280
// httpCode will be negative on error
8381
if (httpCode > 0) {
8482
// HTTP header has been send and Server response header has been handled
85-
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
83+
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
8684

8785
// file found at server
8886
if (httpCode == HTTP_CODE_OK) {
8987
String payload = http.getString();
90-
USE_SERIAL.println(payload);
88+
Serial.println(payload);
9189
}
9290
} else {
93-
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
91+
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
9492
}
9593

9694
http.end();

libraries/HTTPClient/examples/ReuseConnection/ReuseConnection.ino

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@
1212

1313
#include <HTTPClient.h>
1414

15-
#define USE_SERIAL Serial
16-
1715
WiFiMulti wifiMulti;
1816

1917
HTTPClient http;
2018

2119
void setup() {
2220

23-
USE_SERIAL.begin(115200);
21+
Serial.begin(115200);
2422

25-
USE_SERIAL.println();
26-
USE_SERIAL.println();
27-
USE_SERIAL.println();
23+
Serial.println();
24+
Serial.println();
25+
Serial.println();
2826

2927
for (uint8_t t = 4; t > 0; t--) {
30-
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
31-
USE_SERIAL.flush();
28+
Serial.printf("[SETUP] WAIT %d...\n", t);
29+
Serial.flush();
3230
delay(1000);
3331
}
3432

@@ -47,14 +45,14 @@ void loop() {
4745

4846
int httpCode = http.GET();
4947
if (httpCode > 0) {
50-
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
48+
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
5149

5250
// file found at server
5351
if (httpCode == HTTP_CODE_OK) {
54-
http.writeToStream(&USE_SERIAL);
52+
http.writeToStream(&Serial);
5553
}
5654
} else {
57-
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
55+
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
5856
}
5957

6058
http.end();

libraries/HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212

1313
#include <HTTPClient.h>
1414

15-
#define USE_SERIAL Serial
16-
1715
WiFiMulti wifiMulti;
1816

1917
void setup() {
2018

21-
USE_SERIAL.begin(115200);
19+
Serial.begin(115200);
2220

23-
USE_SERIAL.println();
24-
USE_SERIAL.println();
25-
USE_SERIAL.println();
21+
Serial.println();
22+
Serial.println();
23+
Serial.println();
2624

2725
for (uint8_t t = 4; t > 0; t--) {
28-
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
29-
USE_SERIAL.flush();
26+
Serial.printf("[SETUP] WAIT %d...\n", t);
27+
Serial.flush();
3028
delay(1000);
3129
}
3230

@@ -39,18 +37,18 @@ void loop() {
3937

4038
HTTPClient http;
4139

42-
USE_SERIAL.print("[HTTP] begin...\n");
40+
Serial.print("[HTTP] begin...\n");
4341

4442
// configure server and url
4543
http.begin("http://192.168.1.12/test.html");
4644
//http.begin("192.168.1.12", 80, "/test.html");
4745

48-
USE_SERIAL.print("[HTTP] GET...\n");
46+
Serial.print("[HTTP] GET...\n");
4947
// start connection and send HTTP header
5048
int httpCode = http.GET();
5149
if (httpCode > 0) {
5250
// HTTP header has been send and Server response header has been handled
53-
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
51+
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
5452

5553
// file found at server
5654
if (httpCode == HTTP_CODE_OK) {
@@ -74,7 +72,7 @@ void loop() {
7472
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
7573

7674
// write it to Serial
77-
USE_SERIAL.write(buff, c);
75+
Serial.write(buff, c);
7876

7977
if (len > 0) {
8078
len -= c;
@@ -83,11 +81,11 @@ void loop() {
8381
delay(1);
8482
}
8583

86-
USE_SERIAL.println();
87-
USE_SERIAL.print("[HTTP] connection closed or file end.\n");
84+
Serial.println();
85+
Serial.print("[HTTP] connection closed or file end.\n");
8886
}
8987
} else {
90-
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
88+
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
9189
}
9290

9391
http.end();

0 commit comments

Comments
 (0)