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

Commit 07e2add

Browse files
authored
v1.9.0 to fix bug and optimize code
### Releases v1.9.0 1. Fix long timeout if using `IPAddress`. Check [setTimeout() hasn't any effect #38](#38) 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` 5. Remove support to STM32 using **LAN8720** due to problem with new STM32 core v2.3.0 5. Update `Packages' Patches`
1 parent dabf181 commit 07e2add

File tree

25 files changed

+524
-438
lines changed

25 files changed

+524
-438
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Please ensure to specify the following:
2929
Arduino IDE version: 1.8.19
3030
ESP32 Core Version 2.0.4
3131
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
3535
I encountered an endless loop while trying to connect to Local WiFi.

README.md

Lines changed: 32 additions & 125 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.9.0](#releases-v190)
1516
* [Releases v1.8.2](#releases-v182)
1617
* [Releases v1.8.1](#releases-v181)
1718
* [Releases v1.8.0](#releases-v180)
@@ -39,6 +40,15 @@
3940

4041
## Changelog
4142

43+
### Releases v1.9.0
44+
45+
1. Fix long timeout if using `IPAddress`. Check [setTimeout() hasn't any effect #38](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/38)
46+
2. Optimize code
47+
3. Display only successful responseText in examples
48+
4. Improve debug messages by adding functions to display error messages instead of `cryptic error number`
49+
5. Remove support to STM32 using **LAN8720** due to problem with new STM32 core v2.3.0
50+
5. Update `Packages' Patches`
51+
4252
### Releases v1.8.2
4353

4454
1. Fix library.properties to remove unavailable items from depends. Check [Remove unavailable items from depends field of library.properties #35](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/pull/35)

examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
//char GET_ServerAddress[] = "192.168.2.110/";
2525
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";
2626

27-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.0"
28-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007000
27+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
28+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
2929

3030
// 600s = 10 minutes to not flooding, 60s in testing
3131
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -68,26 +68,35 @@ void sendRequest(void)
6868
}
6969
}
7070

71-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
71+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
7272
{
7373
(void) optParm;
74-
74+
7575
if (readyState == readyStateDone)
7676
{
77-
Serial.println("\n**************************************");
78-
Serial.println(request->responseText());
79-
Serial.println("**************************************");
77+
Serial.println();
78+
AHTTP_LOGDEBUG(F("**************************************"));
79+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
8080

81-
request->setDebug(false);
81+
if (request->responseHTTPcode() == 200)
82+
{
83+
Serial.println(F("**************************************"));
84+
Serial.println(request->responseText());
85+
Serial.println(F("**************************************"));
86+
}
87+
else
88+
{
89+
AHTTP_LOGERROR(F("Response error"));
90+
}
8291
}
8392
}
8493

8594
void setup(void)
8695
{
8796
Serial.begin(115200);
88-
while (!Serial);
97+
while (!Serial && millis() < 5000);
8998

90-
Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME));
99+
Serial.print("\nStart AsyncCustomHeader_STM32 on "); Serial.println(BOARD_NAME);
91100
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
92101

93102
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)

examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const char GET_ServerAddress[] = "dweet.io";
3535
// use your own thing name here
3636
String dweetName = "/dweet/for/currentSecond?second=";
3737

38-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.0"
39-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007000
38+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
39+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
4040

4141
// 600s = 10 minutes to not flooding, 60s in testing
4242
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -119,25 +119,36 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
119119

120120
if (readyState == readyStateDone)
121121
{
122-
String responseText = request->responseText();
123-
124-
Serial.println("\n**************************************");
125-
//Serial.println(request->responseText());
126-
Serial.println(responseText);
127-
Serial.println("**************************************");
122+
Serial.println();
123+
AHTTP_LOGDEBUG(F("**************************************"));
124+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
128125

129-
parseResponse(responseText);
126+
if (request->responseHTTPcode() == 200)
127+
{
128+
String responseText = request->responseText();
130129

131-
request->setDebug(false);
130+
Serial.println("\n**************************************");
131+
//Serial.println(request->responseText());
132+
Serial.println(responseText);
133+
Serial.println("**************************************");
134+
135+
parseResponse(responseText);
136+
137+
request->setDebug(false);
138+
}
139+
else
140+
{
141+
AHTTP_LOGERROR(F("Response error"));
142+
}
132143
}
133144
}
134145

135146
void setup(void)
136147
{
137148
Serial.begin(115200);
138-
while (!Serial);
139-
140-
Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME));
149+
while (!Serial && millis() < 5000);
150+
151+
Serial.print("\nStart AsyncDweetGET_STM32 on "); Serial.println(BOARD_NAME);
141152
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
142153

