Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit205495a

Browse files
Remove 400b stack allocation from AdvWeb example
The AdvancedWebServer.ino example allocated a 400 byte char array on thestack which, in the case of the example, will work but in general is adangerous thing to show new users to try.Instead, use a StreamString to generate the string on the heap.
1 parenta76852a commit205495a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎libraries/ESP8266WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include<WiFiClient.h>
3333
#include<ESP8266WebServer.h>
3434
#include<ESP8266mDNS.h>
35+
#include<StreamString.h>
3536

3637
#ifndef STASSID
3738
#defineSTASSID"your-ssid"
@@ -47,14 +48,14 @@ const int led = 13;
4748

4849
voidhandleRoot() {
4950
digitalWrite(led,1);
50-
char temp[400];
5151
int sec =millis() /1000;
5252
int min = sec /60;
5353
int hr = min /60;
5454

55-
snprintf(temp,400,
56-
57-
"<html>\
55+
StreamString temp;
56+
temp.reserve(500);// Preallocate a large chunk to avoid memory fragmentation
57+
temp.printf("\
58+
<html>\
5859
<head>\
5960
<meta http-equiv='refresh' content='5'/>\
6061
<title>ESP8266 Demo</title>\
@@ -68,9 +69,8 @@ void handleRoot() {
6869
<img src=\"/test.svg\" />\
6970
</body>\
7071
</html>",
71-
72-
hr, min %60, sec %60);
73-
server.send(200,"text/html", temp);
72+
hr, min %60, sec %60);
73+
server.send(200,"text/html", temp.c_str());
7474
digitalWrite(led,0);
7575
}
7676

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp