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

Commit c0af8ac

Browse files
authored
v1.6.0 to save heap when sending large data
#### Releases v1.6.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 9087dbc commit c0af8ac

File tree

1 file changed

+138
-5
lines changed

1 file changed

+138
-5
lines changed

README.md

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
## Table of contents
1717

1818
* [Table of contents](#table-of-contents)
19+
* [Important Note from v1.6.0](#Important-Note-from-v160)
1920
* [Why do we need this AsyncWebServer_WT32_ETH01 library](#why-do-we-need-this-asyncwebserver_wt32_eth01-library)
2021
* [Important notes](#Important-notes)
2122
* [Features](#features)
@@ -86,8 +87,11 @@
8687
* [ 6. Async_PostServer](examples/Async_PostServer)
8788
* [ 7. Async_RegexPatterns_WT32_ETH01](examples/Async_RegexPatterns_WT32_ETH01)
8889
* [ 8. AsyncSimpleServer_WT32_ETH01](examples/AsyncSimpleServer_WT32_ETH01)
90+
* [ 9. Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) **New**
91+
* [10. Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) **New**
8992
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
9093
* [1. AsyncMultiWebServer_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720](#1-asyncmultiwebserver_wt32_eth01-on-wt32-eth01-with-eth_phy_lan8720)
94+
* [2. Async_AdvancedWebServer_MemoryIssues_Send_CString on WT32-ETH01 with ETH_PHY_LAN8720](#2-Async_AdvancedWebServer_MemoryIssues_Send_CString-on-wt32-eth01-with-eth_phy_lan8720)
9195
* [Debug](#debug)
9296
* [Troubleshooting](#troubleshooting)
9397
* [Issues](#issues)
@@ -98,6 +102,62 @@
98102
* [License](#license)
99103
* [Copyright](#copyright)
100104

105+
---
106+
---
107+
108+
### Important Note from v1.6.0
109+
110+
The new `v1.6.0` has added a new and powerful feature to permit using `CString` to save heap to send `very large data`.
111+
112+
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
113+
114+
1. [Async_AdvancedWebServer_MemoryIssues_Send_CString](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_Send_CString)
115+
2. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString)
116+
117+
If using Arduino `String`, to send a buffer around 30 KBytes, the used `Max Heap` is around **152,088 bytes**
118+
119+
If using `CString`, with the same 30 KBytes, the used `Max Heap` is around **120,876 bytes, saving around 30 KBytes**
120+
121+
This is very critical in use-cases where sending `very large data` is necessary, without `heap-allocation-error`.
122+
123+
1. The traditional function used to send `Arduino String` is
124+
125+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L511
126+
127+
such as
128+
129+
```cpp
130+
request->send(200, textPlainStr, ArduinoStr);
131+
```
132+
133+
The required HEAP is around **2 times of the String size**
134+
135+
2. To use `CString` but don't destroy it after sending. Use function
136+
137+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L513
138+
139+
such as
140+
141+
```cpp
142+
request->send(200, textPlainStr, cStr);
143+
```
144+
145+
The required HEAP is also around **2 times of the CString size**
146+
147+
148+
3. To use `CString` but destroy it after sending. Use function
149+
150+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L513
151+
152+
such as
153+
154+
```cpp
155+
request->send(200, textPlainStr, cStr, false);
156+
```
157+
158+
The required HEAP is also about **1 times of the CString size**.
159+
160+
101161
---
102162
---
103163
@@ -116,7 +176,7 @@ It's better to preserve the old enum order and just adding new items **to do no
116176
117177
To use with core `v1.0.6-`, just define in your sketch
118178
119-
```
179+
```cpp
120180
#define USING_CORE_ESP32_CORE_V200_PLUS false
121181
```
122182

@@ -1351,13 +1411,16 @@ build_flags =
13511411
6. [Async_PostServer](examples/Async_PostServer)
13521412
7. [Async_RegexPatterns_WT32_ETH01](examples/Async_RegexPatterns_WT32_ETH01)
13531413
8. [AsyncSimpleServer_WT32_ETH01](examples/AsyncSimpleServer_WT32_ETH01)
1414+
9. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) **New**
1415+
10. [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) **New**
1416+
13541417

13551418
---
13561419
---
13571420

13581421
### Example [Async_AdvancedWebServer](examples/Async_AdvancedWebServer)
13591422

1360-
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/c110c9dc0fd1b0158eb9f454f5a366fa193b8538/examples/Async_AdvancedWebServer/Async_AdvancedWebServer.ino#L41-L190
1423+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/examples/Async_AdvancedWebServer/Async_AdvancedWebServer.ino#L41-L190
13611424

13621425

13631426
You can access the Async Advanced WebServer @ the server IP
@@ -1378,7 +1441,7 @@ Following are debug terminal output and screen shots when running example [Async
13781441

13791442
```
13801443
Starting AsyncMultiWebServer_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720
1381-
AsyncWebServer_WT32_ETH01 v1.5.0 for core v2.0.0+
1444+
AsyncWebServer_WT32_ETH01 v1.6.0 for core v2.0.0+
13821445
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232
13831446
FULL_DUPLEX, 100Mbps
13841447
@@ -1405,6 +1468,73 @@ You can access the Async Advanced WebServers @ the server IP and corresponding p
14051468
<img src="https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/main/pics/AsyncMultiWebServer_WT32_SVR3.png">
14061469
</p>
14071470

1471+
---
1472+
1473+
#### 8. Async_AdvancedWebServer_MemoryIssues_Send_CString on RASPBERRY_PI_PICO_W
1474+
1475+
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
1476+
1477+
1478+
##### Using CString ===> smaller heap (120,876 bytes)
1479+
1480+
```
1481+
Start Async_AdvancedWebServer_MemoryIssues_Send_CString on WT32-ETH01 with ETH_PHY_LAN8720
1482+
AsyncWebServer_WT32_ETH01 v1.6.0 for core v2.0.0+
1483+
1484+
ETH Started
1485+
ETH Connected
1486+
ETH MAC: A8:48:FA:08:4B:FF, IPv4: 192.168.2.76
1487+
FULL_DUPLEX, 100Mbps
1488+
HTTP EthernetWebServer is @ IP : 192.168.2.232
1489+
1490+
HEAP DATA - Pre Create Arduino String Max heap: 326680 Free heap: 216212 Used heap: 110468
1491+
.
1492+
HEAP DATA - Pre Send Max heap: 326680 Free heap: 212292 Used heap: 114388
1493+
1494+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205848 Used heap: 120832
1495+
.
1496+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205816 Used heap: 120864
1497+
..
1498+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205812 Used heap: 120868
1499+
...... ..
1500+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205804 Used heap: 120876
1501+
........ .......... .......... .......... .......... .......... ..........
1502+
Out String Length=31282
1503+
.......... .
1504+
```
1505+
1506+
While using `Arduino String`, the HEAP usage is very large
1507+
1508+
1509+
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (152,088 bytes)
1510+
1511+
```
1512+
Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on WT32-ETH01 with ETH_PHY_LAN8720
1513+
AsyncWebServer_WT32_ETH01 v1.6.0 for core v2.0.0+
1514+
1515+
ETH Started
1516+
ETH Connected
1517+
ETH MAC: A8:48:FA:08:4B:FF, IPv4: 192.168.2.76
1518+
FULL_DUPLEX, 100Mbps
1519+
HTTP EthernetWebServer is @ IP : 192.168.2.232
1520+
1521+
HEAP DATA - Pre Create Arduino String Max heap: 326952 Free heap: 256484 Used heap: 70468
1522+
.
1523+
HEAP DATA - Pre Send Max heap: 326952 Free heap: 212600 Used heap: 114352
1524+
1525+
HEAP DATA - Post Send Max heap: 326952 Free heap: 174864 Used heap: 152088
1526+
....... .......... .......... ..........
1527+
.......... .......... .......... ........
1528+
Out String Length=31247
1529+
.. .......... .
1530+
```
1531+
1532+
1533+
You can access the Async Advanced WebServers at the displayed server IP, e.g. `192.168.2.74`
1534+
1535+
<p align="center">
1536+
<img src="https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/main/pics/Async_AdvancedWebServer_MemoryIssues_Send_CString.png">
1537+
</p>
14081538

14091539
---
14101540
---
@@ -1451,19 +1581,22 @@ Submit issues to: [AsyncWebServer_WT32_ETH01 issues](https://github.com/khoih-pr
14511581
6. Auto detect ESP32 core v1.0.6- or v2.0.0+ to use correct settings
14521582
7. Display compiler `#warning` only when DEBUG_LEVEL is 3+
14531583
8. Fix AsyncWebSocket bug
1454-
1584+
9. 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)
1585+
1586+
14551587
---
14561588
---
14571589

14581590

14591591
### Contributions and Thanks
14601592

14611593
1. Based on and modified from [Hristo Gochkov's ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer). Many thanks to [Hristo Gochkov](https://github.com/me-no-dev) for great [ESPAsyncWebServer Library](https://github.com/me-no-dev/ESPAsyncWebServer)
1462-
1594+
2. 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`
14631595

14641596
<table>
14651597
<tr>
14661598
<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>
1599+
<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>
14671600
</tr>
14681601
</table>
14691602

0 commit comments

Comments
 (0)