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

Commit c9d6805

Browse files
authored
v1.4.2 to add demo sending in chunks
### Releases v1.4.2 1. Add examples [Async_AdvancedWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/Async_AdvancedWebServer_SendChunked) and [AsyncWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/AsyncWebServer_SendChunked) to demo how to use `beginChunkedResponse()` to send large `html` in chunks 2. Use `allman astyle` and add `utils` 3. Update `Packages_Patches`
1 parent 6dec28d commit c9d6805

File tree

72 files changed

+5812
-4386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+5812
-4386
lines changed

CONTRIBUTING.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.3.0)
18+
* `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.4.1)
1919
* `Portenta_H7` Board type (e.g. Portenta_H7 Rev2 ABX00042, etc.)
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
@@ -28,28 +28,51 @@ Please ensure to specify the following:
2828

2929
```
3030
Arduino IDE version: 1.8.19
31-
`ArduinoCore-mbed` mbed_portenta core v3.3.0
31+
`ArduinoCore-mbed` mbed_portenta core v3.4.1
3232
Portenta_H7 Rev2 ABX00042
3333
OS: Ubuntu 20.04 LTS
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
34+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3535
3636
Context:
3737
I encountered a crash while using this library
38-
3938
Steps to reproduce:
4039
1. ...
4140
2. ...
4241
3. ...
4342
4. ...
4443
```
4544

45+
### Additional context
46+
47+
Add any other context about the problem here.
48+
49+
---
50+
4651
### Sending Feature Requests
4752

4853
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4954

5055
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
5156

57+
---
58+
5259
### Sending Pull Requests
5360

5461
Pull Requests with changes and fixes are also welcome!
5562

63+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
64+
65+
1. Change directory to the library GitHub
66+
67+
```
68+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/Portenta_H7_AsyncWebServer_GitHub/
69+
xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$
70+
```
71+
72+
2. Issue astyle command
73+
74+
```
75+
xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$ bash utils/restyle.sh
76+
```
77+
78+

changelog.md

+12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
66
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/Portenta_H7_AsyncWebServer.svg)](http://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues)
77

8+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
9+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
10+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
11+
<a href="https://profile-counter.glitch.me/khoih-prog-Portenta_H7_AsyncWebServer/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-Portenta_H7_AsyncWebServer/count.svg" style="height: 30px;width: 200px;"></a>
12+
813
---
914
---
1015

1116
## Table of Contents
1217

1318
* [Changelog](#changelog)
19+
* [Releases v1.4.2](#Releases-v142)
1420
* [Releases v1.4.1](#Releases-v141)
1521
* [Releases v1.4.0](#Releases-v140)
1622
* [Releases v1.3.0](#Releases-v130)
@@ -25,6 +31,12 @@
2531

2632
## Changelog
2733

34+
### Releases v1.4.2
35+
36+
1. Add examples [Async_AdvancedWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/Async_AdvancedWebServer_SendChunked) and [AsyncWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/AsyncWebServer_SendChunked) to demo how to use `beginChunkedResponse()` to send large `html` in chunks
37+
2. Use `allman astyle` and add `utils`
38+
3. Update `Packages_Patches`
39+
2840
### Releases v1.4.1
2941

3042
1. Don't need `memmove()`, CString no longer destroyed. Check [All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
/****************************************************************************************************************************
2+
AsyncWebServer_SendChunked.ino
3+
4+
For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi
5+
6+
Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi
7+
8+
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
9+
Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer
10+
Licensed under GPLv3 license
11+
*****************************************************************************************************************************/
12+
13+
#if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) )
14+
#error For Portenta_H7 only
15+
#endif
16+
17+
#define _PORTENTA_H7_ATCP_LOGLEVEL_ 1
18+
#define _PORTENTA_H7_AWS_LOGLEVEL_ 4
19+
20+
#define USE_ETHERNET_PORTENTA_H7 true
21+
22+
#include <Portenta_Ethernet.h>
23+
#include <Ethernet.h>
24+
#warning Using Portenta_Ethernet lib for Portenta_H7.
25+
26+
#include <Portenta_H7_AsyncWebServer.h>
27+
28+
// In bytes
29+
#define STRING_SIZE 50000
30+
31+
// Enter a MAC address and IP address for your controller below.
32+
#define NUMBER_OF_MAC 20
33+
34+
byte mac[][NUMBER_OF_MAC] =
35+
{
36+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
37+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
38+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
39+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
40+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
41+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
42+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
43+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
44+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
45+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
46+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
47+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
48+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
49+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
50+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
51+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
52+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
53+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
54+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
55+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
56+
};
57+
// Select the IP address according to your local network
58+
IPAddress ip(192, 168, 2, 232);
59+
60+
AsyncWebServer server(80);
61+
62+
int reqCount = 0; // number of requests received
63+
64+
#define BUFFER_SIZE 512
65+
char temp[BUFFER_SIZE];
66+
67+
void createPage(String &pageInput)
68+
{
69+
int sec = millis() / 1000;
70+
int min = sec / 60;
71+
int hr = min / 60;
72+
int day = hr / 24;
73+
74+
snprintf(temp, BUFFER_SIZE - 1,
75+
"<html>\
76+
<head>\
77+
<meta http-equiv='refresh' content='5'/>\
78+
<title>AsyncWebServer-%s</title>\
79+
<style>\
80+
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
81+
</style>\
82+
</head>\
83+
<body>\
84+
<h2>AsyncWebServer_SendChunked_Portenta_H7!</h2>\
85+
<h3>running on %s</h3>\
86+
<p>Uptime: %d d %02d:%02d:%02d</p>\
87+
</body>\
88+
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60);
89+
90+
pageInput = temp;
91+
}
92+
93+
void handleNotFound(AsyncWebServerRequest *request)
94+
{
95+
String message = "File Not Found\n\n";
96+
97+
message += "URI: ";
98+
message += request->url();
99+
message += "\nMethod: ";
100+
message += (request->method() == HTTP_GET) ? "GET" : "POST";
101+
message += "\nArguments: ";
102+
message += request->args();
103+
message += "\n";
104+
105+
for (uint8_t i = 0; i < request->args(); i++)
106+
{
107+
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
108+
}
109+
110+
request->send(404, "text/plain", message);
111+
}
112+
113+
String out;
114+
115+
void handleRoot(AsyncWebServerRequest *request)
116+
{
117+
char temp[70];
118+
119+
// clear the String to start over
120+
out = String();
121+
122+
createPage(out);
123+
124+
out += "<html><body>\r\n<table><tr><th>INDEX</th><th>DATA</th></tr>";
125+
126+
for (uint16_t lineIndex = 0; lineIndex < 500; lineIndex++)
127+
{
128+
out += "<tr><td>";
129+
out += String(lineIndex);
130+
out += "</td><td>";
131+
out += "Portenta_H7_AsyncWebServer_SendChunked_ABCDEFGHIJKLMNOPQRSTUVWXYZ</td></tr>";
132+
}
133+
134+
out += "</table></body></html>\r\n";
135+
136+
AWS_LOGDEBUG1("Total length to send in chunks =", out.length());
137+
138+
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", [](uint8_t *buffer, size_t maxLen, size_t filledLength) -> size_t
139+
{
140+
size_t len = min(maxLen, out.length() - filledLength);
141+
memcpy(buffer, out.c_str() + filledLength, len);
142+
143+
AWS_LOGDEBUG1("Bytes sent in chunk =", len);
144+
145+
return len;
146+
});
147+
148+
request->send(response);
149+
}
150+
151+
void setup()
152+
{
153+
out.reserve(STRING_SIZE);
154+
155+
Serial.begin(115200);
156+
157+
while (!Serial && millis() < 5000);
158+
159+
delay(200);
160+
161+
Serial.print("\nStart AsyncWebServer_SendChunked on ");
162+
Serial.print(BOARD_NAME);
163+
Serial.print(" with ");
164+
Serial.println(SHIELD_TYPE);
165+
Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION);
166+
Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION);
167+
168+
///////////////////////////////////
169+
170+
// start the ethernet connection and the server
171+
// Use random mac
172+
uint16_t index = millis() % NUMBER_OF_MAC;
173+
174+
// Use Static IP
175+
//Ethernet.begin(mac[index], ip);
176+
// Use DHCP dynamic IP and random mac
177+
Ethernet.begin(mac[index]);
178+
179+
if (Ethernet.hardwareStatus() == EthernetNoHardware)
180+
{
181+
Serial.println("No Ethernet found. Stay here forever");
182+
183+
while (true)
184+
{
185+
delay(1); // do nothing, no point running without Ethernet hardware
186+
}
187+
}
188+
189+
if (Ethernet.linkStatus() == LinkOFF)
190+
{
191+
Serial.println("Not connected Ethernet cable");
192+
}
193+
194+
Serial.print(F("Using mac index = "));
195+
Serial.println(index);
196+
197+
Serial.print(F("Connected! IP address: "));
198+
Serial.println(Ethernet.localIP());
199+
200+
///////////////////////////////////
201+
202+
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
203+
{
204+
handleRoot(request);
205+
});
206+
207+
server.on("/inline", [](AsyncWebServerRequest * request)
208+
{
209+
request->send(200, "text/plain", "This works as well");
210+
});
211+
212+
server.onNotFound(handleNotFound);
213+
214+
server.begin();
215+
216+
Serial.print(F("AsyncWebServer is @ IP : "));
217+
Serial.println(Ethernet.localIP());
218+
}
219+
220+
void heartBeatPrint()
221+
{
222+
static int num = 1;
223+
224+
Serial.print(F("."));
225+
226+
if (num == 80)
227+
{
228+
Serial.println();
229+
num = 1;
230+
}
231+
else if (num++ % 10 == 0)
232+
{
233+
Serial.print(F(" "));
234+
}
235+
}
236+
237+
void check_status()
238+
{
239+
static unsigned long checkstatus_timeout = 0;
240+
241+
#define STATUS_CHECK_INTERVAL 10000L
242+
243+
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
244+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
245+
{
246+
heartBeatPrint();
247+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
248+
}
249+
}
250+
251+
void loop()
252+
{
253+
check_status();
254+
}

0 commit comments

Comments
 (0)