143154
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)

examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const char POST_ServerAddress[] = "dweet.io";
2929
// use your own thing name here
3030
String dweetName = "/dweet/for/pinA0-Read?";
3131

32-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.0"
33-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007000
32+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
33+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
3434

3535
// 600s = 10 minutes to not flooding, 60s in testing
3636
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
@@ -116,25 +116,36 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
116116

117117
if (readyState == readyStateDone)
118118
{
119-
String responseText = request->responseText();
120-
121-
Serial.println("\n**************************************");
122-
//Serial.println(request->responseText());
123-
Serial.println(responseText);
124-
Serial.println("**************************************");
119+
Serial.println();
120+
AHTTP_LOGDEBUG(F("**************************************"));
121+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
125122

126-
parseResponse(responseText);
123+
if (request->responseHTTPcode() == 200)
124+
{
125+
String responseText = request->responseText();
127126

128-
request->setDebug(false);
127+
Serial.println("\n**************************************");
128+
//Serial.println(request->responseText());
129+
Serial.println(responseText);
130+
Serial.println("**************************************");
131+
132+
parseResponse(responseText);
133+
134+
request->setDebug(false);
135+
}
136+
else
137+
{
138+
AHTTP_LOGERROR(F("Response error"));
139+
}
129140
}
130141
}
131142

132143
void setup(void)
133144
{
134145
Serial.begin(115200);
135-
while (!Serial);
136-
137-
Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME));
146+
while (!Serial && millis() < 5000);
147+
148+
Serial.print("\nStart AsyncDweetPOST_STM32 on "); Serial.println(BOARD_NAME);
138149
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
139150

140151
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)

examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
4545
#endif
4646

47-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.0"
48-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007000
47+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
48+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
4949

5050
// Level from 0-4
5151
#define ASYNC_HTTP_DEBUG_PORT Serial
52-
#define _ASYNC_HTTP_LOGLEVEL_ 1
52+
#define _ASYNC_HTTP_LOGLEVEL_ 4
5353

5454
// 300s = 5 minutes to not flooding
5555
#define HTTP_REQUEST_INTERVAL 60 //300
@@ -68,10 +68,8 @@ const char* password = "your_pass";
6868
#include <WiFi.h>
6969
#endif
7070

71-
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
72-
7371
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
74-
#include <AsyncHTTPRequest_Impl_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
72+
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
7573

7674
#include <Ticker.h>
7775

@@ -150,9 +148,15 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
150148

