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

Commit 73cdc77

Browse files
authored
v1.2.2 default to reconnect to the same host:port
### Release v1.2.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](khoih-prog/AsyncHTTPRequest_Generic#44) 2. Fix bug 3. Use `allman astyle` and add `utils`
1 parent 284af5d commit 73cdc77

25 files changed

+1163
-885
lines changed

CONTRIBUTING.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `RP2040` Core Version (e.g. RP2040 core v2.6.1)
18+
* `RP2040` Core Version (e.g. RP2040 core v2.6.3)
1919
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO_W)
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
@@ -28,28 +28,50 @@ Please ensure to specify the following:
2828

2929
```
3030
Arduino IDE version: 1.8.19
31-
RP2040 core v2.6.1
31+
RP2040 core v2.6.3
3232
RASPBERRY_PI_PICO_W Module
3333
OS: Ubuntu 20.04 LTS
34-
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
34+
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
3535
3636
Context:
37-
I encountered a crash when using this library
38-
37+
I encountered a crash while using this library
3938
Steps to reproduce:
4039
1. ...
4140
2. ...
4241
3. ...
4342
4. ...
4443
```
4544

45+
### Additional context
46+
47+
Add any other context about the problem here.
48+
49+
---
50+
4651
### Sending Feature Requests
4752

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

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

57+
---
58+
5259
### Sending Pull Requests
5360

5461
Pull Requests with changes and fixes are also welcome!
5562

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

changelog.md

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

