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

Commit fda81dc

Browse files
authored
v1.4.2 default to reconnect to the same host:port
### Releases v1.4.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. Use `allman astyle` and add `utils`
1 parent 3c56997 commit fda81dc

37 files changed

+2435
-2112
lines changed

CONTRIBUTING.md

+26-3
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,48 @@ Arduino IDE version: 1.8.19
3131
`ArduinoCore-mbed` mbed_portenta core v3.4.1
3232
Portenta_H7 Rev2 ABX00042
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/Portenta_H7_AsyncHTTPRequest/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/Portenta_H7_AsyncHTTPRequest_GitHub/
69+
xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncHTTPRequest_GitHub$
70+
```
71+
72+
2. Issue astyle command
73+
74+
```
75+
xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncHTTPRequest_GitHub$ bash utils/restyle.sh
76+
```
77+
78+

changelog.md

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

1313
* [Changelog](#changelog)
14+
* [Releases v1.4.2](#releases-v142)
1415
* [Releases v1.4.1](#releases-v141)
1516
* [Releases v1.4.0](#releases-v140)
1617
* [Releases v1.3.1](#releases-v131)
@@ -24,6 +25,11 @@
2425

2526
## Changelog
2627

28+
### Releases v1.4.2
29+
30+
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)
31+
2. Use `allman astyle` and add `utils`
32+
2733
### Releases v1.4.1
2834

2935
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,26 +1,29 @@
11
/****************************************************************************************************************************
22
AsyncCustomHeader.ino
3-
3+
44
For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi
5-
5+
66
Portenta_H7_AsyncHTTPRequest is a library for the Portenta_H7 with with Vision-Shield Ethernet Ethernet or Murata WiFi
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/Portenta_H7_AsyncHTTPRequest
11-
11+
1212
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
13-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
13+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
1414
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
1515
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1616
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*****************************************************************************************************************************/
1919

2020
#include "defines.h"
2121

22-
#define PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN_TARGET "Portenta_H7_AsyncHTTPRequest v1.4.1"
23-
#define PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN 1004001
22+
#define PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN_TARGET "Portenta_H7_AsyncHTTPRequest v1.4.2"
23+
#define PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN 1004002
24+
25+
// Uncomment for certain HTTP site to optimize
26+
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
2427

2528
// Select a test server address
2629
//char GET_ServerAddress[] = "192.168.2.110/";
@@ -33,123 +36,128 @@ AsyncHTTPRequest request;
3336

3437
void sendRequest()
3538
{
36-
static bool requestOpenResult;
37-
38-
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
39-
{
40-
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
41-
42-
requestOpenResult = request.open("GET", GET_ServerAddress);
43-
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
44-
if (requestOpenResult)
45-
{
46-
// Only send() if open() returns true, or crash
47-
request.send();
48-
}
49-
else
50-
{
51-
Serial.println("Can't send bad request");
52-
}
53-
}
54-
else
55-
{
56-
Serial.println("Can't send request");
57-
}
39+
static bool requestOpenResult;
40+
41+
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
42+
{
43+
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));
44+
45+
requestOpenResult = request.open("GET", GET_ServerAddress);
46+
47+
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
48+
if (requestOpenResult)
49+
{
50+
// Only send() if open() returns true, or crash
51+
request.send();
52+
}
53+
else
54+
{
55+
Serial.println("Can't send bad request");
56+
}
57+
}
58+
else
59+
{
60+
Serial.println("Can't send request");
61+
}
5862
}
5963

6064
void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState)
6165
{
62-
(void) optParm;
63-
64-
if (readyState == readyStateDone)
65-
{
66-
AHTTP_LOGWARN(F("\n**************************************"));
67-
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
68-
69-
if (request->responseHTTPcode() == 200)
70-
{
71-
Serial.println(F("\n**************************************"));
72-
Serial.println(request->responseText());
73-
Serial.println(F("**************************************"));
74-
}
75-
}
66+
(void) optParm;
67+
68+
if (readyState == readyStateDone)
69+
{
70+
AHTTP_LOGWARN(F("\n**************************************"));
71+
AHTTP_LOGWARN1(F("Response Code = "), request->responseHTTPString());
72+
73+
if (request->responseHTTPcode() == 200)
74+
{
75+
Serial.println(F("\n**************************************"));
76+
Serial.println(request->responseText());
77+
Serial.println(F("**************************************"));
78+
}
79+
}
7680
}
7781

7882
void setup()
7983
{
80-
Serial.begin(115200);
81-
while (!Serial && millis() < 5000);
84+
Serial.begin(115200);
8285

83-
Serial.print("\nStart AsyncCustomHeader on "); Serial.println(BOARD_NAME);
84-
Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION);
85-
Serial.println(PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION);
86+
while (!Serial && millis() < 5000);
87+
88+
Serial.print("\nStart AsyncCustomHeader on ");
89+
Serial.println(BOARD_NAME);
90+
Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION);
91+
Serial.println(PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION);
8692

8793
#if defined(PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN)
88-
if (PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_INT < PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN)
89-
{
90-
Serial.print("Warning. Must use this example on Version equal or later than : ");
91-
Serial.println(PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN_TARGET);
92-
}
94+
95+
if (PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_INT < PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN)
96+
{
97+
Serial.print("Warning. Must use this example on Version equal or later than : ");
98+
Serial.println(PORTENTA_H7_ASYNC_HTTP_REQUEST_VERSION_MIN_TARGET);
99+
}
100+
93101
#endif
94102

95-
///////////////////////////////////
96-
97-
// start the ethernet connection and the server
98-
// Use random mac
99-
uint16_t index = millis() % NUMBER_OF_MAC;
100-
101-
// Use Static IP
102-
//Ethernet.begin(mac[index], ip);
103-
// Use DHCP dynamic IP and random mac
104-
Ethernet.begin(mac[index]);
105-
106-
if (Ethernet.hardwareStatus() == EthernetNoHardware)
107-
{
108-
Serial.println("No Ethernet found. Stay here forever");
109-
110-
while (true)
111-
{
112-
delay(1); // do nothing, no point running without Ethernet hardware
113-
}
114-
}
115-
116-
if (Ethernet.linkStatus() == LinkOFF)
117-
{
118-
Serial.println("Not connected Ethernet cable");
119-
}
120-
121-
Serial.print(F("Using mac index = "));
122-
Serial.println(index);
123-
124-
Serial.print(F("Connected! IP address: "));
125-
Serial.println(Ethernet.localIP());
126-
127-
///////////////////////////////////
128-
129-
request.setDebug(false);
130-
131-
// 5s timeout
132-
request.setTimeout(5);
133-
134-
request.onReadyStateChange(requestCB);
103+
///////////////////////////////////
104+
105+
// start the ethernet connection and the server
106+
// Use random mac
107+
uint16_t index = millis() % NUMBER_OF_MAC;
108+
109+
// Use Static IP
110+
//Ethernet.begin(mac[index], ip);
111+
// Use DHCP dynamic IP and random mac
112+
Ethernet.begin(mac[index]);
113+
114+
if (Ethernet.hardwareStatus() == EthernetNoHardware)
115+
{
116+
Serial.println("No Ethernet found. Stay here forever");
117+
118+
while (true)
119+
{
120+
delay(1); // do nothing, no point running without Ethernet hardware
121+
}
122+
}
123+
124+
if (Ethernet.linkStatus() == LinkOFF)
125+
{
126+
Serial.println("Not connected Ethernet cable");
127+
}
128+
129+
Serial.print(F("Using mac index = "));
130+
Serial.println(index);
131+
132+
Serial.print(F("Connected! IP address: "));
133+
Serial.println(Ethernet.localIP());
134+
135+
///////////////////////////////////
136+
137+
request.setDebug(false);
138+
139+
// 5s timeout
140+
request.setTimeout(5);
141+
142+
request.onReadyStateChange(requestCB);
135143
}
136144

137145
void sendRequestRepeat()
138146
{
139-
static unsigned long sendRequest_timeout = 0;
147+
static unsigned long sendRequest_timeout = 0;
140148

141149
#define SEND_REQUEST_INTERVAL 60000L
142150

143-
// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
144-
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
145-
{
146-
sendRequest();
147-
148-
sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
149-
}
151+
// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
152+
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
153+
{
154+
sendRequest();
155+
156+
sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
157+
}
150158
}
151159

152160
void loop()
153161
{
154-
sendRequestRepeat();
162+
sendRequestRepeat();
155163
}

0 commit comments

Comments
 (0)