151149
if (readyState == readyStateDone)
152150
{
153-
Serial.print(F("\n***************")); Serial.print(requestName[ requestIndex ]); Serial.println(F("***************"));
154-
Serial.println(request->responseText());
155-
Serial.println(F("**************************************"));
151+
AHTTP_LOGDEBUG(F("\n**************************************"));
152+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
153+
154+
if (request->responseHTTPcode() == 200)
155+
{
156+
Serial.print(F("\n***************")); Serial.print(requestName[ requestIndex ]); Serial.println(F("***************"));
157+
Serial.println(request->responseText());
158+
Serial.println(F("**************************************"));
159+
}
156160

157161
#if 1
158162
// Bypass hourly
@@ -163,7 +167,7 @@ void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
163167
#else
164168
// hourly too long, not display anyway. Not enough heap.
165169
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
166-
#endif
170+
#endif
167171

168172
request->setDebug(false);
169173
}
@@ -173,7 +177,7 @@ void setup()
173177
{
174178
// put your setup code here, to run once:
175179
Serial.begin(115200);
176-
while (!Serial);
180+
while (!Serial && millis() < 5000);
177181

178182
delay(200);
179183

examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
// Level from 0-4
4848
#define ASYNC_HTTP_DEBUG_PORT Serial
49-
#define _ASYNC_HTTP_LOGLEVEL_ 1
49+
#define _ASYNC_HTTP_LOGLEVEL_ 1
5050

5151
// 300s = 5 minutes to not flooding
5252
#define HTTP_REQUEST_INTERVAL 60 //300
@@ -65,8 +65,8 @@ const char* password = "your_pass";
6565
#include <WiFi.h>
6666
#endif
6767

68-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.0"
69-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007000
68+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
69+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
7070

7171
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
7272
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
@@ -122,27 +122,29 @@ void sendRequest()
122122
}
123123
}
124124

125-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
125+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
126126
{
127127
(void) optParm;
128-
129-
if (readyState == readyStateDone)
128+
129+
if (readyState == readyStateDone)
130130
{
131-
Serial.println(F("\n**************************************"));
132-
Serial.println(request->responseText());
133-
Serial.println(F("**************************************"));
134-
135-
request->setDebug(false);
131+
AHTTP_LOGDEBUG(F("\n**************************************"));
132+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
133+
134+
if (request->responseHTTPcode() == 200)
135+
{
136+
Serial.println(F("\n**************************************"));
137+
Serial.println(request->responseText());
138+
Serial.println(F("**************************************"));
139+
}
136140
}
137141
}
138142

139143
void setup()
140144
{
141145
// put your setup code here, to run once:
142146
Serial.begin(115200);
143-
while (!Serial);
144-
145-
delay(200);
147+
while (!Serial && millis() < 5000);
146148

147149
Serial.print(F("\nStarting AsyncHTTPRequest_ESP using ")); Serial.println(ARDUINO_BOARD);
148150
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);

examples/AsyncHTTPRequest_ESP8266_Ethernet/AsyncHTTPRequest_ESP8266_Ethernet.ino

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@
9393

9494
using TCPClient = WiFiClient;
9595

96-
97-
98-
99-
10096
//////////////////////////////////////////////////////////
10197

102-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.7.1"
103-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1007001
98+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.9.0"
99+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1009000
104100

105101
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
106102
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
@@ -156,17 +152,21 @@ void sendRequest()
156152
}
157153
}
158154

159-
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
155+
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
160156
{
161157
(void) optParm;
162-
163-
if (readyState == readyStateDone)
158+
159+
if (readyState == readyStateDone)
164160
{
165-
Serial.println(F("\n**************************************"));
166-
Serial.println(request->responseText());
167-
Serial.println(F("**************************************"));
168-
169-
request->setDebug(false);
161+
AHTTP_LOGDEBUG(F("\n**************************************"));
162+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
163+
164+
if (request->responseHTTPcode() == 200)
165+
{
166+
Serial.println(F("\n**************************************"));
167+
Serial.println(request->responseText());
168+
Serial.println(F("**************************************"));
169+
}
170170
}
171171
}
172172

@@ -211,8 +211,8 @@ void setup()
211211

212212
delay(200);
213213

214-
Serial.print(F("\nStarting AsyncHTTPRequest_ESP8266_Ethernet on ")); Serial.print(ARDUINO_BOARD);
215-
Serial.print(F(" using ")); Serial.println(SHIELD_TYPE);
214+
Serial.print("\nStart AsyncHTTPRequest_ESP8266_Ethernet on "); Serial.print(ARDUINO_BOARD);
215+
Serial.print(" using "); Serial.println(SHIELD_TYPE);
216216
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
217217

218218
initEthernet();

0 commit comments

Comments
 (0)