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

Commit b98e97c

Browse files
authored
v1.4.0 to save heap when sending large data
### 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](#8) 2. Add multiple examples to demo the new feature
1 parent bb1a0a2 commit b98e97c

File tree

8 files changed

+256
-95
lines changed

8 files changed

+256
-95
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Arduino IDE version: 1.8.19
3131
`ArduinoCore-mbed` mbed_portenta core v3.3.0
3232
Portenta_H7 Rev2 ABX00042
3333
OS: Ubuntu 20.04 LTS
34-
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
34+
Linux xy-Inspiron-3593 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3535
3636
Context:
3737
I encountered a crash while using this library
@@ -52,3 +52,4 @@ There are usually some outstanding feature requests in the [existing issues list
5252
### Sending Pull Requests
5353

5454
Pull Requests with changes and fixes are also welcome!
55+

README.md

Lines changed: 186 additions & 24 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
## Table of Contents
1212

1313
* [Changelog](#changelog)
14+
* [Releases v1.4.0](#Releases-v140)
1415
* [Releases v1.3.0](#Releases-v130)
1516
* [Releases v1.2.1](#Releases-v121)
1617
* [Releases v1.2.0](#Releases-v120)
@@ -23,6 +24,11 @@
2324

2425
## Changelog
2526

27+
### Releases v1.4.0
28+
29+
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](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8)
30+
2. Add multiple examples to demo the new feature
31+
2632
### Releases v1.3.0
2733

2834
1. 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)

examples/Ethernet/Async_AdvancedWebServer_MemoryIssues_Send_CString/Async_AdvancedWebServer_MemoryIssues_Send_CString.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#endif
4444

4545
#define _PORTENTA_H7_ATCP_LOGLEVEL_ 1
46-
#define _PORTENTA_H7_AWS_LOGLEVEL_ 1
46+
#define _PORTENTA_H7_AWS_LOGLEVEL_ 0
4747

4848
#define USE_ETHERNET_PORTENTA_H7 true
4949

@@ -242,6 +242,9 @@ void setup()
242242
Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION);
243243
Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION);
244244

245+
Serial.print("TCP_MSS = "); Serial.print(TCP_MSS); Serial.print(", TCP_SND_BUF = "); Serial.println(TCP_SND_BUF);
246+
247+
245248
#if USING_CSTRING_IN_SDRAM
246249
SDRAM.begin();
247250

examples/WiFi/Async_AdvancedWebServer/Async_AdvancedWebServer.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/****************************************************************************************************************************
2-
Async_AdvancedWebServer.ino - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet
2+
Async_AdvancedWebServer.ino - Dead simple AsyncWebServer for Portenta_H7
33
4-
For Portenta_H7 (STM32H7) with Vision-Shield Ethernet
4+
For Portenta_H7 (STM32H7) with Portenta_H7 WiFi
55
6-
Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet
6+
Portenta_H7_AsyncWebServer is a library for the Portenta_H7
77
88
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
99
Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer

examples/WiFi/Async_AdvancedWebServer_MemoryIssues_Send_CString/Async_AdvancedWebServer_MemoryIssues_Send_CString.ino

Lines changed: 52 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/****************************************************************************************************************************
22
Async_AdvancedWebServer_MemoryIssues_Send_CString.ino - Dead simple AsyncWebServer for Portenta_H7
3-
4-
For Portenta_H7 (STM32H7) with Vision-Shield Ethernet
53
6-
Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet
4+
For Portenta_H7 (STM32H7) with Portenta_H7 WiFi
5+
6+
Portenta_H7_AsyncWebServer is a library for the Portenta_H7
77
88
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
99
Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer
@@ -45,14 +45,18 @@
4545
#define _PORTENTA_H7_ATCP_LOGLEVEL_ 1
4646
#define _PORTENTA_H7_AWS_LOGLEVEL_ 1
4747

48-
#define USE_ETHERNET_PORTENTA_H7 true
48+
#define USE_WIFI_PORTENTA_H7 true
4949

50-
#include <Portenta_Ethernet.h>
51-
#include <Ethernet.h>
52-
#warning Using Portenta_Ethernet lib for Portenta_H7.
50+
#include <WiFi.h>
51+
#warning Using WiFi for Portenta_H7.
5352

5453
#include <Portenta_H7_AsyncWebServer.h>
5554

55+
char ssid[] = "your_ssid"; // your network SSID (name)
56+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
57+
58+
int status = WL_IDLE_STATUS;
59+
5660
char *cStr;
5761

5862
// In bytes
@@ -65,35 +69,6 @@ char *cStr;
6569
#include "SDRAM.h"
6670
#endif
6771

68-
// Enter a MAC address and IP address for your controller below.
69-
#define NUMBER_OF_MAC 20
70-
71-
byte mac[][NUMBER_OF_MAC] =
72-
{
73-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
74-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
75-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
76-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
77-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
78-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
79-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
80-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
81-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
82-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
83-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
84-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
85-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
86-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
87-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
88-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
89-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
90-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
91-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
92-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
93-
};
94-
// Select the IP address according to your local network
95-
IPAddress ip(192, 168, 2, 232);
96-
9772
AsyncWebServer server(80);
9873

9974
int reqCount = 0; // number of requests received
@@ -116,21 +91,21 @@ void handleRoot(AsyncWebServerRequest *request)
11691
snprintf(temp, BUFFER_SIZE - 1,
11792
"<html>\
11893
<head>\
119-
<meta http-equiv='refresh' content='5'/>\
94+
<meta http-equiv='refresh' content='60'/>\
12095
<title>AsyncWebServer-%s</title>\
12196
<style>\
12297
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
12398
</style>\
12499
</head>\
125100
<body>\
126101
<h2>AsyncWebServer_Portenta_H7!</h2>\
127-
<h3>running on %s</h3>\
102+
<h3>running WiFi on %s</h3>\
128103
<p>Uptime: %d d %02d:%02d:%02d</p>\
129104
<img src=\"/test.svg\" />\
130105
</body>\
131106
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60);
132107

133-
request->send(200, "text/html", temp, false);
108+
request->send(200, "text/html", temp);
134109

135110
digitalWrite(LED_BUILTIN, LED_OFF);
136111
}
@@ -221,6 +196,24 @@ void drawGraph(AsyncWebServerRequest *request)
221196
PrintHeapData("Post Send");
222197
}
223198

199+
void printWifiStatus()
200+
{
201+
// print the SSID of the network you're attached to:
202+
Serial.print("SSID: ");
203+
Serial.println(WiFi.SSID());
204+
205+
// print your board's IP address:
206+
IPAddress ip = WiFi.localIP();
207+
Serial.print("Local IP Address: ");
208+
Serial.println(ip);
209+
210+
// print the received signal strength:
211+
long rssi = WiFi.RSSI();
212+
Serial.print("signal strength (RSSI):");
213+
Serial.print(rssi);
214+
Serial.println(" dBm");
215+
}
216+
224217
void setup()
225218
{
226219
pinMode(LED_BUILTIN, OUTPUT);
@@ -259,35 +252,31 @@ void setup()
259252

260253
///////////////////////////////////
261254

262-
// start the ethernet connection and the server
263-
// Use random mac
264-
uint16_t index = millis() % NUMBER_OF_MAC;
265-
266-
// Use Static IP
267-
//Ethernet.begin(mac[index], ip);
268-
// Use DHCP dynamic IP and random mac
269-
Ethernet.begin(mac[index]);
270-
271-
if (Ethernet.hardwareStatus() == EthernetNoHardware)
255+
// check for the WiFi module:
256+
if (WiFi.status() == WL_NO_MODULE)
272257
{
273-
Serial.println("No Ethernet found. Stay here forever");
274-
275-
while (true)
276-
{
277-
delay(1); // do nothing, no point running without Ethernet hardware
278-
}
258+
Serial.println("Communication with WiFi module failed!");
259+
// don't continue
260+
while (true);
279261
}
280262

281-
if (Ethernet.linkStatus() == LinkOFF)
263+
Serial.print(F("Connecting to SSID: "));
264+
Serial.println(ssid);
265+
266+
status = WiFi.begin(ssid, pass);
267+
268+
delay(1000);
269+
270+
// attempt to connect to WiFi network
271+
while ( status != WL_CONNECTED)
282272
{
283-
Serial.println("Not connected Ethernet cable");
273+
delay(500);
274+
275+
// Connect to WPA/WPA2 network
276+
status = WiFi.status();
284277
}
285278

286-
Serial.print(F("Using mac index = "));
287-
Serial.println(index);
288-
289-
Serial.print(F("Connected! IP address: "));
290-
Serial.println(Ethernet.localIP());
279+
printWifiStatus();
291280

292281
///////////////////////////////////
293282

@@ -311,7 +300,7 @@ void setup()
311300
server.begin();
312301

313302
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
314-
Serial.println(Ethernet.localIP());
303+
Serial.println(WiFi.localIP());
315304

316305
PrintHeapData("Pre Create Arduino String");
317306

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "Portenta_H7_AsyncWebServer",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"keywords": "http, async, websocket, webserver, async-webserver, async-tcp, async-udp, async-websocket, async-http, ssl, tls, mbed, mbed-portenta, portenta-h7, portentah7, portenta-h7-m7, portenta-h7-m4, portentah7-m7, portentah7-m4, stm32h7",
5-
"description": "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.",
5+
"description": "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",
66
"authors":
77
[
88
{

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version=1.3.0
33
author=Hristo Gochkov,Khoi Hoang
44
maintainer=Khoi Hoang <khoih.prog@gmail.com>
55
sentence=Asynchronous WebServer Library for STM32H7-based Portenta_H7 using mbed_portenta core.
6-
paragraph=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.
6+
paragraph=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
77
category=Communication
88
url=https://github.com/khoih-prog/Portenta_H7_AsyncWebServer
99
architectures=mbed,mbed_portenta,ArduinoCore-mbed

0 commit comments

Comments
 (0)