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

Commit 639ce91

Browse files
authored
v1.10.2 default to reconnect to the same host:port
### Releases v1.10.2 1. Default to reconnect to the same `host:port` after connected for new HTTP sites. Check [Host/Headers not always sent with 1.10.1 #44](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues44) 2. Update `Packages' Patches`
1 parent 89acc33 commit 639ce91

33 files changed

+2884
-2548
lines changed

CONTRIBUTING.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,49 @@ Please ensure to specify the following:
2929
Arduino IDE version: 1.8.19
3030
ESP32 Core Version 2.0.5
3131
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.15.0-50-generic #56~20.04.1-Ubuntu SMP Tue Sep 27 15:51:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
35-
I encountered a crash when using this library
36-
35+
I encountered a crash while using this library
3736
Steps to reproduce:
3837
1. ...
3938
2. ...
4039
3. ...
4140
4. ...
4241
```
4342

43+
### Additional context
44+
45+
Add any other context about the problem here.
46+
47+
---
48+
4449
### Sending Feature Requests
4550

4651
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4752

4853
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
4954

55+
---
56+
5057
### Sending Pull Requests
5158

5259
Pull Requests with changes and fixes are also welcome!
5360

61+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
62+
63+
1. Change directory to the library GitHub
64+
65+
```
66+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncHTTPRequest_Generic_GitHub/
67+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPRequest_Generic_GitHub$
68+
```
69+
70+
2. Issue astyle command
71+
72+
```
73+
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPRequest_Generic_GitHub$ bash utils/restyle.sh
74+
```
75+
76+
77+

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.10.2](#releases-v1102)
1516
* [Releases v1.10.1](#releases-v1101)
1617
* [Releases v1.10.0](#releases-v1100)
1718
* [Releases v1.9.2](#releases-v192)
@@ -44,6 +45,11 @@
4445

4546
## Changelog
4647

48+
### Releases v1.10.2
49+
50+
1. Default to reconnect to the same `host:port` after connected for new HTTP sites. Check [Host/Headers not always sent with 1.10.1 #44](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues44)
51+
2. Update `Packages' Patches`
52+
4753
### Releases v1.10.1
4854

4955
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)
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/****************************************************************************************************************************
22
AsyncCustomHeader_STM32.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
3-
3+
44
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
5-
5+
66
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
7-
7+
88
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
9-
9+
1010
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
1111
Licensed under MIT license
12-
12+
1313
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
14-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
14+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
1515
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
1616
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1717
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*****************************************************************************************************************************/
2020

2121
#include "defines.h"
@@ -24,12 +24,15 @@
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.10.1"
28-
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
27+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
28+
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
2929

3030
// 600s = 10 minutes to not flooding, 60s in testing
3131
#define HTTP_REQUEST_INTERVAL_MS 60000 //600000
3232

33+
// Uncomment for certain HTTP site to optimize
34+
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
35+
3336
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
3437
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
3538

@@ -44,97 +47,102 @@ Ticker sendHTTPRequest(sendRequest, HTTP_REQUEST_INTERVAL_MS, 0, MILLIS);
4447

4548
void sendRequest(void)
4649
{
47-
static bool requestOpenResult;
48-
49-
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
50-
{
51-
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
52-
53-
requestOpenResult = request.open("GET", GET_ServerAddress);
54-
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
55-
if (requestOpenResult)
56-
{
57-
// Only send() if open() returns true, or crash
58-
request.send();
59-
}
60-
else
61-
{
62-
Serial.println("Can't send bad request");
63-
}
64-
}
65-
else
66-
{
67-
Serial.println("Can't send request");
68-
}
50+
static bool requestOpenResult;
51+
52+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
53+
{
54+
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
55+
56+
requestOpenResult = request.open("GET", GET_ServerAddress);
57+
58+
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
59+
if (requestOpenResult)
60+
{
61+
// Only send() if open() returns true, or crash
62+
request.send();
63+
}
64+
else
65+
{
66+
Serial.println("Can't send bad request");
67+
}
68+
}
69+
else
70+
{
71+
Serial.println("Can't send request");
72+
}
6973
}
7074

7175
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
7276
{
73-
(void) optParm;
74-
75-
if (readyState == readyStateDone)
76-
{
77-
Serial.println();
78-
AHTTP_LOGDEBUG(F("**************************************"));
79-
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
80-
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-
}
91-
}
77+
(void) optParm;
78+
79+
if (readyState == readyStateDone)
80+
{
81+
Serial.println();
82+
AHTTP_LOGDEBUG(F("**************************************"));
83+
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
84+
85+
if (request->responseHTTPcode() == 200)
86+
{
87+
Serial.println(F("**************************************"));
88+
Serial.println(request->responseText());
89+
Serial.println(F("**************************************"));
90+
}
91+
else
92+
{
93+
AHTTP_LOGERROR(F("Response error"));
94+
}
95+
}
9296
}
9397

9498
void setup(void)
9599
{
96-
Serial.begin(115200);
97-
while (!Serial && millis() < 5000);
100+
Serial.begin(115200);
101+
102+
while (!Serial && millis() < 5000);
98103

99-
Serial.print("\nStart AsyncCustomHeader_STM32 on "); Serial.println(BOARD_NAME);
100-
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
104+
Serial.print("\nStart AsyncCustomHeader_STM32 on ");
105+
Serial.println(BOARD_NAME);
106+
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
101107

102108
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
103-
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
104-
{
105-
Serial.print("Warning. Must use this example on Version equal or later than : ");
106-
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
107-
}
109+
110+
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
111+
{
112+
Serial.print("Warning. Must use this example on Version equal or later than : ");
113+
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
114+
}
115+
108116
#endif
109117

110-
// start the ethernet connection and the server
111-
// Use random mac
112-
uint16_t index = millis() % NUMBER_OF_MAC;
118+
// start the ethernet connection and the server
119+
// Use random mac
120+
uint16_t index = millis() % NUMBER_OF_MAC;
113121

114-
// Use Static IP
115-
//Ethernet.begin(mac[index], ip);
116-
// Use DHCP dynamic IP and random mac
117-
Ethernet.begin(mac[index]);
122+
// Use Static IP
123+
//Ethernet.begin(mac[index], ip);
124+
// Use DHCP dynamic IP and random mac
125+
Ethernet.begin(mac[index]);
118126

119-
Serial.print(F("AsyncHTTPRequest @ IP : "));
120-
Serial.println(Ethernet.localIP());
121-
Serial.println();
127+
Serial.print(F("AsyncHTTPRequest @ IP : "));
128+
Serial.println(Ethernet.localIP());
129+
Serial.println();
122130

123-
request.setDebug(false);
131+
request.setDebug(false);
124132

125-
// 5s timeout
126-
request.setTimeout(5);
133+
// 5s timeout
134+
request.setTimeout(5);
127135

128-
request.onReadyStateChange(requestCB);
136+
request.onReadyStateChange(requestCB);
129137

130-
sendHTTPRequest.start(); //start the ticker.
138+
sendHTTPRequest.start(); //start the ticker.
131139

132-
// Send first request now
133-
delay(10000);
134-
sendRequest();
140+
// Send first request now
141+
delay(10000);
142+
sendRequest();
135143
}
136144

137145
void loop(void)
138146
{
139-
sendHTTPRequest.update();
147+
sendHTTPRequest.update();
140148
}

0 commit comments

Comments
 (0)