1313
* [Changelog](#changelog)
14+
* [Release v1.2.2](#Release-v122)
1415
* [Release v1.2.1](#Release-v121)
1516
* [Release v1.2.0](#Release-v120)
1617
* [Release v1.1.1](#Release-v111)
@@ -23,6 +24,12 @@
2324

2425
## Changelog
2526

27+
### Release v1.2.2
28+
29+
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/issues/44)
30+
2. Fix bug
31+
3. Use `allman astyle` and add `utils`
32+
2633
### Release v1.2.1
2734

2835
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)
+108-99
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
/****************************************************************************************************************************
22
AsyncCustomHeader.ino
3-
3+
44
For RP2040W with CYW43439 WiFi
5-
5+
66
AsyncHTTPRequest_RP2040W is a library for the RP2040W with CYW43439 WiFi
7-
7+
88
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
99
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
10-
10+
1111
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
12-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
12+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
1313
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
1414
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*****************************************************************************************************************************/
1818

1919
#include "defines.h"
2020

21-
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN_TARGET "AsyncHTTPRequest_RP2040W v1.2.1"
22-
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN 1002001
21+
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN_TARGET "AsyncHTTPRequest_RP2040W v1.2.2"
22+
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN 1002002
23+
24+
// Uncomment for certain HTTP site to optimize
25+
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
2326

2427
// Level from 0-4
2528
#define ASYNC_HTTP_DEBUG_PORT Serial
@@ -38,131 +41,137 @@ int status = WL_IDLE_STATUS;
3841

3942
void sendRequest()
4043
{
41-
static bool requestOpenResult;
42-
43-
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
44-
{
45-
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
46-
47-
requestOpenResult = request.open("GET", GET_ServerAddress);
48-
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
49-
if (requestOpenResult)
50-
{
51-
// Only send() if open() returns true, or crash
52-
request.send();
53-
}
54-
else
55-
{
56-
Serial.println("Can't send bad request");
57-
}
58-
}
59-
else
60-
{
61-
Serial.println("Can't send request");
62-
}
44+
static bool requestOpenResult;
45+
46+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
47+
{
48+
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
49+
50+
requestOpenResult = request.open("GET", GET_ServerAddress);
51+
52+
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
53+
if (requestOpenResult)
54+
{
55+
// Only send() if open() returns true, or crash
56+
request.send();
57+
}
58+
else
59+
{
60+
Serial.println("Can't send bad request");
61+
}
62+
}
63+
else
64+
{
65+
Serial.println("Can't send request");
66+
}
6367
}
6468

6569
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
6670
{
67-
(void) optParm;
68-
69-
if (readyState == readyStateDone)
70-
{
71-
AHTTP_LOGWARN(F("\n**************************************"));
72-
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
73-
74-
if (request->responseHTTPcode() == 200)
75-
{
76-
Serial.println(F("\n**************************************"));
77-
Serial.println(request->responseText());
78-
Serial.println(F("**************************************"));
79-
}
80-
}
71+
(void) optParm;
72+
73+
if (readyState == readyStateDone)
74+
{
75+
AHTTP_LOGWARN(F("\n**************************************"));
76+
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
77+
78+
if (request->responseHTTPcode() == 200)
79+
{
80+
Serial.println(F("\n**************************************"));
81+
Serial.println(request->responseText());
82+
Serial.println(F("**************************************"));
83+
}
84+
}
8185
}
8286

8387
void printWifiStatus()
8488
{
85-
// print the SSID of the network you're attached to:
86-
Serial.print("SSID: ");
87-
Serial.println(WiFi.SSID());
88-
89-
// print your board's IP address:
90-
IPAddress ip = WiFi.localIP();
91-
Serial.print("Local IP Address: ");
92-
Serial.println(ip);
89+
// print the SSID of the network you're attached to:
90+
Serial.print("SSID: ");
91+
Serial.println(WiFi.SSID());
92+
93+
// print your board's IP address:
94+
IPAddress ip = WiFi.localIP();
95+
Serial.print("Local IP Address: ");
96+
Serial.println(ip);
9397
}
9498

9599
void setup()
96100
{
97-
Serial.begin(115200);
98-
while (!Serial && millis() < 5000);
101+
Serial.begin(115200);
102+
103+
while (!Serial && millis() < 5000);
99104

100-
Serial.print("\nStart AsyncCustomHeader on "); Serial.println(BOARD_NAME);
101-
Serial.println(ASYNCTCP_RP2040W_VERSION);
102-
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION);
105+
Serial.print("\nStart AsyncCustomHeader on ");
106+
Serial.println(BOARD_NAME);
107+
Serial.println(ASYNCTCP_RP2040W_VERSION);
108+
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION);
103109

104110
#if defined(ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
105-
if (ASYNC_HTTP_REQUEST_RP2040W_VERSION_INT < ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
106-
{
107-
Serial.print("Warning. Must use this example on Version equal or later than : ");
108-
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN);
109-
}
111+
112+
if (ASYNC_HTTP_REQUEST_RP2040W_VERSION_INT < ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
113+
{
114+
Serial.print("Warning. Must use this example on Version equal or later than : ");
115+
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN);
116+
}
117+
110118
#endif
111119

112-
///////////////////////////////////
113-
114-
// check for the WiFi module:
115-
if (WiFi.status() == WL_NO_MODULE)
116-
{
117-
Serial.println("Communication with WiFi module failed!");
118-
// don't continue
119-
while (true);
120-
}
120+
///////////////////////////////////
121+
122+
// check for the WiFi module:
123+
if (WiFi.status() == WL_NO_MODULE)
124+
{
125+
Serial.println("Communication with WiFi module failed!");
126+
127+
// don't continue
128+
while (true);
129+
}
121130

122-
Serial.print(F("Connecting to SSID: "));
123-
Serial.println(ssid);
131+
Serial.print(F("Connecting to SSID: "));
132+
Serial.println(ssid);
124133

125-
status = WiFi.begin(ssid, pass);
134+
status = WiFi.begin(ssid, pass);
126135

127-
delay(1000);
128-
129-
// attempt to connect to WiFi network
130-
while ( status != WL_CONNECTED)
131-
{
132-
delay(500);
133-
134-
// Connect to WPA/WPA2 network
135-
status = WiFi.status();
136-
}
136+
delay(1000);
137137

138-
printWifiStatus();
138+
// attempt to connect to WiFi network
139+
while ( status != WL_CONNECTED)
140+
{
141+
delay(500);
139142

140-
///////////////////////////////////
143+
// Connect to WPA/WPA2 network
144+
status = WiFi.status();
145+
}
141146

142-
request.setDebug(false);
147+
printWifiStatus();
143148

144-
// 5s timeout
145-
request.setTimeout(5);
149+
///////////////////////////////////
146150

147-
request.onReadyStateChange(requestCB);
151+
request.setDebug(false);
152+
153+
// 5s timeout
154+
request.setTimeout(5);
155+
156+
request.onReadyStateChange(requestCB);
148157
}
149158

150159
void sendRequestRepeat()
151160
{
152-
static unsigned long sendRequest_timeout = 0;
161+
static unsigned long sendRequest_timeout = 0;
153162

154163
#define SEND_REQUEST_INTERVAL 60000L
155164

156-
// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
157-
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
158-
{
159-
sendRequest();
160-
161-
sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
162-
}
165+
// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
166+
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
167+
{
168+
sendRequest();
169+
170+
sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
171+
}
163172
}
164173

165174
void loop()
166175
{
167-
sendRequestRepeat();
176+
sendRequestRepeat();
168177
}

examples/AsyncCustomHeader/defines.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/****************************************************************************************************************************
22
defines.h
3-
3+
44
For RP2040W with CYW43439 WiFi
5-
5+
66
AsyncHTTPRequest_RP2040W is a library for the RP2040W with CYW43439 WiFi
7-
7+
88
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
99
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
10-
10+
1111
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
12-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
12+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
1313
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
1414
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*****************************************************************************************************************************/
1818

1919

2020
#ifndef defines_h
2121
#define defines_h
2222

2323
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
24-
#error For RASPBERRY_PI_PICO_W only
24+
#error For RASPBERRY_PI_PICO_W only
2525
#endif
2626

2727
char ssid[] = "your_ssid"; // your network SSID (name)

0 commit comments

Comments
 (0)