- Why do we need the new Async AsyncHTTPRequest_RP2040W library
- Changelog
- Prerequisites
- Installation
- HOWTO Fix
Multiple Definitions
Linker Error - Examples
- Example AsyncHTTPRequest
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License and credits
- Copyright
Why do we need this Async AsyncHTTPRequest_RP2040W library
- Asynchronous HTTP Request library for RASPBERRY_PI_PICO_W using CYW43439 WiFi
- Providing a subset of HTTP.
- Relying on
Khoi Hoang's AsyncTCP_RP2040W
- Methods similar in format and usage to XmlHTTPrequest in Javascript.
- GET, POST, PUT, PATCH, DELETE and HEAD
- Request and response headers
- Chunked response
- Single String response for short (<~5K) responses (heap permitting).
- Optional onData callback.
- Optional onReadyStatechange callback.
This library adds a simple HTTP layer on top of the AsyncTCP_RP2040W
library to facilitate REST communication from a Client to a Server. The paradigm is similar to the XMLHttpRequest in Javascript, employing the notion of a ready-state progression through the transaction request.
Synchronization can be accomplished using callbacks on ready-state change, a callback on data receipt, or simply polling for ready-state change. Data retrieval can be incremental as received, or bulk retrieved when the transaction completes provided there is enough heap to buffer the entire response.
The underlying buffering uses a new xbuf class. It handles both character and binary data. Class xbuf uses a chain of small (64 byte) segments that are allocated and added to the tail as data is added and deallocated from the head as data is read, achieving the same result as a dynamic circular buffer limited only by the size of heap. The xbuf implements indexOf and readUntil functions.
For short transactions, buffer space should not be an issue. In fact, it can be more economical than other methods that use larger fixed length buffers. Data is acked when retrieved by the caller, so there is some limited flow control to limit heap usage for larger transfers.
Request and response headers are handled in the typical fashion.
Chunked responses are recognized and handled transparently.
This library is based on, modified from:
- RASPBERRY_PI_PICO_W with CYW43439 WiFi using arduino-pico core v2.4.0+
Arduino IDE 1.8.19+
for Arduino.Earle Philhower's arduino-pico core v2.7.1+
for RASPBERRY_PI_PICO_W with CYW43439 WiFi, etc.AsyncTCP_RP2040W library v1.1.0+
for RASPBERRY_PI_PICO_W with CYW43439 WiFi. To install. check
The best and easiest way is to use Arduino Library Manager
. Search for AsyncHTTPRequest_RP2040W
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to AsyncHTTPRequest_RP2040W page.
- Download the latest release
AsyncHTTPRequest_RP2040W-main.zip
. - Extract the zip file to
AsyncHTTPRequest_RP2040W-main
directory - Copy the whole
AsyncHTTPRequest_RP2040W-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install AsyncHTTPRequest_RP2040W library by using Library Manager. Search for AsyncHTTPRequest_RP2040W in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
The current library implementation, using xyz-Impl.h
instead of standard xyz.cpp
, possibly creates certain Multiple Definitions
Linker error in certain use cases.
You can include this .hpp
file
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "AsyncHTTPRequest_RP2040W.hpp" //https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
in many files. But be sure to use the following .h
file in just 1 .h
, .cpp
or .ino
file, which must not be included in any other file, to avoid Multiple Definitions
Linker Error
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AsyncHTTPRequest_RP2040W.h" //https://github.com/khoih-prog/AsyncHTTPRequest_RP2040W
Check the new multiFileProject example for a HOWTO
demo.
Have a look at the discussion in Different behaviour using the src_cpp or src_h lib #80
- AsyncHTTPRequest
- AsyncCustomHeader
- AsyncDweetGet
- AsyncDweetPost
- AsyncSimpleGET
- AsyncWebClientRepeating
- multiFileProject
Example AsyncHTTPRequest
Please take a look at other examples, as well.
1. File AsyncHTTPRequest.ino
AsyncHTTPRequest_RP2040W/examples/AsyncHTTPRequest/AsyncHTTPRequest.ino
Lines 41 to 193 in 73cdc77
2. File defines.h
AsyncHTTPRequest_RP2040W/examples/AsyncHTTPRequest/defines.h
Lines 20 to 30 in 73cdc77
1. AsyncHTTPRequest running on RASPBERRY_PI_PICO_W using CYW43439 WiFi
Start AsyncHTTPRequest on RASPBERRY_PI_PICO_W
AsyncTCP_RP2040W v1.1.0
AsyncHTTPRequest_RP2040W v1.3.0
Connecting to SSID: HueNet1
SSID: HueNet1
Local IP Address: 192.168.2.77
Request sent
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:54:16.675525-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from:
dst_offset: 0
dst_until:
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675227256
utc_datetime: 2023-02-01T04:54:16.675525+00:00
utc_offset: -05:00
week_number: 5
**************************************
2. AsyncDweetPost running on RASPBERRY_PI_PICO_W using CYW43439 WiFi
Start AsyncDweetPOST on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
AsyncTCP_RP2040W v1.1.0
AsyncHTTPRequest_RP2040W v1.3.0
Connecting to SSID: HueNet1
SSID: HueNet1
Local IP Address: 192.168.2.180
Making new POST request
**************************************
{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"pinA0-Read","created":"2022-08-14T00:17:43.768Z","content":{"sensorValue":88},"transaction":"34ca3083-054b-42ef-bcb0-91f7150dc680"}}
**************************************
"sensorValue":88
Value string: 88
Actual value: 88
3. AsyncWebClientRepeating running on RASPBERRY_PI_PICO_W using CYW43439 WiFi
Start AsyncWebClientRepeating on RASPBERRY_PI_PICO_W
AsyncTCP_RP2040W v1.1.0
AsyncHTTPRequest_RP2040W v1.3.0
Connecting to SSID: HueNet1
SSID: HueNet1
Local IP Address: 192.168.2.180
**************************************
`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;;
;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;;
.;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;;
;;;;;; ;;;;;;; ;;;;;;, ;;;;;;.
,;;;;; ;;;;;;.;;;;;;` ;;;;;;
;;;;;. ;;;;;;;;;;;` ``` ;;;;;`
;;;;; ;;;;;;;;;, ;;; .;;;;;
`;;;;: `;;;;;;;; ;;; ;;;;;
,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;
:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;
:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;
.;;;;. ;;;;;;;. ;;; ;;;;;
;;;;; ;;;;;;;;; ;;; ;;;;;
;;;;; .;;;;;;;;;; ;;; ;;;;;,
;;;;;; `;;;;;;;;;;;; ;;;;;
`;;;;;, .;;;;;; ;;;;;;; ;;;;;;
;;;;;;: :;;;;;;. ;;;;;;; ;;;;;;
;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;:
;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;;
`;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;:
,;;;;;;;;;;;;;, ;;;;;;;;;;;;;;
.;;;;;;;;;` ,;;;;;;;;:
;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;;
;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;;
,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;;
;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;.
;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;`
,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
**************************************
Debug is enabled by default on Serial.
You can also change the debugging level from 0 to 4
#define ASYNC_HTTP_RP2040W_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNCTCP_RP2040W_LOGLEVEL_ 1
#define _ASYNC_HTTP_LOGLEVEL_ 1
If you get compilation errors, more often than not, you may need to install a newer version of the arduino-pico core
Sometimes, the library will only work if you update the arduino-pico core core to the latest version because I am using newly added functions.
Submit issues to: AsyncHTTPRequest_RP2040W issues
- Fix bug. Add enhancement
- Add many more examples.
- Add support to RASPBERRY_PI_PICO_W using CYW43439 WiFi
- Add debugging features.
- Add PUT, PATCH, DELETE and HEAD besides GET and POST.
- Fix
multiple-definitions
linker error and weird bug related tosrc_cpp
. - Optimize library code by using
reference-passing
instead ofvalue-passing
- Fix long timeout if using
IPAddress
- Not try to reconnect to the same
host:port
after connected - Fix bug of wrong
reqStates
- Default to reconnect to the same
host:port
after connected for new HTTP sites. - Use
allman astyle
and addutils
- Fix bug of
_parseURL()
. Check Bug with _parseURL() #21 - Improve
README.md
so that links can be used in other sites, such asPIO
This library is based on, modified, bug-fixed and improved from:
- Bob Lemaire's asyncHTTPrequest Library to use the better asynchronous features of
AsyncTCP_RP2040W
.
⭐️ Bob Lemaire |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under GPLv3
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
Copyright (C) 2022- Khoi Hoang