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

Commit

Permalink
v1.2.2 default to reconnect to the same host:port
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog authored Nov 10, 2022
1 parent 284af5d commit 73cdc77
Show file tree
Hide file tree
Showing 25 changed files with 1,163 additions and 885 deletions.
32 changes: 27 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

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

```
Arduino IDE version: 1.8.19
RP2040 core v2.6.1
RP2040 core v2.6.3
RASPBERRY_PI_PICO_W Module
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/AsyncHTTPRequest_RP2040W/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/AsyncHTTPRequest_RP2040W_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncHTTPRequest_RP2040W_GitHub$
```

2. Issue astyle command

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

7 changes: 7 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)
* [Release v1.2.2](#Release-v122)
* [Release v1.2.1](#Release-v121)
* [Release v1.2.0](#Release-v120)
* [Release v1.1.1](#Release-v111)
Expand All @@ -23,6 +24,12 @@

## Changelog

### 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](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/44)
2. Fix bug
3. Use `allman astyle` and add `utils`

### Release v1.2.1

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)
Expand Down
207 changes: 108 additions & 99 deletions examples/AsyncCustomHeader/AsyncCustomHeader.ino
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
/****************************************************************************************************************************
AsyncCustomHeader.ino
For RP2040W with CYW43439 WiFi
AsyncHTTPRequest_RP2040W is a library for the RP2040W with CYW43439 WiFi
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
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/>.
*****************************************************************************************************************************/

#include "defines.h"

#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN_TARGET "AsyncHTTPRequest_RP2040W v1.2.1"
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN 1002001
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN_TARGET "AsyncHTTPRequest_RP2040W v1.2.2"
#define ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN 1002002

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

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

void sendRequest()
{
static bool requestOpenResult;

if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));

requestOpenResult = request.open("GET", GET_ServerAddress);
//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
if (requestOpenResult)
{
// Only send() if open() returns true, or crash
request.send();
}
else
{
Serial.println("Can't send bad request");
}
}
else
{
Serial.println("Can't send request");
}
static bool requestOpenResult;

if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
{
Serial.println("\nSending GET Request to " + String(GET_ServerAddress));

requestOpenResult = request.open("GET", GET_ServerAddress);

//request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
if (requestOpenResult)
{
// Only send() if open() returns true, or crash
request.send();
}
else
{
Serial.println("Can't send bad request");
}
}
else
{
Serial.println("Can't send request");
}
}

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

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

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

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

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

void printWifiStatus()
{
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("Local IP Address: ");
Serial.println(ip);
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("Local IP Address: ");
Serial.println(ip);
}

void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);
Serial.begin(115200);

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

Serial.print("\nStart AsyncCustomHeader on "); Serial.println(BOARD_NAME);
Serial.println(ASYNCTCP_RP2040W_VERSION);
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION);
Serial.print("\nStart AsyncCustomHeader on ");
Serial.println(BOARD_NAME);
Serial.println(ASYNCTCP_RP2040W_VERSION);
Serial.println(ASYNC_HTTP_REQUEST_RP2040W_VERSION);

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

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

#endif

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

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
///////////////////////////////////

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");

// don't continue
while (true);
}

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

status = WiFi.begin(ssid, pass);
status = WiFi.begin(ssid, pass);

delay(1000);

// attempt to connect to WiFi network
while ( status != WL_CONNECTED)
{
delay(500);

// Connect to WPA/WPA2 network
status = WiFi.status();
}
delay(1000);

printWifiStatus();
// attempt to connect to WiFi network
while ( status != WL_CONNECTED)
{
delay(500);

///////////////////////////////////
// Connect to WPA/WPA2 network
status = WiFi.status();
}

request.setDebug(false);
printWifiStatus();

// 5s timeout
request.setTimeout(5);
///////////////////////////////////

request.onReadyStateChange(requestCB);
request.setDebug(false);

// 5s timeout
request.setTimeout(5);

request.onReadyStateChange(requestCB);
}

void sendRequestRepeat()
{
static unsigned long sendRequest_timeout = 0;
static unsigned long sendRequest_timeout = 0;

#define SEND_REQUEST_INTERVAL 60000L

// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
{
sendRequest();
sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
}
// sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
if ((millis() > sendRequest_timeout) || (sendRequest_timeout == 0))
{
sendRequest();

sendRequest_timeout = millis() + SEND_REQUEST_INTERVAL;
}
}

void loop()
{
sendRequestRepeat();
sendRequestRepeat();
}
14 changes: 7 additions & 7 deletions examples/AsyncCustomHeader/defines.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/****************************************************************************************************************************
defines.h
For RP2040W with CYW43439 WiFi
AsyncHTTPRequest_RP2040W is a library for the RP2040W with CYW43439 WiFi
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
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/>.
*****************************************************************************************************************************/


#ifndef defines_h
#define defines_h

#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
#error For RASPBERRY_PI_PICO_W only
#error For RASPBERRY_PI_PICO_W only
#endif

char ssid[] = "your_ssid"; // your network SSID (name)
Expand Down
Loading

0 comments on commit 73cdc77

Please sign in to comment.