khoih-prog / Portenta_H7_AsyncWebServer

Asynchronous WebServer Library for STM32H7-based Portenta_H7 using mbed_portenta core. This library, which is relied on Portenta_H7_AsyncTCP, is part of a series of advanced Async libraries, such as AsyncTCP, AsyncUDP, AsyncWebSockets, AsyncHTTPRequest, AsyncHTTPSRequest, etc. Now supporting using CString in optional SDRAM to save heap to send very large data
GNU Lesser General Public License v3.0
12 stars 3 forks source link

request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8

Closed salasidis closed 1 year ago

salasidis commented 1 year ago

Do not update src files, as they do not include khoih changes already made

khoih-prog commented 1 year ago

Can you also update the src files to your repo, then make the PR again to reduce the number of PRs?

khoih-prog commented 1 year ago

Also merge to the RSMOD branch first to test. Then will merge to the main branch after everything is OK.

salasidis commented 1 year ago

Don't know how to resolve the conflicts - it says has conflicts, and use command line to resolve. I need to merge your changes first, and then will d a new pull request, and the example files should be the only thing different

khoih-prog commented 1 year ago

It's very good now. I'll scan thru and merge soon.

salasidis commented 1 year ago

I guess I don't have to confirm a pull request - I thought I hadn't completed it.

Thanks for the walkthrough - I was missing having to download the files locally, and then upload them into my repository. There were actually no conflicts after doing that.

khoih-prog commented 1 year ago

The new examples somehow don't auto-refresh the graph. Can you check why with the new code ?

salasidis commented 1 year ago

I specifically eliminated the auto refresh, by removing the meta tag on the web html. Just to make the output cleaner - single pass. Can manually refresh if required.

khoih-prog commented 1 year ago

To demo the larger graph, also change the examples to

  strcat(cStr, "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1810\" height=\"150\">\n");
  strcat(cStr, "<rect width=\"1810\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"2\" stroke=\"rgb(0, 0, 0)\" />\n");

from

  strcat(cStr, "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n");
  strcat(cStr, "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"2\" stroke=\"rgb(0, 0, 0)\" />\n");

Selection_096

khoih-prog commented 1 year ago

OK, I still prefer put it back to demo the HEAP is still very good after many times running

<meta http-equiv='refresh' content='5'/>\
khoih-prog commented 1 year ago

So far so good. Everybody will love your new powerful enhancement.

Will certainly spread to many other Async libraries, at least mine.

khoih-prog commented 1 year ago

Merging now. Will create a new version soon after some minor changes and enhancements (favicon example, etc.)

If you have time, please create similar powerful PRs for many other AsyncWebserver libraries of mine.

Best Regards,

salasidis commented 1 year ago

I unfortunately have no other boards to run or test on, but if I need to use another lower cost board, I will be sure to port this to it as well (presumably the source is very similar between all of them).

One important thing to note however, without the memory mapped SDRAM, other boards would only get half the benefit, as the initial string will have to reside in the regular heap space. So in the second example (with the C string), I think the heap required would be in the order of 50k-60k instead of 12k (but still better than 111k)

khoih-prog commented 1 year ago

One important thing to note however, without the memory mapped SDRAM, other boards would only get half the benefit, as the initial string will have to reside in the regular heap space. So in the second example (with the C string), I think the heap required would be in the order of 50k-60k instead of 12k (but still better than 111k)

Certainly, everybody must know this, at least not 2x or 3x like before

I unfortunately have no other boards to run or test on, but if I need to use another lower cost board, I will be sure to port this to it as well (presumably the source is very similar between all of them).

You can start with very cheap boards, such as (according to priority : power, cost, popularity, availability, etc.)

khoih-prog commented 1 year ago

So far so good

image


Async_AdvancedWebServer_MemoryIssues_Send_CString ===> Using SDRAM, very small heap (12847).

Start Async_AdvancedWebServer_MemoryIssues_Send_CString on PORTENTA_H7_M7 with Ethernet using Portenta_Ethernet Library
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncWebServer v1.3.0
Using mac index = 18
Connected! IP address: 192.168.2.123
HTTP EthernetWebServer is @ IP : 192.168.2.123
HEAP DATA - Pre Create Arduino String  Cur heap: 8458  Res Size: 451680  Max heap: 8472
.HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 10196
Out String Length=31259
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31279
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
.HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31231
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
.HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31239
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31259
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
.HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31249
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
HEAP DATA - Pre Send  Cur heap: 9634  Res Size: 451680  Max heap: 12847
Out String Length=31200
HEAP DATA - Post Send  Cur heap: 9734  Res Size: 451680  Max heap: 12847
.

Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (111387)

Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on PORTENTA_H7_M7 with Ethernet using Portenta_Ethernet Library
Portenta_H7_AsyncTCP v1.4.0
Portenta_H7_AsyncWebServer v1.3.0
Using mac index = 15
Connected! IP address: 192.168.2.123
HTTP EthernetWebServer is @ IP : 192.168.2.123
HEAP DATA - Pre Create Arduino String  Cur heap: 7434  Res Size: 452048  Max heap: 7448
.HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 48611
Out String Length=31259
HEAP DATA - Post Send  Cur heap: 79009  Res Size: 452048  Max heap: 111347
.HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 111347
Out String Length=31279
HEAP DATA - Post Send  Cur heap: 79029  Res Size: 452048  Max heap: 111387
HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 111387
Out String Length=31231
HEAP DATA - Post Send  Cur heap: 78981  Res Size: 452048  Max heap: 111387
.HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 111387
Out String Length=31239
HEAP DATA - Post Send  Cur heap: 78989  Res Size: 452048  Max heap: 111387
HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 111387
Out String Length=31259
HEAP DATA - Post Send  Cur heap: 79009  Res Size: 452048  Max heap: 111387
.HEAP DATA - Pre Send  Cur heap: 48611  Res Size: 452048  Max heap: 111387
Out String Length=31249
HEAP DATA - Post Send  Cur heap: 78999  Res Size: 452048  Max heap: 111387
khoih-prog commented 1 year ago

Can you, if having time, make a new example using CString, but not in SDRAM. This will be used in many other boards without SDRAM access.

salasidis commented 1 year ago

Can do - will be going out to dinner soon, so I will do it later today, or tomorrow

khoih-prog commented 1 year ago

No worry, I have to go too.

khoih-prog commented 1 year ago

Hi @salasidis

The new Portenta_H7_AsyncWebServer v1.4.0 has just been published. Your contribution is noted in Contributions and Thanks

Also check Important Note from v1.4.0


Releases v1.4.0

  1. Support using CString in optional SDRAM to save heap to send very large data. Check request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8
  2. Add multiple examples to demo the new feature

Selection_099