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

Commit 0657ad6

Browse files
authored
v1.2.0 to save heap when sending large data
### Release v1.2.0 1. Support using `CString` to save heap to send `very large data`. Check [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](khoih-prog/Portenta_H7_AsyncWebServer#8) 2. Add multiple examples to demo the new feature
1 parent 9075cb4 commit 0657ad6

File tree

2 files changed

+145
-10
lines changed

2 files changed

+145
-10
lines changed

README.md

Lines changed: 144 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
## Table of contents
1515

1616
* [Table of contents](#table-of-contents)
17+
* [Important Note from v1.2.0](#Important-Note-from-v120)
1718
* [Why do we need this AsyncWebServer_RP2040W library](#why-do-we-need-this-AsyncWebServer_RP2040W-library)
1819
* [Features](#features)
1920
* [Why Async is better](#why-async-is-better)
@@ -87,6 +88,8 @@
8788
* [10. WebClientRepeating](examples/WebClientRepeating)
8889
* [11. Async_AdvancedWebServer_Country](examples/Async_AdvancedWebServer_Country) **New**
8990
* [12. Async_AdvancedWebServer_favicon](examples/Async_AdvancedWebServer_favicon) **New**
91+
* [13. Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) **New**
92+
* [14. Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) **New**
9093
* [Example Async_AdvancedWebServer](#Example-Async_AdvancedWebServer)
9194
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
9295
* [1. Async_AdvancedWebServer on RASPBERRY_PI_PICO_W using CYW43439 WiFi](#1-Async_AdvancedWebServer-on-RASPBERRY_PI_PICO_W-using-CYW43439-WiFi)
@@ -96,6 +99,7 @@
9699
* [5. MQTT_ThingStream on RASPBERRY_PI_PICO_W using CYW43439 WiFi](#5-MQTT_ThingStream-on-RASPBERRY_PI_PICO_W-using-CYW43439-WiFi)
97100
* [6. Async_AdvancedWebServer_Country on RASPBERRY_PI_PICO_W using CYW43439 WiFi](#6-Async_AdvancedWebServer_Country-on-RASPBERRY_PI_PICO_W-using-CYW43439-WiFi)
98101
* [7. Async_AdvancedWebServer_favicon on RASPBERRY_PI_PICO_W using CYW43439 WiFi](#7-Async_AdvancedWebServer_favicon-on-RASPBERRY_PI_PICO_W-using-CYW43439-WiFi)
102+
* [8. Async_AdvancedWebServer_MemoryIssues_Send_CString on RASPBERRY_PI_PICO_W](#8-Async_AdvancedWebServer_MemoryIssues_Send_CString-on-RASPBERRY_PI_PICO_W)
99103
* [Debug](#debug)
100104
* [Troubleshooting](#troubleshooting)
101105
* [Issues](#issues)
@@ -106,6 +110,63 @@
106110
* [License](#license)
107111
* [Copyright](#copyright)
108112

113+
---
114+
---
115+
116+
### Important Note from v1.2.0
117+
118+
The new `v1.2.0` has added a new and powerful feature to permit using `CString` to save heap to send `very large data`.
119+
120+
Check the `marvelleous` PR of **@salasidis** [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8) and these new examples
121+
122+
1. [Async_AdvancedWebServer_MemoryIssues_Send_CString](https://github.com/khoih-prog/AsyncWebServer_RP2040W/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_Send_CString)
123+
2. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](https://github.com/khoih-prog/AsyncWebServer_RP2040W/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString)
124+
125+
If using Arduino `String`, to send a buffer around 40 KBytes, the used `Max Heap` is around **75,240 bytes (~2 times)**
126+
127+
If using CString, with the same 40 KByte, the used `Max Heap` is around **43,976 bytes (~1 times)**
128+
129+
This is very critical in use-cases where sending `very large data` is necessary, without `heap-allocation-error`.
130+
131+
132+
1. The traditional function used to send `Arduino String` is
133+
134+
https://github.com/khoih-prog/AsyncWebServer_RP2040W/blob/9075cb4cce8be687ae4a79d96afc1c46180b3304/src/AsyncWebServer_RP2040W.h#L413
135+
136+
such as
137+
138+
```cpp
139+
request->send(200, textPlainStr, ArduinoStr);
140+
```
141+
The required HEAP is about **2 times of the String size**
142+
143+
2. To use `CString` but don't destroy it after sending. Use function
144+
145+
https://github.com/khoih-prog/AsyncWebServer_RP2040W/blob/9075cb4cce8be687ae4a79d96afc1c46180b3304/src/AsyncWebServer_RP2040W.h#L414
146+
147+
such as
148+
149+
```cpp
150+
request->send(200, textPlainStr, cStr);
151+
```
152+
153+
The required HEAP is also about **2 times of the CString size**
154+
155+
156+
3. To use `CString` but destroy it after sending. Use function
157+
158+
https://github.com/khoih-prog/AsyncWebServer_RP2040W/blob/9075cb4cce8be687ae4a79d96afc1c46180b3304/src/AsyncWebServer_RP2040W.h#L414
159+
160+
such as
161+
162+
```cpp
163+
request->send(200, textPlainStr, cStr, false);
164+
```
165+
166+
The required HEAP is also about **1 times of the CString size**.
167+
168+
169+
109170
---
110171
---
111172
@@ -1426,7 +1487,8 @@ build_flags =
14261487
10. [WebClientRepeating](examples/WebClientRepeating)
14271488
11. [Async_AdvancedWebServer_Country](examples/Async_AdvancedWebServer_Country) **New**
14281489
12. [Async_AdvancedWebServer_favicon](examples/Async_AdvancedWebServer_favicon) **New**
1429-
1490+
13. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) **New**
1491+
14. [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) **New**
14301492

14311493
---
14321494
---
@@ -1454,7 +1516,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer](e
14541516
```
14551517
Start Async_AdvancedWebServer on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
14561518
AsyncTCP_RP2040W v1.1.0
1457-
AsyncWebServer_RP2040W v1.1.2
1519+
AsyncWebServer_RP2040W v1.2.0
14581520
Connecting to SSID: HueNet1
14591521
SSID: HueNet1
14601522
Local IP Address: 192.168.2.180
@@ -1478,7 +1540,7 @@ Following is debug terminal output when running example [WebClient](examples/Web
14781540
```
14791541
Start WebClient on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
14801542
AsyncTCP_RP2040W v1.1.0
1481-
AsyncWebServer_RP2040W v1.1.2
1543+
AsyncWebServer_RP2040W v1.2.0
14821544
Connecting to SSID: HueNet1
14831545
SSID: HueNet1
14841546
Local IP Address: 192.168.2.180
@@ -1556,7 +1618,7 @@ Following is debug terminal output when running example [MQTTClient_Auth](exampl
15561618
```
15571619
Start MQTTClient_Auth on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
15581620
AsyncTCP_RP2040W v1.1.0
1559-
AsyncWebServer_RP2040W v1.1.2
1621+
AsyncWebServer_RP2040W v1.2.0
15601622
Connecting to SSID: HueNet1
15611623
SSID: HueNet1
15621624
Local IP Address: 192.168.2.180
@@ -1578,7 +1640,7 @@ Following is debug terminal output when running example [MQTTClient_Basic](examp
15781640
```
15791641
Start MQTTClient_Basic on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
15801642
AsyncTCP_RP2040W v1.1.0
1581-
AsyncWebServer_RP2040W v1.1.2
1643+
AsyncWebServer_RP2040W v1.2.0
15821644
Connecting to SSID: HueNet1
15831645
SSID: HueNet1
15841646
Local IP Address: 192.168.2.180
@@ -1600,7 +1662,7 @@ Following is debug terminal output when running example [MQTT_ThingStream](examp
16001662
```
16011663
Start MQTT_ThingStream on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
16021664
AsyncTCP_RP2040W v1.1.0
1603-
AsyncWebServer_RP2040W v1.1.2
1665+
AsyncWebServer_RP2040W v1.2.0
16041666
Connecting to SSID: HueNet1
16051667
SSID: HueNet1
16061668
Local IP Address: 192.168.2.180
@@ -1628,7 +1690,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer_Co
16281690
```
16291691
Start Async_AdvancedWebServer_Country on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
16301692
AsyncTCP_RP2040W v1.1.0
1631-
AsyncWebServer_RP2040W v1.1.2
1693+
AsyncWebServer_RP2040W v1.2.0
16321694
Connecting to SSID: HueNet1
16331695
SSID: HueNet1
16341696
Local IP Address: 192.168.2.180
@@ -1664,7 +1726,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer_fa
16641726
```
16651727
14:22:06.632 -> Start Async_AdvancedWebServer_favicon on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
16661728
14:22:06.632 -> AsyncTCP_RP2040W v1.1.0
1667-
14:22:06.632 -> AsyncWebServer_RP2040W v1.1.2
1729+
14:22:06.632 -> AsyncWebServer_RP2040W v1.2.0
16681730
14:22:06.632 -> Connecting to SSID: HueNet1
16691731
14:22:13.328 -> SSID: HueNet1
16701732
14:22:13.328 -> Local IP Address: 192.168.2.180
@@ -1688,6 +1750,77 @@ You can see the `favicon.ico` at the upper left corner
16881750
<img src="https://github.com/khoih-prog/AsyncWebServer_RP2040W/blob/main/pics/Async_AdvancedWebServer_Firefox_favicon.png">
16891751
</p>
16901752

1753+
---
1754+
1755+
1756+
#### 8. Async_AdvancedWebServer_MemoryIssues_Send_CString on RASPBERRY_PI_PICO_W
1757+
1758+
Following is the debug terminal and screen shot when running example [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) on RASPBERRY_PI_PICO_W to demonstrate the new and powerful `HEAP-saving` feature
1759+
1760+
1761+
##### Using CString ===> small heap (43,976 bytes)
1762+
1763+
```
1764+
Start Async_AdvancedWebServer_MemoryIssues_Send_CString on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1765+
AsyncTCP_RP2040W v1.1.0
1766+
AsyncWebServer_RP2040W v1.2.0
1767+
Connecting to SSID: HueNet1
1768+
SSID: HueNet1
1769+
Local IP Address: 192.168.2.74
1770+
Country code: XX
1771+
HTTP EthernetWebServer is @ IP : 192.168.2.74
1772+
1773+
HEAP DATA - Pre Create Arduino String Cur heap: 193000 Free heap: 150928 Max heap: 42072
1774+
..
1775+
HEAP DATA - Pre Send Cur heap: 193000 Free heap: 149176 Max heap: 43824
1776+
1777+
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149048 Max heap: 43952
1778+
1779+
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149032 Max heap: 43968
1780+
........ .
1781+
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149024 Max heap: 43976
1782+
.......... .......... .......... ........
1783+
Out String Length=31247
1784+
.. .......... .......... .......... ..........
1785+
```
1786+
1787+
While using Arduino String, the HEAP usage is very large
1788+
1789+
1790+
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (75,240 bytes)
1791+
1792+
```
1793+
Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1794+
AsyncTCP_RP2040W v1.1.0
1795+
AsyncWebServer_RP2040W v1.2.0
1796+
Connecting to SSID: HueNet1
1797+
SSID: HueNet1
1798+
Local IP Address: 192.168.2.74
1799+
Country code: XX
1800+
HTTP EthernetWebServer is @ IP : 192.168.2.74
1801+
1802+
HEAP DATA - Pre Create Arduino String Cur heap: 193256 Free heap: 191192 Max heap: 2064
1803+
.
1804+
HEAP DATA - Pre Send Cur heap: 193256 Free heap: 149432 Max heap: 43824
1805+
1806+
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118056 Max heap: 75200
1807+
......
1808+
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118024 Max heap: 75232
1809+
... .......... .......... .......... ...
1810+
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118016 Max heap: 75240
1811+
....... .......... .......... ..........
1812+
.......... .......... .......... ........
1813+
Out String Length=31247
1814+
.. .......... .
1815+
```
1816+
1817+
1818+
You can access the Async Advanced WebServers at the displayed server IP, e.g. `192.168.2.74`
1819+
1820+
<p align="center">
1821+
<img src="https://github.com/khoih-prog/AsyncWebServer_RP2040W v1.2.0/blob/main/pics/Async_AdvancedWebServer_MemoryIssues_Send_CString.png">
1822+
</p>
1823+
16911824
---
16921825
---
16931826

@@ -1730,7 +1863,7 @@ Submit issues to: [AsyncWebServer_RP2040W issues](https://github.com/khoih-prog/
17301863
4. Add tempo method to modify `arduino-pico` core to change `country-code`
17311864
5. Fix issue with slow browsers or network. Check [Target stops responding after variable time when using Firefox on Windows 10 #3](https://github.com/khoih-prog/AsyncWebServer_RP2040W/issues/3)
17321865
6. Add functions and example `Async_AdvancedWebServer_favicon` to support `favicon.ico`
1733-
1866+
7. Support using `CString` to save heap to send `very large data`. Check [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8)
17341867

17351868
---
17361869
---
@@ -1741,11 +1874,13 @@ Submit issues to: [AsyncWebServer_RP2040W issues](https://github.com/khoih-prog/
17411874
2. Thanks to [revell1](https://github.com/revell1) to
17421875
- report the bug in [LED state appears to be reversed. #2](https://github.com/khoih-prog/AsyncWebServer_RP2040W/issues/2), leading to v1.0.2
17431876
- request enhancement in [Target stops responding after variable time when using Firefox on Windows 10 #3](https://github.com/khoih-prog/AsyncWebServer_RP2040W/issues/3), leading to v1.1.0
1877+
3. Thanks to [salasidis](https://github.com/salasidis) aka [rs77can](https://forum.arduino.cc/u/rs77can) to discuss and make the mavellous PR [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8), leading to `v1.2.0` to support using `CString` to save heap to send `very large data`
17441878

17451879
<table>
17461880
<tr>
17471881
<td align="center"><a href="https://github.com/me-no-dev"><img src="https://github.com/me-no-dev.png" width="100px;" alt="me-no-dev"/><br /><sub><b>⭐️⭐️ Hristo Gochkov</b></sub></a><br /></td>
17481882
<td align="center"><a href="https://github.com/revell1"><img src="https://github.com/revell1.png" width="100px;" alt="revell1"/><br /><sub><b>revell1</b></sub></a><br /></td>
1883+
<td align="center"><a href="https://github.com/salasidis"><img src="https://github.com/salasidis.png" width="100px;" alt="salasidis"/><br /><sub><b>⭐️ salasidis</b></sub></a><br /></td>
17491884
</tr>
17501885
</table>
17511886

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AsyncWebServer_RP2040W
2-
version=1.1.2
2+
version=1.2.0
33
author=Hristo Gochkov,Khoi Hoang
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=Asynchronous WebServer Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core.

0 commit comments

Comments
 (0)