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`
This commit is contained in:
Khoi Hoang
2022-11-09 23:46:36 -05:00
committed by GitHub
parent 89acc339e0
commit 639ce917e5
33 changed files with 2779 additions and 2443 deletions
@@ -1,21 +1,21 @@
/****************************************************************************************************************************
AsyncHTTPMultiRequests.ino - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
Licensed under MIT license
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************************************************************************/
//************************************************************************************************************
//
@@ -41,11 +41,11 @@
//*************************************************************************************************************
#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_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.1"
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010001
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.10.2"
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1010002
// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT Serial
@@ -63,13 +63,16 @@ 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
// Seconds for timeout, default is 3s
#define DEFAULT_RX_TIMEOUT 10
#define DEFAULT_RX_TIMEOUT 10
// Uncomment for certain HTTP site to optimize
//#define NOT_SEND_HEADER_AFTER_CONNECTED true
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <AsyncHTTPRequest_Generic.h> // https://github.com/khoih-prog/AsyncHTTPRequest_Generic
@@ -82,22 +85,22 @@ Ticker ticker1;
void heartBeatPrint(void)
{
static int num = 1;
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 (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(" "));
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
// To replace with your real APP_API
@@ -121,106 +124,115 @@ const char* requestAll[ NUM_REQUESTS ] = { requestCurrent.c_str(), requestMinute
uint8_t requestIndex = 0;
void sendRequest()
void sendRequest()
{
static bool requestOpenResult;
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
requestOpenResult = request.open("GET", requestAll[requestIndex] );
static bool requestOpenResult;
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"));
}
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
requestOpenResult = request.open("GET", requestAll[requestIndex] );
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, AsyncHTTPRequest* request, int readyState)
void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
(void) optParm;
if (readyState == readyStateDone)
{
AHTTP_LOGDEBUG(F("\n**************************************"));
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
(void) optParm;
if (request->responseHTTPcode() == 200)
{
Serial.print(F("\n***************")); Serial.print(requestName[ requestIndex ]); Serial.println(F("***************"));
Serial.println(request->responseText());
Serial.println(F("**************************************"));
}
if (readyState == readyStateDone)
{
AHTTP_LOGDEBUG(F("\n**************************************"));
AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString());
if (request->responseHTTPcode() == 200)
{
Serial.print(F("\n***************"));
Serial.print(requestName[ requestIndex ]);
Serial.println(F("***************"));
Serial.println(request->responseText());
Serial.println(F("**************************************"));
}
#if 1
// Bypass hourly
if (requestIndex == 1)
requestIndex = 3;
else
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
// Bypass hourly
if (requestIndex == 1)
requestIndex = 3;
else
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
#else
// hourly too long, not display anyway. Not enough heap.
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
// hourly too long, not display anyway. Not enough heap.
requestIndex = (requestIndex + 1) % NUM_REQUESTS;
#endif
request->setDebug(false);
}
request->setDebug(false);
}
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(200);
Serial.print(F("\nStarting AsyncHTTPMultiRequests using ")); Serial.println(ARDUINO_BOARD);
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(200);
Serial.print(F("\nStarting AsyncHTTPMultiRequests using "));
Serial.println(ARDUINO_BOARD);
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
{
Serial.print(F("Warning. Must use this example on Version equal or later than : "));
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
}
if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN)
{
Serial.print(F("Warning. Must use this example on Version equal or later than : "));
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET);
}
#endif
WiFi.mode(WIFI_STA);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print(F("Connecting to WiFi SSID: ")); Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(F("."));
}
Serial.print(F("Connecting to WiFi SSID: "));
Serial.println(ssid);
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(WiFi.localIP());
request.setDebug(false);
request.onReadyStateChange(requestCB);
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(F("."));
}
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
// Send first request now
sendRequest();
Serial.print(F("AsyncHTTPRequest @ IP : "));
Serial.println(WiFi.localIP());
request.setDebug(false);
request.onReadyStateChange(requestCB);
ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);
ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);
// Send first request now
sendRequest();
}
void loop()
{
{
}