Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit d2cc3d7

Browse files
authored
v1.8.0 to fix bug and optimize code
### Releases v1.8.0 1. Fix long timeout if using bad `IPAddress` 2. Optimize code 3. Display only successful responseText in examples 4. Improve debug messages by adding functions to display error messages instead of `cryptic error number`
1 parent fa55285 commit d2cc3d7

File tree

6 files changed

+93
-51
lines changed

6 files changed

+93
-51
lines changed

examples/AsyncCustomHeader/AsyncCustomHeader.ino

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
//char GET_ServerAddress[] = "192.168.2.110/";
2020
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
2121

22-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.7.1"
23-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1007001
22+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.0"
23+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008000
24+
25+
// Level from 0-4
26+
#define ASYNC_HTTP_DEBUG_PORT Serial
27+
#define _ASYNC_HTTP_LOGLEVEL_ 2
2428

2529
// 600s = 10 minutes to not flooding, 60s in testing
2630
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -63,24 +67,28 @@ void sendRequest()
6367
}
6468
}
6569

66-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
70+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
6771
{
6872
(void) optParm;
69-
73+
7074
if (readyState == readyStateDone)
7175
{
72-
Serial.println("\n**************************************");
73-
Serial.println(request->responseText());
74-
Serial.println("**************************************");
76+
AHTTP_LOGDEBUG(F("\n**************************************"));
77+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
7578

76-
request->setDebug(false);
79+
if (request->responseHTTPcode() == 200)
80+
{
81+
Serial.println(F("\n**************************************"));
82+
Serial.println(request->responseText());
83+
Serial.println(F("**************************************"));
84+
}
7785
}
7886
}
7987

8088
void setup()
8189
{
8290
Serial.begin(115200);
83-
while (!Serial);
91+
while (!Serial && millis() < 5000);
8492

8593
Serial.print("\nStart AsyncCustomHeader on "); Serial.println(BOARD_NAME);
8694
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

examples/AsyncDweetGet/AsyncDweetGet.ino

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ const char GET_ServerAddress[] = "dweet.io";
3030
// use your own thing name here
3131
String dweetName = "/dweet/for/currentSecond?second=";
3232

33-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.7.1"
34-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1007001
33+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.0"
34+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008000
35+
36+
// Level from 0-4
37+
#define ASYNC_HTTP_DEBUG_PORT Serial
38+
#define _ASYNC_HTTP_LOGLEVEL_ 2
3539

3640
// 600s = 10 minutes to not flooding, 60s in testing
3741
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -112,14 +116,19 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
112116

113117
if (readyState == readyStateDone)
114118
{
115-
String responseText = request->responseText();
116-
117-
Serial.println("\n**************************************");
118-
//Serial.println(request->responseText());
119-
Serial.println(responseText);
120-
Serial.println("**************************************");
119+
AHTTP_LOGWARN(F("\n**************************************"));
120+
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
121121

122-
parseResponse(responseText);
122+
if (request->responseHTTPcode() == 200)
123+
{
124+
String responseText = request->responseText();
125+
126+
Serial.println("\n**************************************");
127+
Serial.println(responseText);
128+
Serial.println("**************************************");
129+
130+
parseResponse(responseText);
131+
}
123132

124133
request->setDebug(false);
125134
}
@@ -128,7 +137,7 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
128137
void setup()
129138
{
130139
Serial.begin(115200);
131-
while (!Serial);
140+
while (!Serial && millis() < 5000);
132141

133142
Serial.print("\nStart AsyncDweetGET on "); Serial.println(BOARD_NAME);
134143
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

examples/AsyncDweetPost/AsyncDweetPost.ino

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ const char POST_ServerAddress[] = "dweet.io";
2424
// use your own thing name here
2525
String dweetName = "/dweet/for/pinA0-Read?";
2626

27-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.7.1"
28-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1007001
27+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.0"
28+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008000
29+
30+
// Level from 0-4
31+
#define ASYNC_HTTP_DEBUG_PORT Serial
32+
#define _ASYNC_HTTP_LOGLEVEL_ 2
2933

3034
// 600s = 10 minutes to not flooding, 60s in testing
3135
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -111,14 +115,19 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
111115

112116
if (readyState == readyStateDone)
113117
{
114-
String responseText = request->responseText();
115-
116-
Serial.println("\n**************************************");
117-
//Serial.println(request->responseText());
118-
Serial.println(responseText);
119-
Serial.println("**************************************");
118+
AHTTP_LOGWARN(F("\n**************************************"));
119+
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
120120

121-
parseResponse(responseText);
121+
if (request->responseHTTPcode() == 200)
122+
{
123+
String responseText = request->responseText();
124+
125+
Serial.println("\n**************************************");
126+
Serial.println(responseText);
127+
Serial.println("**************************************");
128+
129+
parseResponse(responseText);
130+
}
122131

123132
request->setDebug(false);
124133
}
@@ -127,7 +136,7 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
127136
void setup()
128137
{
129138
Serial.begin(115200);
130-
while (!Serial);
139+
while (!Serial && millis() < 5000);
131140

132141
Serial.print("\nStart AsyncDweetPOST on "); Serial.println(BOARD_NAME);
133142
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

examples/AsyncHTTPRequest/AsyncHTTPRequest.ino

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
// Level from 0-4
4444
#define ASYNC_HTTP_DEBUG_PORT Serial
45-
#define _ASYNC_HTTP_LOGLEVEL_ 4
45+
#define _ASYNC_HTTP_LOGLEVEL_ 2
4646

4747
// 600s = 10 minutes to not flooding, 60s in testing
4848
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -84,24 +84,28 @@ void sendRequest()
8484
}
8585
}
8686

87-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
87+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
8888
{
8989
(void) optParm;
90-
91-
if (readyState == readyStateDone)
90+
91+
if (readyState == readyStateDone)
9292
{
93-
Serial.println("\n**************************************");
94-
Serial.println(request->responseText());
95-
Serial.println("**************************************");
96-
97-
request->setDebug(false);
93+
AHTTP_LOGDEBUG(F("\n**************************************"));
94+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
95+
96+
if (request->responseHTTPcode() == 200)
97+
{
98+
Serial.println(F("\n**************************************"));
99+
Serial.println(request->responseText());
100+
Serial.println(F("**************************************"));
101+
}
98102
}
99103
}
100104

101105
void setup()
102106
{
103107
Serial.begin(115200);
104-
while (!Serial);
108+
while (!Serial && millis() < 5000);
105109

106110
Serial.print("\nStart AsyncHTTPRequest on "); Serial.println(BOARD_NAME);
107111
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

examples/AsyncSimpleGET/AsyncSimpleGET.ino

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
//char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/";
2020
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
2121

22-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.7.1"
23-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1007001
22+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.0"
23+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008000
24+
25+
// Level from 0-4
26+
#define ASYNC_HTTP_DEBUG_PORT Serial
27+
#define _ASYNC_HTTP_LOGLEVEL_ 2
2428

2529
// 600s = 10 minutes to not flooding, 60s in testing
2630
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -61,24 +65,28 @@ void sendRequest()
6165
}
6266
}
6367

