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

Commit e860ca6

Browse files
authored
v1.2.1 to fix bug of wrong reqStates
### Release v1.9.1 1. Fix bug of wrong `reqStates`. Check [Release 1.9 breakes previously running code #39](khoih-prog/AsyncHTTPRequest_Generic#39) and [Callback behaviour is buggy (ESP8266) #43](khoih-prog/AsyncHTTPRequest_Generic#43) 2. Optional larger `DEFAULT_RX_TIMEOUT` from default 3s, for slower networks
1 parent 711a420 commit e860ca6

File tree

13 files changed

+73
-65
lines changed

13 files changed

+73
-65
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
* [Table of contents](#table-of-contents)
1515
* [Changelog](#changelog)
16+
* [Releases v1.9.1](#releases-v191)
1617
* [Releases v1.9.0](#releases-v190)
1718
* [Releases v1.8.1](#releases-v181)
1819
* [Releases v1.8.0](#releases-v180)
@@ -23,6 +24,11 @@
2324

2425
## Changelog
2526

27+
### Release v1.9.1
28+
29+
1. Fix bug of wrong `reqStates`. Check [Release 1.9 breakes previously running code #39](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/39) and [Callback behaviour is buggy (ESP8266) #43](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/43)
30+
2. Optional larger `DEFAULT_RX_TIMEOUT` from default 3s, for slower networks
31+
2632
### Release v1.9.0
2733

2834
1. Fix bug.

examples/AsyncCustomHeader/AsyncCustomHeader.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
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.9.0"
23-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
22+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
23+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
2424

2525
// Level from 0-4
2626
#define ASYNC_HTTP_DEBUG_PORT Serial

examples/AsyncDweetGet/AsyncDweetGet.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ 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.9.0"
34-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
33+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
34+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
3535

3636
// Level from 0-4
3737
#define ASYNC_HTTP_DEBUG_PORT Serial

examples/AsyncDweetPost/AsyncDweetPost.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ 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.9.0"
28-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
27+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
28+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
2929

3030
// Level from 0-4
3131
#define ASYNC_HTTP_DEBUG_PORT Serial

examples/AsyncHTTPRequest/AsyncHTTPRequest.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
#include "defines.h"
3939

40-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
41-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
40+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
41+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
4242

4343
// Level from 0-4
4444
#define ASYNC_HTTP_DEBUG_PORT Serial

examples/AsyncSimpleGET/AsyncSimpleGET.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
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.9.0"
23-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
22+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
23+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
2424

2525
// Level from 0-4
2626
#define ASYNC_HTTP_DEBUG_PORT Serial

examples/multiFileProject/multiFileProject.ino

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

24-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
25-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000
24+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.1"
25+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009001
2626

2727
// Level from 0-4
2828
#define ASYNC_HTTP_DEBUG_PORT Serial

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"AsyncHTTPRequest_Teensy41",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of Teensy41_AsyncTCP for Teensy 4.1 using QNEthernet. This library is one of the current or future Async libraries to support Teensy 4.1 using QNEthernet, such as AsyncHTTPRequest_Generic, AsyncHTTPSRequest_Generic, AsyncMQTT_Generic, Teensy41_AsyncWebServer, Teensy41_AsyncUDP, Teensy41_AsyncDNSServer, AsyncHTTPRequest_Teensy41_SSL, etc.",
55
"keywords":"communication, async, tcp, http, async-tcp, async-http, teensy, teensy41, teensy-41, qnethernet, lwip",
66
"authors": [

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AsyncHTTPRequest_Teensy41
2-
version=1.9.0
2+
version=1.9.1
33
author=Bob Lemaire, Khoi Hoang <[email protected]>
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of Teensy41_AsyncTCP for Teensy 4.1 using QNEthernet.

src/AsyncHTTPRequest_Teensy41.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
You should have received a copy of the GNU General Public License along with this program.
2121
If not, see <https://www.gnu.org/licenses/>.
2222
23-
Version: 1.9.0
23+
Version: 1.9.1
2424
2525
Version Modified By Date Comments
2626
------- ----------- ---------- -----------
2727
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
2828
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
2929
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
3030
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
31-
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
31+
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
32+
1.9.1 K Hoang 22/10/2022 Fix bug of wrong reqStates
3233
*****************************************************************************************************************************/
3334

3435
#pragma once

src/AsyncHTTPRequest_Teensy41.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
You should have received a copy of the GNU General Public License along with this program.
2121
If not, see <https://www.gnu.org/licenses/>.
2222
23-
Version: 1.9.0
23+
Version: 1.9.1
2424
2525
Version Modified By Date Comments
2626
------- ----------- ---------- -----------
2727
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
2828
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
2929
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
3030
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
31-
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
31+
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
32+
1.9.1 K Hoang 22/10/2022 Fix bug of wrong reqStates
3233
*****************************************************************************************************************************/
3334

3435
#pragma once
@@ -38,13 +39,13 @@
3839

3940
////////////////////////////////////////
4041

41-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION "AsyncHTTPRequest_Teensy41 v1.9.0"
42+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION "AsyncHTTPRequest_Teensy41 v1.9.1"
4243

4344
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MAJOR 1
4445
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MINOR 9
45-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_PATCH 0
46+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_PATCH 1
4647

47-
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_INT 1009000
48+
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_INT 1009001
4849

4950
////////////////////////////////////////
5051

@@ -194,7 +195,9 @@ class xbuf: public Print
194195
DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\
195196
DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);}
196197

197-
#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout
198+
#if !defined(DEFAULT_RX_TIMEOUT)
199+
#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout
200+
#endif
198201

199202
////////////////////////////////////////
200203

@@ -284,7 +287,6 @@ class AsyncHTTPRequest
284287

285288
bool open(const char* /*GET/POST*/, const char* URL); // Initiate a request
286289
void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change
287-
// or you can simply poll readyState()
288290
void setTimeout(int); // overide default timeout (seconds)
289291

290292
void setReqHeader(const char* name, const char* value); // add a request header
@@ -318,7 +320,7 @@ class AsyncHTTPRequest
318320
char* responseLongText(); // response long (whole* or partial* as string)
319321

320322
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
321-
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
323+
uint32_t elapsedTime(); // Elapsed time of transaction or last completed (ms)
322324
String version(); // Version of AsyncHTTPRequest
323325

324326
////////////////////////////////////////

src/AsyncHTTPRequest_Teensy41_Debug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
You should have received a copy of the GNU General Public License along with this program.
2121
If not, see <https://www.gnu.org/licenses/>.
2222
23-
Version: 1.9.0
23+
Version: 1.9.1
2424
2525
Version Modified By Date Comments
2626
------- ----------- ---------- -----------
2727
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
2828
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
2929
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
3030
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
31-
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
31+
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
32+
1.9.1 K Hoang 22/10/2022 Fix bug of wrong reqStates
3233
*****************************************************************************************************************************/
3334

3435
#pragma once

src/AsyncHTTPRequest_Teensy41_Impl.h

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
You should have received a copy of the GNU General Public License along with this program.
2121
If not, see <https://www.gnu.org/licenses/>.
2222
23-
Version: 1.9.0
23+
Version: 1.9.1
2424
2525
Version Modified By Date Comments
2626
------- ----------- ---------- -----------
2727
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
2828
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
2929
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
3030
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
31-
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
31+
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
32+
1.9.1 K Hoang 22/10/2022 Fix bug of wrong reqStates
3233
*****************************************************************************************************************************/
3334

3435
#pragma once
@@ -158,6 +159,7 @@ size_t xbuf::read(uint8_t* buf, const size_t len)
158159
size_t supply = (_offset + _used) > _segSize ? _segSize - _offset : _used;
159160
size_t demand = len - read;
160161
size_t chunk = supply < demand ? supply : demand;
162+
161163
memcpy(buf + read, _head->data + _offset, chunk);
162164
_offset += chunk;
163165
_used -= chunk;
@@ -455,7 +457,6 @@ AsyncHTTPRequest::~AsyncHTTPRequest()
455457
if (_client)
456458
_client->close(true);
457459

458-
459460
SAFE_DELETE(_URL)
460461
SAFE_DELETE(_headers)
461462
SAFE_DELETE(_request)
@@ -790,35 +791,35 @@ int AsyncHTTPRequest::responseHTTPcode()
790791

791792
String AsyncHTTPRequest::responseHTTPString()
792793
{
793-
switch(_HTTPcode)
794-
{
795-
case 0:
796-
return F("OK");
797-
case HTTPCODE_CONNECTION_REFUSED:
798-
return F("CONNECTION_REFUSED");
799-
case HTTPCODE_SEND_HEADER_FAILED:
800-
return F("SEND_HEADER_FAILED");
801-
case HTTPCODE_SEND_PAYLOAD_FAILED:
802-
return F("SEND_PAYLOAD_FAILED");
803-
case HTTPCODE_NOT_CONNECTED:
804-
return F("NOT_CONNECTED");
805-
case HTTPCODE_CONNECTION_LOST:
806-
return F("CONNECTION_LOST");
807-
case HTTPCODE_NO_STREAM:
808-
return F("NO_STREAM");
809-
case HTTPCODE_NO_HTTP_SERVER:
810-
return F("NO_HTTP_SERVER");
811-
case HTTPCODE_TOO_LESS_RAM:
812-
return F("TOO_LESS_RAM");
813-
case HTTPCODE_ENCODING:
814-
return F("ENCODING");
815-
case HTTPCODE_STREAM_WRITE:
816-
return F("STREAM_WRITE");
817-
case HTTPCODE_TIMEOUT:
818-
return F("TIMEOUT");
819-
820-
// HTTP positive code
821-
case 100: return F("Continue");
794+
switch(_HTTPcode)
795+
{
796+
case 0:
797+
return F("OK");
798+
case HTTPCODE_CONNECTION_REFUSED:
799+
return F("CONNECTION_REFUSED");
800+
case HTTPCODE_SEND_HEADER_FAILED:
801+
return F("SEND_HEADER_FAILED");
802+
case HTTPCODE_SEND_PAYLOAD_FAILED:
803+
return F("SEND_PAYLOAD_FAILED");
804+
case HTTPCODE_NOT_CONNECTED:
805+
return F("NOT_CONNECTED");
806+
case HTTPCODE_CONNECTION_LOST:
807+
return F("CONNECTION_LOST");
808+
case HTTPCODE_NO_STREAM:
809+
return F("NO_STREAM");
810+
case HTTPCODE_NO_HTTP_SERVER:
811+
return F("NO_HTTP_SERVER");
812+
case HTTPCODE_TOO_LESS_RAM:
813+
return F("TOO_LESS_RAM");
814+
case HTTPCODE_ENCODING:
815+
return F("ENCODING");
816+
case HTTPCODE_STREAM_WRITE:
817+
return F("STREAM_WRITE");
818+
case HTTPCODE_TIMEOUT:
819+
return F("TIMEOUT");
820+
821+
// HTTP positive code
822+
case 100: return F("Continue");
822823
case 101: return F("Switching Protocols");
823824
case 200: return F("HTTP OK");
824825
case 201: return F("Created");
@@ -858,8 +859,8 @@ String AsyncHTTPRequest::responseHTTPString()
858859
case 503: return F("Service Unavailable");
859860
case 504: return F("Gateway Time-out");
860861
case 505: return F("HTTP Version not supported");
861-
default: return "UNKNOWN";
862-
}
862+
default: return "UNKNOWN";
863+
}
863864
}
864865

865866
////////////////////////////////////////
@@ -1224,12 +1225,9 @@ size_t AsyncHTTPRequest::_send()
12241225
return 0;
12251226

12261227
if ( ! _client->connected())
1227-
{
1228+
{
12281229
// KH fix bug https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/38
1229-
_HTTPcode = HTTPCODE_NOT_CONNECTED;
1230-
_setReadyState(readyStateDone);
1231-
1232-
///////////////////////////
1230+
_timeout = DEFAULT_RX_TIMEOUT;
12331231

12341232
return 0;
12351233
}

0 commit comments

Comments
 (0)