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

Commit

Permalink
v1.9.0 to fix bug and clean-up
Browse files Browse the repository at this point in the history
### Release v1.9.0

1. Fix bug. 
2. Clean up
  • Loading branch information
khoih-prog authored Oct 21, 2022
1 parent f581a35 commit 44abb8b
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 324 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

* [Table of contents](#table-of-contents)
* [Changelog](#changelog)
* [Releases v1.9.0](#releases-v190)
* [Releases v1.8.1](#releases-v181)
* [Releases v1.8.0](#releases-v180)
* [Releases v1.7.1](#releases-v171)
Expand All @@ -22,6 +23,11 @@

## Changelog

### Release v1.9.0

1. Fix bug.
2. Clean up

### Releases v1.8.1

1. Not try to reconnect to the same host:port after connected. Check [setReuse feature #12](https://github.com/khoih-prog/AsyncHTTPSRequest_Generic/issues/12)
Expand Down
4 changes: 2 additions & 2 deletions examples/AsyncCustomHeader/AsyncCustomHeader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
//char GET_ServerAddress[] = "192.168.2.110/";
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
4 changes: 2 additions & 2 deletions examples/AsyncDweetGet/AsyncDweetGet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const char GET_ServerAddress[] = "dweet.io";
// use your own thing name here
String dweetName = "/dweet/for/currentSecond?second=";

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
4 changes: 2 additions & 2 deletions examples/AsyncDweetPost/AsyncDweetPost.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const char POST_ServerAddress[] = "dweet.io";
// use your own thing name here
String dweetName = "/dweet/for/pinA0-Read?";

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
4 changes: 2 additions & 2 deletions examples/AsyncHTTPRequest/AsyncHTTPRequest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

#include "defines.h"

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
4 changes: 2 additions & 2 deletions examples/AsyncSimpleGET/AsyncSimpleGET.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
//char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/";
char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt";

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
4 changes: 2 additions & 2 deletions examples/multiFileProject/multiFileProject.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#error Only Teensy 4.1 supported
#endif

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.8.1"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1008001
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN_TARGET "AsyncHTTPRequest_Teensy41 v1.9.0"
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MIN 1009000

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"AsyncHTTPRequest_Teensy41",
"version": "1.8.1",
"version": "1.9.0",
"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.",
"keywords":"communication, async, tcp, http, async-tcp, async-http, teensy, teensy41, teensy-41, qnethernet, lwip",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AsyncHTTPRequest_Teensy41
version=1.8.1
version=1.9.0
author=Bob Lemaire, Khoi Hoang <[email protected]>
maintainer=Khoi Hoang <[email protected]>
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.
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncHTTPRequest_Teensy41.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
Version: 1.8.1
Version: 1.9.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
*****************************************************************************************************************************/

#pragma once
Expand Down
151 changes: 93 additions & 58 deletions src/AsyncHTTPRequest_Teensy41.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,40 @@
You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
Version: 1.8.1
Version: 1.9.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.7.1 K Hoang 18/03/2022 Initial coding for Teensy 4.1 using built-in QNEthernet.
Bump up version to v1.7.1 to sync with AsyncHTTPRequest_Generic v1.7.1
1.8.0 K Hoang 01/09/2022 Fix bug. Improve debug messages. Optimize code
1.8.1 K Hoang 18/10/2022 Not try to reconnect to the same host:port after connected
1.9.0 K Hoang 21/10/2022 Fix bug. Clean up
*****************************************************************************************************************************/

#pragma once

#ifndef ASYNC_HTTP_REQUEST_TEENSY41_HPP
#define ASYNC_HTTP_REQUEST_TEENSY41_HPP

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION "AsyncHTTPRequest_Teensy41 v1.8.1"
////////////////////////////////////////

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION "AsyncHTTPRequest_Teensy41 v1.9.0"

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MAJOR 1
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MINOR 8
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_PATCH 1
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_MINOR 9
#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_PATCH 0

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_INT 1009000

#define ASYNC_HTTP_REQUEST_TEENSY41_VERSION_INT 1008001
////////////////////////////////////////

#include <Arduino.h>

#include "AsyncHTTPRequest_Teensy41_Debug.h"

////////////////////////////////////////

#ifndef DEBUG_IOTA_PORT
#define DEBUG_IOTA_PORT Serial
#endif
Expand All @@ -57,30 +64,41 @@
#define DEBUG_IOTA_HTTP_SET false
#endif

////////////////////////////////////////

// KH add
#define SAFE_DELETE(object) if (object) { delete object;}
#define SAFE_DELETE_ARRAY(object) if (object) { delete[] object;}

#define ASYNC_HTTP_PREFIX "HTTP://"
#define ASYNC_HTTP_PORT 80

#define ASYNC_HTTPS_PREFIX "HTTPS://"
#define ASYNC_HTTPS_PORT 443

////////////////////////////////////////

#include "Teensy41_AsyncTCP.hpp"

#define MUTEX_LOCK_NR
#define MUTEX_LOCK(returnVal)
#define _AHTTP_lock
#define _AHTTP_unlock


////////////////////////////////////////

#include <pgmspace.h>

// Merge xbuf
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////

struct xseg
{
xseg *next;
uint8_t data[];
};

////////////////////////////////////////

class xbuf: public Print
{
public:
Expand Down Expand Up @@ -129,8 +147,7 @@ class xbuf: public Print

String peekString(int);

/* In addition to the above functions,
the following inherited functions from the Print class are available.
/* In addition to the above functions, the following inherited functions from the Print class are available.
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
size_t print(const String &);
Expand Down Expand Up @@ -171,14 +188,16 @@ class xbuf: public Print

};

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////

#define DEBUG_HTTP(format,...) if(_debug){\
DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\
DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);}

#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout

////////////////////////////////////////

#define HTTPCODE_CONNECTION_REFUSED (-1)
#define HTTPCODE_SEND_HEADER_FAILED (-2)
#define HTTPCODE_SEND_PAYLOAD_FAILED (-3)
Expand All @@ -191,6 +210,8 @@ class xbuf: public Print
#define HTTPCODE_STREAM_WRITE (-10)
#define HTTPCODE_TIMEOUT (-11)

////////////////////////////////////////

typedef enum
{
readyStateUnsent = 0, // Client created, open not yet called
Expand All @@ -199,62 +220,65 @@ typedef enum
readyStateLoading = 3, // receiving, partial data available
readyStateDone = 4 // Request complete, all data available.
} reqStates;


////////////////////////////////////////

class AsyncHTTPRequest
{
struct header
struct header
{
header* next;
char* name;
char* value;

header(): next(nullptr), name(nullptr), value(nullptr)
{};

~header()
{
header* next;
char* name;
char* value;

header(): next(nullptr), name(nullptr), value(nullptr)
{};
SAFE_DELETE_ARRAY(name)
SAFE_DELETE_ARRAY(value)
SAFE_DELETE(next)
}
};

struct URL
{
char *buffer;
char *scheme;
char *host;
int port;
char *path;
char *query;

URL(): buffer(nullptr), scheme(nullptr), host(nullptr),
port(80), path(nullptr), query(nullptr)
{};

~header()
{
SAFE_DELETE_ARRAY(name)
SAFE_DELETE_ARRAY(value)
SAFE_DELETE(next)
//delete[] name;
//delete[] value;
//delete next;
}
};

struct URL
~URL()
{
char *buffer;
char *scheme;
char *host;
int port;
char *path;
char *query;

URL(): buffer(nullptr), scheme(nullptr), host(nullptr),
port(80), path(nullptr), query(nullptr)
{};

~URL()
{
SAFE_DELETE_ARRAY(buffer)
SAFE_DELETE_ARRAY(scheme)
SAFE_DELETE_ARRAY(host)
SAFE_DELETE_ARRAY(path)
SAFE_DELETE_ARRAY(query)
}
};

typedef std::function<void(void*, AsyncHTTPRequest*, int readyState)> readyStateChangeCB;
typedef std::function<void(void*, AsyncHTTPRequest*, size_t available)> onDataCB;
SAFE_DELETE_ARRAY(buffer)
SAFE_DELETE_ARRAY(scheme)
SAFE_DELETE_ARRAY(host)
SAFE_DELETE_ARRAY(path)
SAFE_DELETE_ARRAY(query)
}
};

typedef std::function<void(void*, AsyncHTTPRequest*, int readyState)> readyStateChangeCB;
typedef std::function<void(void*, AsyncHTTPRequest*, size_t available)> onDataCB;

////////////////////////////////////////

public:
AsyncHTTPRequest();
~AsyncHTTPRequest();


//External functions in typical order of use:
//__________________________________________________________________________________________________________*/

////////////////////////////////////////

void setDebug(bool); // Turn debug message on/off
bool debug(); // is debug on or off?

Expand Down Expand Up @@ -296,13 +320,23 @@ class AsyncHTTPRequest
size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer
uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms)
String version(); // Version of AsyncHTTPRequest
//___________________________________________________________________________________________________________________________________

////////////////////////////////////////

private:

bool _requestReadyToSend;

typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
typedef enum
{
HTTPmethodGET,
HTTPmethodPOST,
HTTPmethodPUT,
HTTPmethodPATCH,
HTTPmethodDELETE,
HTTPmethodHEAD,
HTTPmethodMAX
} HTTPmethod;

HTTPmethod _HTTPmethod;

Expand Down Expand Up @@ -348,7 +382,6 @@ class AsyncHTTPRequest
size_t _send();
void _setReadyState(reqStates);


// callbacks

void _onConnect(AsyncClient*);
Expand All @@ -359,4 +392,6 @@ class AsyncHTTPRequest
bool _collectHeaders();
};

////////////////////////////////////////

#endif // ASYNC_HTTP_REQUEST_TEENSY41_HPP
Loading

0 comments on commit 44abb8b

Please sign in to comment.