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

Commit 0479c0e

Browse files
authored
v1.6.1 to not destroy original CString
#### Releases v1.6.1 1. Don't need `memmove()`, CString no longer destroyed. Check [All memmove() removed - string no longer destroyed #11](khoih-prog/Portenta_H7_AsyncWebServer#11)
1 parent 6c499f1 commit 0479c0e

File tree

1 file changed

+59
-42
lines changed

1 file changed

+59
-42
lines changed

README.md

+59-42
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,73 @@
107107

108108
### Important Note from v1.6.0
109109

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`.
110+
The new `v1.6.0+` has added a new and powerful feature to permit using `CString` in optional `SDRAM` to save heap to send `very large data`.
111111

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
112+
Check the `marvelleous` PRs of **@salasidis** in [Portenta_H7_AsyncWebServer library](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer)
113+
- [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8)
114+
- [All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11)
115+
116+
and these new examples
113117

114118
1. [Async_AdvancedWebServer_MemoryIssues_Send_CString](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_Send_CString)
115119
2. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString)
116120

117-
If using Arduino `String`, to send a buffer around 30 KBytes, the used `Max Heap` is around **152,088 bytes**
121+
If using Arduino String, to send a buffer around 30 KBytes, the used `Max Heap` is around **152,136 bytes**
118122

119-
If using `CString`, with the same 30 KBytes, the used `Max Heap` is around **120,876 bytes, saving around 30 KBytes**
123+
If using CString in regular memory, with the same 30 KBytes, the used `Max Heap` is around **120,880 bytes), saving around a buffer size (30 KBytes)**
120124

121125
This is very critical in use-cases where sending `very large data` is necessary, without `heap-allocation-error`.
122126

127+
123128
1. The traditional function used to send `Arduino String` is
124129

125-
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L511
130+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/6c499f1d3e91b1e33f86f3d9c6a36fa60470a38f/src/AsyncWebServer_WT32_ETH01.h#L518
131+
132+
```cpp
133+
void send(int code, const String& contentType = String(), const String& content = String());
134+
```
126135
127136
such as
128137
129138
```cpp
130139
request->send(200, textPlainStr, ArduinoStr);
131140
```
141+
The required additional HEAP is about **3 times of the String size**
142+
132143

133-
The required HEAP is around **2 times of the String size**
144+
2. To use `CString` with copying while sending. Use function
134145

135-
2. To use `CString` but don't destroy it after sending. Use function
146+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/6c499f1d3e91b1e33f86f3d9c6a36fa60470a38f/src/AsyncWebServer_WT32_ETH01.h#L520
136147

137-
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L513
148+
```cpp
149+
void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD
150+
```
138151
139152
such as
140153
141154
```cpp
142155
request->send(200, textPlainStr, cStr);
143156
```
144157

145-
The required HEAP is also around **2 times of the CString size**
158+
The required additional HEAP is also about **2 times of the CString size** because of `unnecessary copies` of the CString in HEAP. Avoid this `unefficient` way.
146159

147160

148-
3. To use `CString` but destroy it after sending. Use function
161+
3. To use `CString` without copying while sending. Use function
149162

150-
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/9087dbc7adf03139f5967b784a9f0c7a0c358339/src/AsyncWebServer_WT32_ETH01.h#L513
163+
https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01/blob/6c499f1d3e91b1e33f86f3d9c6a36fa60470a38f/src/AsyncWebServer_WT32_ETH01.h#L520
164+
165+
```cpp
166+
void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD
167+
```
151168
152169
such as
153170
154171
```cpp
155172
request->send(200, textPlainStr, cStr, false);
156173
```
157174

158-
The required HEAP is also about **1 times of the CString size**.
175+
The required additional HEAP is about **1 times of the CString size**. This way is the best and most efficient way to use by avoiding of `unnecessary copies` of the CString in HEAP
176+
159177

160178

161179
---
@@ -256,7 +274,7 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncW
256274
## Important things to remember
257275

258276
- This is fully asynchronous server and as such does not run on the loop thread.
259-
- You can not use yield() or delay() or any function that uses them inside the callbacks
277+
- You can not use `yield()` or `delay()` or any function that uses them inside the callbacks
260278
- The server is smart enough to know when to close the connection and free resources
261279
- You can not send more than one response to a single request
262280

@@ -1057,7 +1075,7 @@ void sendDataWs(AsyncWebSocketClient * client)
10571075

10581076
### Limiting the number of web socket clients
10591077

1060-
Browsers sometimes do not correctly close the websocket connection, even when the close() function is called in javascript. This will eventually exhaust the web server's resources and will cause the server to crash. Periodically calling the cleanClients() function from the main loop() function limits the number of clients by closing the oldest client when the maximum number of clients has been exceeded. This can called be every cycle, however, if you wish to use less power, then calling as infrequently as once per second is sufficient.
1078+
Browsers sometimes do not correctly close the websocket connection, even when the `close()` function is called in javascript. This will eventually exhaust the web server's resources and will cause the server to crash. Periodically calling the `cleanClients()` function from the main `loop()` function limits the number of clients by closing the oldest client when the maximum number of clients has been exceeded. This can called be every cycle, however, if you wish to use less power, then calling as infrequently as once per second is sufficient.
10611079

10621080
```cpp
10631081
void loop(){
@@ -1069,8 +1087,8 @@ void loop(){
10691087

10701088
## Async Event Source Plugin
10711089

1072-
The server includes EventSource (Server-Sent Events) plugin which can be used to send short text events to the browser.
1073-
Difference between EventSource and WebSockets is that EventSource is single direction, text-only protocol.
1090+
The server includes `EventSource` (Server-Sent Events) plugin which can be used to send short text events to the browser.
1091+
Difference between `EventSource` and `WebSockets` is that `EventSource` is single direction, text-only protocol.
10741092

10751093
### Setup Event Source on the server
10761094

@@ -1436,12 +1454,12 @@ You can access the Async Advanced WebServer @ the server IP
14361454

14371455
#### 1. AsyncMultiWebServer_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720
14381456

1439-
Following are debug terminal output and screen shots when running example [AsyncMultiWebServer_WT32_ETH01](examples/AsyncMultiWebServer_WT32_ETH01) on WT32-ETH01 with ETH_PHY_LAN8720, using EP32 core v2.0.0, to demonstrate the operation of 3 independent AsyncWebServers on 3 different ports and how to handle the complicated AsyncMultiWebServers.
1457+
Following are debug terminal output and screen shots when running example [AsyncMultiWebServer_WT32_ETH01](examples/AsyncMultiWebServer_WT32_ETH01) on `WT32-ETH01 with ETH_PHY_LAN8720`, using ESP32 core `v2.0.0+`, to demonstrate the operation of 3 independent AsyncWebServers on 3 different ports and how to handle the complicated AsyncMultiWebServers.
14401458

14411459

14421460
```
14431461
Starting AsyncMultiWebServer_WT32_ETH01 on WT32-ETH01 with ETH_PHY_LAN8720
1444-
AsyncWebServer_WT32_ETH01 v1.6.0 for core v2.0.0+
1462+
AsyncWebServer_WT32_ETH01 v1.6.1 for core v2.0.0+
14451463
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232
14461464
FULL_DUPLEX, 100Mbps
14471465
@@ -1472,32 +1490,28 @@ You can access the Async Advanced WebServers @ the server IP and corresponding p
14721490

14731491
#### 2. Async_AdvancedWebServer_MemoryIssues_Send_CString on WT32-ETH01 with ETH_PHY_LAN8720
14741492

1475-
Following is the debug terminal and screen shot when running example [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString), on WT32-ETH01 with ETH_PHY_LAN8720, to demonstrate the new and powerful `HEAP-saving` feature
1493+
Following is the debug terminal and screen shot when running example [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString), on `WT32-ETH01 with ETH_PHY_LAN8720`, to demonstrate the new and powerful `HEAP-saving` feature
14761494

14771495

1478-
##### Using CString ===> smaller heap (120,876 bytes)
1496+
##### Using CString ===> smaller heap (120,880 bytes)
14791497

14801498
```
14811499
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+
1500+
AsyncWebServer_WT32_ETH01 v1.6.1 for core v2.0.0+
14831501
14841502
ETH Started
14851503
ETH Connected
14861504
ETH MAC: A8:48:FA:08:4B:FF, IPv4: 192.168.2.76
14871505
FULL_DUPLEX, 100Mbps
14881506
HTTP EthernetWebServer is @ IP : 192.168.2.232
14891507
1490-
HEAP DATA - Pre Create Arduino String Max heap: 326680 Free heap: 216212 Used heap: 110468
1508+
HEAP DATA - Pre Create Arduino String Max heap: 326680 Free heap: 216200 Used heap: 110480
14911509
.
14921510
HEAP DATA - Pre Send Max heap: 326680 Free heap: 212292 Used heap: 114388
14931511
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
1512+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205832 Used heap: 120848
1513+
1514+
HEAP DATA - Post Send Max heap: 326680 Free heap: 205800 Used heap: 120880
15011515
........ .......... .......... .......... .......... .......... ..........
15021516
Out String Length=31282
15031517
.......... .
@@ -1506,25 +1520,26 @@ Out String Length=31282
15061520
While using `Arduino String`, the HEAP usage is very large
15071521

15081522

1509-
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (152,088 bytes)
1523+
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (152,136 bytes)
15101524

15111525
```
15121526
Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on WT32-ETH01 with ETH_PHY_LAN8720
1513-
AsyncWebServer_WT32_ETH01 v1.6.0 for core v2.0.0+
1527+
AsyncWebServer_WT32_ETH01 v1.6.1 for core v2.0.0+
15141528
15151529
ETH Started
15161530
ETH Connected
1517-
ETH MAC: A8:48:FA:08:4B:FF, IPv4: 192.168.2.76
1531+
ETH MAC: A8:48:FA:08:4B:FF, IPv4: 192.168.2.232
15181532
FULL_DUPLEX, 100Mbps
15191533
HTTP EthernetWebServer is @ IP : 192.168.2.232
15201534
1521-
HEAP DATA - Pre Create Arduino String Max heap: 326952 Free heap: 256484 Used heap: 70468
1535+
HEAP DATA - Pre Create Arduino String Max heap: 326968 Free heap: 256504 Used heap: 70464
15221536
.
1523-
HEAP DATA - Pre Send Max heap: 326952 Free heap: 212600 Used heap: 114352
1537+
HEAP DATA - Pre Send Max heap: 326968 Free heap: 212596 Used heap: 114372
15241538
1525-
HEAP DATA - Post Send Max heap: 326952 Free heap: 174864 Used heap: 152088
1526-
....... .......... .......... ..........
1527-
.......... .......... .......... ........
1539+
HEAP DATA - Post Send Max heap: 326968 Free heap: 174856 Used heap: 152112
1540+
......... .......... .......... .......... ...
1541+
HEAP DATA - Post Send Max heap: 326968 Free heap: 174832 Used heap: 152136
1542+
....... .......... ..........
15281543
Out String Length=31247
15291544
.. .......... .
15301545
```
@@ -1573,13 +1588,13 @@ Submit issues to: [AsyncWebServer_WT32_ETH01 issues](https://github.com/khoih-pr
15731588

15741589
## DONE
15751590

1576-
1. Initial port to WT32_ETH01 boards using built-in LAN8720A Ethernet
1591+
1. Initial port to `WT32_ETH01` boards using built-in `LAN8720A` Ethernet
15771592
2. Add more examples.
15781593
3. Add debugging features.
15791594
4. Add Table-of-Contents and Version String
1580-
5. Support breaking ESP32 core v2.0.0+ as well as v1.0.6-
1581-
6. Auto detect ESP32 core v1.0.6- or v2.0.0+ to use correct settings
1582-
7. Display compiler `#warning` only when DEBUG_LEVEL is 3+
1595+
5. Support breaking ESP32 core `v2.0.0+` as well as `v1.0.6-`
1596+
6. Auto detect ESP32 core `v1.0.6-` or `v2.0.0+` to use correct settings
1597+
7. Display compiler `#warning` only when `DEBUG_LEVEL` is 3+
15831598
8. Fix AsyncWebSocket bug
15841599
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)
15851600

@@ -1591,7 +1606,9 @@ Submit issues to: [AsyncWebServer_WT32_ETH01 issues](https://github.com/khoih-pr
15911606
### Contributions and Thanks
15921607

15931608
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)
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`
1609+
2. Thanks to [salasidis](https://github.com/salasidis) aka [rs77can](https://forum.arduino.cc/u/rs77can) to discuss and make the following `marvellous` PRs in [Portenta_H7_AsyncWebServer library](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer)
1610+
- [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.6.0` to support using `CString` in optional `SDRAM` to save heap to send `very large data`
1611+
- [All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11), leading to `v1.6.1` to remove `memmove()` and not to destroy String anymore
15951612

15961613
<table>
15971614
<tr>

0 commit comments

Comments
 (0)