- Important Change from v1.2.0
- Why do we need the new Async Portenta_H7_AsyncHTTPRequest library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- HOWTO Fix
Multiple Definitions
Linker Error - Examples
- Example AsyncHTTPRequest
- Debug Terminal Output Samples
- 1. AsyncHTTPRequest running on PORTENTA_H7_M7 WiFi
- 2. AsyncDweetPOST running on PORTENTA_H7_M7 WiFi
- 3. AsyncWebClientRepeating running on PORTENTA_H7_M7 WiFi
- 4. AsyncCustomHeader running on PORTENTA_H7_M7 Ethernet
- 5. AsyncWebClientRepeating running on PORTENTA_H7_M7 Ethernet
- 6. AsyncSimpleGET running on PORTENTA_H7_M7 Ethernet
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License and credits
- Copyright
Please have a look at HOWTO Fix Multiple Definitions
Linker Error
Why do we need this Async Portenta_H7_AsyncHTTPRequest library
- Asynchronous HTTP Request library for Portenta_H7 using
Murata WiFi
orVision-shield Ethernet
. - Providing a subset of HTTP.
- Relying on on
Khoi Hoang's Portenta_H7_AsyncTCP
- 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 Portenta_H7_AsyncTCP
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:
- Portenta_H7 boards such as Portenta_H7 Rev2 ABX00042, etc., using ArduinoCore-mbed mbed_portenta core using
Vision-shield Ethernet
orMurata WiFi
Arduino IDE 1.8.19+
for Arduino.ArduinoCore-mbed mbed_portenta core 3.5.4+
for Arduino Portenta_H7 boards, such as Portenta_H7 Rev2 ABX00042, etc..Portenta_H7_AsyncTCP library v1.4.0+
for Portenta_H7 usingVision-shield Ethernet
orMurata WiFi
. To install. check
The best and easiest way is to use Arduino Library Manager
. Search for Portenta_H7_AsyncHTTPRequest
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to Portenta_H7_AsyncHTTPRequest page.
- Download the latest release
Portenta_H7_AsyncHTTPRequest-main.zip
. - Extract the zip file to
Portenta_H7_AsyncHTTPRequest-main
directory - Copy the whole
Portenta_H7_AsyncHTTPRequest-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install Portenta_H7_AsyncHTTPRequest library by using Library Manager. Search for Portenta_H7_AsyncHTTPRequest 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
To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh).
Then run the following command using sudo
$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh
This will create the file /etc/udev/rules.d/49-portenta_h7.rules
as follows:
# Portenta H7 bootloader mode UDEV rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh
To be able to compile, run on Portenta_H7 boards, you have to copy the whole mbed_portenta Packages_Patches directory into Arduino mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1).
Supposing the Arduino mbed_portenta version is 3.4.1. These file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/libraries/SocketWrapper/src/MbedUdp.h
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/libraries/SocketWrapper/src/MbedUdp.cpp
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/cores/arduino/src/mbed/connectivity/lwipstack/include/lwipstack/lwipopts.h
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 "Portenta_H7_AsyncHTTPRequest.hpp" //https://github.com/khoih-prog/Portenta_H7_AsyncHTTPRequest
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 "Portenta_H7_AsyncHTTPRequest.h" //https://github.com/khoih-prog/Portenta_H7_AsyncHTTPRequest
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
- AsyncHTTPRequest
- AsyncCustomHeader
- AsyncDweetGet
- AsyncDweetPost
- AsyncSimpleGET
- AsyncWebClientRepeating
- multiFileProject New
Example AsyncHTTPRequest
Please take a look at other examples, as well.
1. File AsyncHTTPRequest.ino
2. File defines.h
1. AsyncHTTPRequest running on PORTENTA_H7_M7 WiFi
Start AsyncHTTPRequest on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Using mac index = 15
Connected! IP address: 192.168.2.101
Request sent
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:01:30.472515-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: 1675224090
utc_datetime: 2023-02-01T04:01:30.472515+00:00
utc_offset: -05:00
week_number: 5
**************************************
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:02:24.463788-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: 1675224144
utc_datetime: 2023-02-01T04:02:24.463788+00:00
utc_offset: -05:00
week_number: 5
**************************************
2. AsyncDweetPOST running on PORTENTA_H7_M7 WiFi
Start AsyncDweetPOST on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Connecting to SSID: HueNet1
SSID: HueNet1
Local IP Address: 192.168.2.94
signal strength (RSSI):-25 dBm
Making new POST request
**************************************
{"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"pinA0-Read","created":"2021-10-15T04:17:43.768Z","content":{"sensorValue":88},"transaction":"34ca3083-054b-42ef-bcb0-91f7150dc680"}}
**************************************
"sensorValue":88
Value string: 88
Actual value: 88
3. AsyncWebClientRepeating running on PORTENTA_H7_M7 WiFi
Start AsyncWebClientRepeating on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Connecting to SSID: HueNet1
SSID: HueNet1
Local IP Address: 192.168.2.94
signal strength (RSS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; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;.
;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;`
,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
**************************************
4. AsyncCustomHeader running on PORTENTA_H7_M7 Ethernet
Start AsyncCustomHeader on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Using mac index = 15
Connected! IP address: 192.168.2.87
Sending GET Request to http://worldtimeapi.org/api/timezone/America/Toronto.txt
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:03:24.464007-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: 1675224204
utc_datetime: 2023-02-01T04:03:24.464007+00:00
utc_offset: -05:00
week_number: 5
**************************************
5. AsyncWebClientRepeating running on PORTENTA_H7_M7 Ethernet
Start AsyncWebClientRepeating on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Using mac index = 16
Connected! IP address: 192.168.2.87
**************************************
`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;;
;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;;
.;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;;
;;;;;; ;;;;;;; ;;;;;;, ;;;;;;.
,;;;;; ;;;;;;.;;;;;;` ;;;;;;
;;;;;. ;;;;;;;;;;;` ``` ;;;;;`
;;;;; ;;;;;;;;;, ;;; .;;;;;
`;;;;: `;;;;;;;; ;;; ;;;;;
,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;
:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;
:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;
.;;;;. ;;;;;;;. ;;; ;;;;;
;;;;; ;;;;;;;;; ;;; ;;;;;
;;;;; .;;;;;;;;;; ;;; ;;;;;,
;;;;;; `;;;;;;;;;;;; ;;;;;
`;;;;;, .;;;;;; ;;;;;;; ;;;;;;
;;;;;;: :;;;;;;. ;;;;;;; ;;;;;;
;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;:
;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;;
`;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;:
,;;;;;;;;;;;;;, ;;;;;;;;;;;;;;
.;;;;;;;;;` ,;;;;;;;;:
;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;;
;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;;
,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;;
;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;.
;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;`
,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;;
;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;;
;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;
**************************************
6. AsyncSimpleGET running on PORTENTA_H7_M7 Ethernet
Start AsyncSimpleGET on PORTENTA_H7_M7
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncHTTPRequest v1.5.0
Using mac index = 7
Connected! IP address: 192.168.2.87
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:04:24.464088-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: 1675224264
utc_datetime: 2023-02-01T04:04:24.464088+00:00
utc_offset: -05:00
week_number: 5
**************************************
HH HHHH
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:05:24.465017-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: 1675224324
utc_datetime: 2023-02-01T04:05:24.465017+00:00
utc_offset: -05:00
week_number: 5
************************************
Debug is enabled by default on Serial.
You can also change the debugging level from 0 to 4
#define PORTENTA_H7_ASYNC_HTTP_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _PORTENTA_H7_ATCP_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 mbed_portenta
core for Arduino.
Sometimes, the library will only work if you update the mbed_portenta
core to the latest version because I am using newly added functions.
Submit issues to: Portenta_H7_AsyncHTTPRequest issues
- Fix bug. Add enhancement
- Add many more examples.
- Add support to Portenta_H7 using
Vision-shield Ethernet
- Add support to
Murata
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
- Display only successful responseText in examples
- Improve debug messages by adding functions to display error messages instead of
cryptic error number
- 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
Portenta_H7_AsyncTCP
.
![]() โญ๏ธ 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) 2021- Khoi Hoang