You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+57-42Lines changed: 57 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,55 +116,72 @@
116
116
117
117
### Important Note from v1.2.0
118
118
119
-
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
+
The new `v1.2.0+` has added a new and powerful feature to permit using `CString` to save heap to send `very large data`.
120
120
121
-
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
+
Check the `marvelleous` PRs of **@salasidis** in [Portenta_H7_AsyncWebServer library](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer)
122
+
-[request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8)
123
+
-[All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11)
The required HEAP is also about **2 times of the CString size**
167
+
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.
168
+
155
169
170
+
3. To use `CString` without copying while sending. Use function
156
171
157
-
3. To use `CString` but destroy it after sending. Use function
The required HEAP is also about **1 times of the CString size**.
184
+
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
168
185
169
186
170
187
@@ -214,7 +231,7 @@ to apply the better and faster **asynchronous** feature of the **powerful** [ESP
214
231
## Prerequisites
215
232
216
233
1.[`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [](https://github.com/arduino/Arduino/releases/latest)
217
-
2. [`Earle Philhower's arduino-pico core v2.5.4+`](https://github.com/earlephilhower/arduino-pico) for **RASPBERRY_PI_PICO_W with CYW43439 WiFi**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
234
+
2.[`Earle Philhower's arduino-pico core v2.6.0+`](https://github.com/earlephilhower/arduino-pico) for **RASPBERRY_PI_PICO_W with CYW43439 WiFi**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
218
235
3.[`AsyncTCP_RP2040W library v1.1.0+`](https://github.com/khoih-prog/AsyncTCP_RP2040W) for RASPBERRY_PI_PICO_W with CYW43439 WiFi. [](https://github.com/khoih-prog/AsyncTCP_RP2040W/releases/latest)
219
236
220
237
---
@@ -245,7 +262,7 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncW
245
262
## Important things to remember
246
263
247
264
- This is fully asynchronous server and as such does not run on the loop thread.
248
-
- You can not use yield() or delay() or any function that uses them inside the callbacks
265
+
- You can not use `yield()` or `delay()` or any function that uses them inside the callbacks
249
266
- The server is smart enough to know when to close the connection and free resources
250
267
- You can not send more than one response to a single request
When sending a web socket message using the above methods a buffer is created. Under certain circumstances you might want to manipulate or populate this buffer directly from your application, for example to prevent unnecessary duplications of the data. This example below shows how to create a buffer and print data to it from an ArduinoJson object then send it.
1031
+
When sending a `websocket` message using the above methods a buffer is created. Under certain circumstances you might want to manipulate or populate this buffer directly from your application, for example to prevent unnecessary duplications of the data. This example below shows how to create a buffer and print data to it from an `ArduinoJson` object then send it.
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.
1064
+
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.
1048
1065
1049
1066
```cpp
1050
1067
voidloop(){
@@ -1056,8 +1073,8 @@ void loop(){
1056
1073
1057
1074
## Async Event Source Plugin
1058
1075
1059
-
The server includes EventSource (Server-Sent Events) plugin which can be used to send short text events to the browser.
1060
-
Difference between EventSource and WebSockets is that EventSource is single direction, text-only protocol.
1076
+
The server includes `EventSource` (Server-Sent Events) plugin which can be used to send short text events to the browser.
1077
+
Difference between `EventSource` and `WebSockets` is that `EventSource` is single direction, text-only protocol.
1061
1078
1062
1079
### Setup Event Source on the server
1063
1080
@@ -1408,9 +1425,9 @@ void loop()
1408
1425
1409
1426
### Adding Default Headers
1410
1427
1411
-
In some cases, such as when working with CORS, or with some sort of custom authentication system,
1428
+
In some cases, such as when working with `CORS`, or with some sort of custom authentication system,
1412
1429
you might need to define a header that should get added to all responses (including static, websocket and EventSource).
1413
-
The DefaultHeaders singleton allows you to do this.
1430
+
The `DefaultHeaders` singleton allows you to do this.
1414
1431
1415
1432
Example:
1416
1433
@@ -1517,7 +1534,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer](e
1517
1534
```
1518
1535
Start Async_AdvancedWebServer on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1519
1536
AsyncTCP_RP2040W v1.1.0
1520
-
AsyncWebServer_RP2040W v1.2.0
1537
+
AsyncWebServer_RP2040W v1.2.1
1521
1538
Connecting to SSID: HueNet1
1522
1539
SSID: HueNet1
1523
1540
Local IP Address: 192.168.2.180
@@ -1541,7 +1558,7 @@ Following is debug terminal output when running example [WebClient](examples/Web
1541
1558
```
1542
1559
Start WebClient on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1543
1560
AsyncTCP_RP2040W v1.1.0
1544
-
AsyncWebServer_RP2040W v1.2.0
1561
+
AsyncWebServer_RP2040W v1.2.1
1545
1562
Connecting to SSID: HueNet1
1546
1563
SSID: HueNet1
1547
1564
Local IP Address: 192.168.2.180
@@ -1619,7 +1636,7 @@ Following is debug terminal output when running example [MQTTClient_Auth](exampl
1619
1636
```
1620
1637
Start MQTTClient_Auth on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1621
1638
AsyncTCP_RP2040W v1.1.0
1622
-
AsyncWebServer_RP2040W v1.2.0
1639
+
AsyncWebServer_RP2040W v1.2.1
1623
1640
Connecting to SSID: HueNet1
1624
1641
SSID: HueNet1
1625
1642
Local IP Address: 192.168.2.180
@@ -1641,7 +1658,7 @@ Following is debug terminal output when running example [MQTTClient_Basic](examp
1641
1658
```
1642
1659
Start MQTTClient_Basic on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1643
1660
AsyncTCP_RP2040W v1.1.0
1644
-
AsyncWebServer_RP2040W v1.2.0
1661
+
AsyncWebServer_RP2040W v1.2.1
1645
1662
Connecting to SSID: HueNet1
1646
1663
SSID: HueNet1
1647
1664
Local IP Address: 192.168.2.180
@@ -1663,7 +1680,7 @@ Following is debug terminal output when running example [MQTT_ThingStream](examp
1663
1680
```
1664
1681
Start MQTT_ThingStream on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1665
1682
AsyncTCP_RP2040W v1.1.0
1666
-
AsyncWebServer_RP2040W v1.2.0
1683
+
AsyncWebServer_RP2040W v1.2.1
1667
1684
Connecting to SSID: HueNet1
1668
1685
SSID: HueNet1
1669
1686
Local IP Address: 192.168.2.180
@@ -1691,7 +1708,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer_Co
1691
1708
```
1692
1709
Start Async_AdvancedWebServer_Country on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1693
1710
AsyncTCP_RP2040W v1.1.0
1694
-
AsyncWebServer_RP2040W v1.2.0
1711
+
AsyncWebServer_RP2040W v1.2.1
1695
1712
Connecting to SSID: HueNet1
1696
1713
SSID: HueNet1
1697
1714
Local IP Address: 192.168.2.180
@@ -1727,7 +1744,7 @@ Following is the debug terminal when running example [Async_AdvancedWebServer_fa
1727
1744
```
1728
1745
14:22:06.632 -> Start Async_AdvancedWebServer_favicon on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1729
1746
14:22:06.632 -> AsyncTCP_RP2040W v1.1.0
1730
-
14:22:06.632 -> AsyncWebServer_RP2040W v1.2.0
1747
+
14:22:06.632 -> AsyncWebServer_RP2040W v1.2.1
1731
1748
14:22:06.632 -> Connecting to SSID: HueNet1
1732
1749
14:22:13.328 -> SSID: HueNet1
1733
1750
14:22:13.328 -> Local IP Address: 192.168.2.180
@@ -1759,27 +1776,25 @@ You can see the `favicon.ico` at the upper left corner
1759
1776
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
1760
1777
1761
1778
1762
-
##### Using CString ===> small heap (43,976 bytes)
1779
+
##### Using CString ===> small heap (44,000 bytes)
1763
1780
1764
1781
```
1765
1782
Start Async_AdvancedWebServer_MemoryIssues_Send_CString on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1766
1783
AsyncTCP_RP2040W v1.1.0
1767
-
AsyncWebServer_RP2040W v1.2.0
1784
+
AsyncWebServer_RP2040W v1.2.1
1768
1785
Connecting to SSID: HueNet1
1769
1786
SSID: HueNet1
1770
1787
Local IP Address: 192.168.2.74
1771
1788
Country code: XX
1772
1789
HTTP EthernetWebServer is @ IP : 192.168.2.74
1773
1790
1774
1791
HEAP DATA - Pre Create Arduino String Cur heap: 193000 Free heap: 150928 Max heap: 42072
1775
-
..
1792
+
.75264
1776
1793
HEAP DATA - Pre Send Cur heap: 193000 Free heap: 149176 Max heap: 43824
1777
1794
1778
-
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149048 Max heap: 43952
1779
-
1780
-
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149032 Max heap: 43968
1781
-
........ .
1782
-
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149024 Max heap: 43976
1795
+
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149016 Max heap: 43984
1796
+
.
1797
+
HEAP DATA - Post Send Cur heap: 193000 Free heap: 149000 Max heap: 44000
1783
1798
.......... .......... .......... ........
1784
1799
Out String Length=31247
1785
1800
.. .......... .......... .......... ..........
@@ -1788,12 +1803,12 @@ Out String Length=31247
1788
1803
While using Arduino String, the HEAP usage is very large
1789
1804
1790
1805
1791
-
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (75,240 bytes)
1806
+
#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (75,264 bytes)
1792
1807
1793
1808
```
1794
1809
Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on RASPBERRY_PI_PICO_W with RP2040W CYW43439 WiFi
1795
1810
AsyncTCP_RP2040W v1.1.0
1796
-
AsyncWebServer_RP2040W v1.2.0
1811
+
AsyncWebServer_RP2040W v1.2.1
1797
1812
Connecting to SSID: HueNet1
1798
1813
SSID: HueNet1
1799
1814
Local IP Address: 192.168.2.74
@@ -1804,11 +1819,9 @@ HEAP DATA - Pre Create Arduino String Cur heap: 193256 Free heap: 191192 Max
1804
1819
.
1805
1820
HEAP DATA - Pre Send Cur heap: 193256 Free heap: 149432 Max heap: 43824
1806
1821
1807
-
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118056 Max heap: 75200
1808
-
......
1809
1822
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118024 Max heap: 75232
1810
-
... .......... .......... .......... ...
1811
-
HEAP DATA - Post Send Cur heap: 193256 Free heap: 118016 Max heap: 75240
1823
+
1824
+
HEAP DATA - Post Send Cur heap: 193256 Free heap: 117992 Max heap: 75264
1812
1825
....... .......... .......... ..........
1813
1826
.......... .......... .......... ........
1814
1827
Out String Length=31247
@@ -1875,7 +1888,9 @@ Submit issues to: [AsyncWebServer_RP2040W issues](https://github.com/khoih-prog/
1875
1888
2. Thanks to [revell1](https://github.com/revell1) to
1876
1889
- 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
1877
1890
- 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
1878
-
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`
1891
+
3. 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)
1892
+
-[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`
1893
+
-[All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11), leading to `v1.2.1` to remove `memmove()` and not to destroy String anymore
0 commit comments