64-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
68+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
6569
{
6670
(void) optParm;
67-
71+
6872
if (readyState == readyStateDone)
6973
{
70-
Serial.println("\n**************************************");
71-
Serial.println(request->responseText());
72-
Serial.println("**************************************");
74+
AHTTP_LOGDEBUG(F("\n**************************************"));
75+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
7376

74-
request->setDebug(false);
77+
if (request->responseHTTPcode() == 200)
78+
{
79+
Serial.println(F("\n**************************************"));
80+
Serial.println(request->responseText());
81+
Serial.println(F("**************************************"));
82+
}
7583
}
7684
}
7785

7886
void setup()
7987
{
8088
Serial.begin(115200);
81-
while (!Serial);
89+
while (!Serial && millis() < 5000);
8290

8391
Serial.print("\nStart AsyncSimpleGET on "); Serial.println(BOARD_NAME);
8492
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

examples/multiFileProject/multiFileProject.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
#error Only Teensy 4.1 supported
2222
#endif
2323

24-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.7.1"
25-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1007001
24+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.0"
25+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008000
26+
27+
// Level from 0-4
28+
#define ASYNC_HTTP_DEBUG_PORT Serial
29+
#define _ASYNC_HTTP_LOGLEVEL_ 2
2630

2731
#include "multiFileProject.h"
2832

@@ -32,7 +36,7 @@
3236
void setup()
3337
{
3438
Serial.begin(115200);
35-
while (!Serial);
39+
while (!Serial && millis() < 5000);
3640

3741
Serial.println("\nStart multiFileProject");
3842
Serial.println(ASYNC_HTTP_REQUEST_TEENSY41_VERSION);

0 commit comments

Comments
 (0)