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

Commit

Permalink
v2.2.1 default to reconnect to the same host:port
Browse files Browse the repository at this point in the history
### Releases v2.2.1

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) and [Getting 400 Bad Request on second call to same host #14](#14)
2. Use `allman astyle` and add `utils`
  • Loading branch information
khoih-prog committed Nov 10, 2022
1 parent ea1b92c commit 6758036
Show file tree
Hide file tree
Showing 17 changed files with 1,764 additions and 1,467 deletions.
29 changes: 26 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,48 @@ Please ensure to specify the following:
Arduino IDE version: 1.8.19
ESP32 Core Version 2.0.5
OS: Ubuntu 20.04 LTS
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
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
Context:
I encountered a crash when using this library
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

### Additional context

Add any other context about the problem here.

---

### Sending Feature Requests

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

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

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncHTTPSRequest_Generic_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPSRequest_Generic_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPSRequest_Generic_GitHub$ bash utils/restyle.sh
```


6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v2.2.1](#releases-v221)
* [Releases v2.2.0](#releases-v220)
* [Releases v2.1.3](#releases-v213)
* [Releases v2.1.2](#releases-v212)
Expand All @@ -32,6 +33,11 @@

## Changelog

### Releases v2.2.1

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) and [Getting 400 Bad Request on second call to same host #14](https://github.com/khoih-prog/AsyncHTTPSRequest_Generic/issues/14)
2. Use `allman astyle` and add `utils`

### Releases v2.2.0

1. Fix crash when turn-on debug or start
Expand Down
188 changes: 99 additions & 89 deletions examples/AsyncHTTPSRequest_ESP/AsyncHTTPSRequest_ESP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@
//*************************************************************************************************************

#if !( defined(ESP8266) || defined(ESP32) )
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#endif

#define ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPSRequest_Generic v2.2.0"
#define ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN 2002000
#define ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPSRequest_Generic v2.2.1"
#define ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN 2002001

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

// Uncomment for certain HTTP site to optimize
//#define NOT_SEND_HEADER_AFTER_CONNECTED true

// Level from 0-4
#define ASYNC_HTTPS_DEBUG_PORT Serial
Expand All @@ -65,9 +70,9 @@ const char* ssid = "your_ssid";
const char* password = "your_pass";

#if (ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WiFi.h>
#elif (ESP32)
#include <WiFi.h>
#include <WiFi.h>
#endif

// Use larger queue size if necessary for large data transfer. Default is 512 bytes if not defined here
Expand All @@ -87,124 +92,129 @@ Ticker ticker1;

void heartBeatPrint()
{
static int num = 1;

if (WiFi.status() == WL_CONNECTED)
Serial.print(F("H")); // H means connected to WiFi
else
Serial.print(F("F")); // F means not connected to WiFi

if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
static int num = 1;

if (WiFi.status() == WL_CONNECTED)
Serial.print(F("H")); // H means connected to WiFi
else
Serial.print(F("F")); // F means not connected to WiFi

if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}

void sendRequest()
{
static bool requestOpenResult;

if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
//requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/Europe/London.txt");
//requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/America/Toronto.txt");
requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/America/Toronto.txt");

if (requestOpenResult)
{
// Only send() if open() returns true, or crash
request.send();
}
else
{
Serial.println(F("Can't send bad request"));
}
}
else
{
Serial.println(F("Can't send request"));
}
static bool requestOpenResult;

if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
//requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/Europe/London.txt");
//requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/America/Toronto.txt");
requestOpenResult = request.open("GET", "https://worldtimeapi.org/api/timezone/America/Toronto.txt");

if (requestOpenResult)
{
// Only send() if open() returns true, or crash
request.send();
}
else
{
Serial.println(F("Can't send bad request"));
}
}
else
{
Serial.println(F("Can't send request"));
}
}

void requestCB(void *optParm, AsyncHTTPSRequest *request, int readyState)
{
(void) optParm;

if (readyState == readyStateDone)
{
AHTTPS_LOGDEBUG0(F("\n**************************************\n"));
AHTTPS_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());

if (request->responseHTTPcode() == 200)
{
Serial.println(F("\n**************************************"));
Serial.println(request->responseText());
Serial.println(F("**************************************"));
}

request->setDebug(false);
}
(void) optParm;

if (readyState == readyStateDone)
{
AHTTPS_LOGDEBUG0(F("\n**************************************\n"));
AHTTPS_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());

if (request->responseHTTPcode() == 200)
{
Serial.println(F("\n**************************************"));
Serial.println(request->responseText());
Serial.println(F("**************************************"));
}

request->setDebug(false);
}
}

void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial && millis() < 5000);
// put your setup code here, to run once:
Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(200);
delay(200);

Serial.print(F("\nStarting AsyncHTTPSRequest_ESP using ")); Serial.println(ARDUINO_BOARD);
Serial.print(F("\nStarting AsyncHTTPSRequest_ESP using "));
Serial.println(ARDUINO_BOARD);

#if defined(ESP32)
Serial.println(ASYNC_TCP_SSL_VERSION);
Serial.println(ASYNC_TCP_SSL_VERSION);
#else
//Serial.println(ESPASYNC_TCP_SSL_VERSION);
//Serial.println(ESPASYNC_TCP_SSL_VERSION);
#endif

Serial.println(ASYNC_HTTPS_REQUEST_GENERIC_VERSION);
Serial.println(ASYNC_HTTPS_REQUEST_GENERIC_VERSION);

#if defined(ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN)
if (ASYNC_HTTPS_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN)
{
Serial.print(F("Warning. Must use this example on Version equal or later than : "));
Serial.println(ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN_TARGET);
}

if (ASYNC_HTTPS_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN)
{
Serial.print(F("Warning. Must use this example on Version equal or later than : "));
Serial.println(ASYNC_HTTPS_REQUEST_GENERIC_VERSION_MIN_TARGET);
}

#endif

WiFi.mode(WIFI_STA);
WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);
WiFi.begin(ssid, password);

Serial.print(F("Connecting to WiFi SSID: ")); Serial.println(ssid);
Serial.print(F("Connecting to WiFi SSID: "));
Serial.println(ssid);

while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}

Serial.print(F("\nAsyncHTTPSRequest @ IP : "));
Serial.println(WiFi.localIP());
Serial.print(F("\nAsyncHTTPSRequest @ IP : "));
Serial.println(WiFi.localIP());

request.setDebug(false);
request.setDebug(false);

request.onReadyStateChange(requestCB);
request.onReadyStateChange(requestCB);

ticker.attach(HTTPS_REQUEST_INTERVAL, sendRequest);
ticker.attach(HTTPS_REQUEST_INTERVAL, sendRequest);

ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);

// Send first request now
sendRequest();
// Send first request now
sendRequest();
}

void loop()
{
//delay(1);
//delay(1);
}

0 comments on commit 6758036

Please sign in to comment.