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

Commit cf3a8b7

Browse files
authored
v1.3.1 to fix String-related bug
### Releases v1.3.1 1. Fix bug related to String in examples
1 parent 8d70093 commit cf3a8b7

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void handleRoot()
5858
{
5959
digitalWrite(led, 1);
6060

61-
#define BUFFER_SIZE 400
61+
#define BUFFER_SIZE 512
6262

6363
char temp[BUFFER_SIZE];
6464
int sec = millis() / 1000;
@@ -111,21 +111,25 @@ void handleNotFound()
111111
digitalWrite(led, 0);
112112
}
113113

114-
#if (defined(ETHERNET_WEBSERVER_STM32_VERSION_INT) && (ETHERNET_WEBSERVER_STM32_VERSION_INT >= 1003000))
115-
116-
EWString initHeader = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
117-
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
118-
"<g stroke=\"blue\">\n";
114+
#define ORIGINAL_STR_LEN 2048
119115

120116
void drawGraph()
121117
{
122-
EWString out;
123-
124-
out.reserve(3000);
118+
static String out;
119+
static uint16_t previousStrLen = ORIGINAL_STR_LEN;
120+
121+
if (out.length() == 0)
122+
{
123+
ET_LOGWARN1(F("String Len = 0, extend to"), ORIGINAL_STR_LEN);
124+
out.reserve(ORIGINAL_STR_LEN);
125+
}
126+
127+
out = F( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
128+
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
129+
"<g stroke=\"blue\">\n");
130+
125131
char temp[70];
126132

127-
out += initHeader;
128-
129133
int y = rand() % 130;
130134

131135
for (int x = 10; x < 300; x += 10)
@@ -135,37 +139,25 @@ void drawGraph()
135139
out += temp;
136140
y = y2;
137141
}
138-
out += "</g>\n</svg>\n";
139-
140-
server.send(200, "image/svg+xml", fromEWString(out));
141-
}
142+
143+
out += F("</g>\n</svg>\n");
142144

143-
#else
145+
ET_LOGDEBUG1(F("String Len = "), out.length());
144146

145-
void drawGraph()
146-
{
147-
String out;
148-
out.reserve(3000);
149-
char temp[70];
150-
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n";
151-
out += "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";
152-
out += "<g stroke=\"black\">\n";
153-
int y = rand() % 130;
147+
if (out.length() > previousStrLen)
148+
{
149+
ET_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
154150

155-
for (int x = 10; x < 300; x += 10)
151+
previousStrLen = out.length() + 48;
152+
153+
out.reserve(previousStrLen);
154+
}
155+
else
156156
{
157-
int y2 = rand() % 130;
158-
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2);
159-
out += temp;
160-
y = y2;
157+
server.send(200, "image/svg+xml", out);
161158
}
162-
out += "</g>\n</svg>\n";
163-
164-
server.send(200, "image/svg+xml", out);
165159
}
166160

167-
#endif
168-
169161
void setup()
170162
{
171163
pinMode(led, OUTPUT);

examples/WebServer/WebServer.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ void loop()
106106
"\r\n");
107107
client.print("<!DOCTYPE HTML>\r\n");
108108
client.print("<html>\r\n");
109-
client.print(String("<h1>Hello World from ") + BOARD_NAME + "!</h1>\r\n");
109+
client.print("<h1>Hello World from ");
110+
client.print(BOARD_NAME);
111+
client.print("!</h1>\r\n");
110112
client.print("Requests received: ");
111113
client.print(++reqCount);
112114
client.print("<br>\r\n");

0 commit comments

Comments
 (0)