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

Commit f02de3b

Browse files
authored
v1.5.1 to fix String-related bug
### Releases v1.5.1 1. Fix bug related to String in library and examples
1 parent 3f26bb0 commit f02de3b

File tree

15 files changed

+434
-343
lines changed

15 files changed

+434
-343
lines changed

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const int led = 13;
7070

7171
void handleRoot()
7272
{
73-
#define BUFFER_SIZE 500
73+
#define BUFFER_SIZE 512
7474

7575
digitalWrite(led, 1);
7676
char temp[BUFFER_SIZE];
@@ -127,22 +127,27 @@ void handleNotFound()
127127
digitalWrite(led, 0);
128128
}
129129

130-
#if (defined(ESP8266_AT_WEBSERVER_VERSION_INT) && (ESP8266_AT_WEBSERVER_VERSION_INT >= 1005000) && !ESP_AT_USE_AVR)
131-
#warning Using EWString
130+
#if 1
132131

133-
EWString initHeader = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
134-
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
135-
"<g stroke=\"blue\">\n";
132+
#define ORIGINAL_STR_LEN 2048
136133

137134
void drawGraph()
138135
{
139-
EWString out;
140-
141-
out.reserve(3000);
136+
static String out;
137+
static uint16_t previousStrLen = ORIGINAL_STR_LEN;
138+
139+
if (out.length() == 0)
140+
{
141+
AT_LOGWARN1(F("String Len = 0, extend to"), ORIGINAL_STR_LEN);
142+
out.reserve(ORIGINAL_STR_LEN);
143+
}
144+
145+
out = F( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
146+
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
147+
"<g stroke=\"blue\">\n");
148+
142149
char temp[70];
143150

144-
out += initHeader;
145-
146151
int y = rand() % 130;
147152

148153
for (int x = 10; x < 300; x += 10)
@@ -152,33 +157,72 @@ void drawGraph()
152157
out += temp;
153158
y = y2;
154159
}
155-
out += "</g>\n</svg>\n";
160+
161+
out += F("</g>\n</svg>\n");
156162

157-
server.send(200, "image/svg+xml", fromEWString(out));
163+
AT_LOGDEBUG1(F("String Len = "), out.length());
164+
165+
if (out.length() > previousStrLen)
166+
{
167+
AT_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
168+
169+
previousStrLen = out.length() + 48;
170+
171+
out.reserve(previousStrLen);
172+
}
173+
else
174+
{
175+
server.send(200, "image/svg+xml", out);
176+
}
158177
}
159178

160179
#else
161180
181+
#define ORIGINAL_STR_LEN 1280
182+
162183
void drawGraph()
163184
{
164-
String out;
165-
out.reserve(3000);
185+
static String out;
186+
static uint16_t previousStrLen = ORIGINAL_STR_LEN;
187+
188+
if (out.length() == 0)
189+
{
190+
AT_LOGWARN1(F("String Len = 0, extend to"), ORIGINAL_STR_LEN);
191+
out.reserve(ORIGINAL_STR_LEN);
192+
}
193+
194+
out = F( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"160\" height=\"80\">\n" \
195+
"<rect width=\"1600\" height=\"800\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
196+
"<g stroke=\"blue\">\n");
197+
166198
char temp[70];
167-
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n";
168-
out += "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n";
169-
out += "<g stroke=\"black\">\n";
170-
int y = rand() % 130;
199+
200+
int y = rand() % 60;
171201
172-
for (int x = 10; x < 300; x += 10)
202+
for (int x = 10; x < 150; x += 10)
173203
{
174-
int y2 = rand() % 130;
175-
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
204+
int y2 = rand() % 60;
205+
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 70 - y, x + 10, 70 - y2);
176206
out += temp;
177207
y = y2;
178208
}
179-
out += "</g>\n</svg>\n";
209+
210+
out += F("</g>\n</svg>\n");
211+
212+
AT_LOGDEBUG1(F("String Len = "), out.length());
213+
214+
if (out.length() > previousStrLen)
215+
{
216+
AT_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
180217
181-
server.send(200, "image/svg+xml", out);
218+
previousStrLen = out.length() + 48;
219+
220+
out.reserve(previousStrLen);
221+
}
222+
else
223+
{
224+
server.send(200, "image/svg+xml", out);
225+
}
182226
}
183227
184228
#endif

examples/AdvancedWebServer/defines.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#ifndef defines_h
1616
#define defines_h
1717

18+
//#define HTTP_UPLOAD_BUFLEN 4096
19+
1820
#define DEBUG_ESP8266_AT_WEBSERVER_PORT Serial
1921

2022
// Debug Level from 0 to 4
21-
#define _ESP_AT_LOGLEVEL_ 0
23+
#define _ESP_AT_LOGLEVEL_ 2
2224

2325
// Uncomment to use ESP32-AT commands
2426
//#define USE_ESP32_AT true

examples/AdvancedWebServer_STM32/AdvancedWebServer_STM32.ino

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const int led = 13;
6868

6969
void handleRoot()
7070
{
71-
#define BUFFER_SIZE 400
71+
#define BUFFER_SIZE 512
7272

7373
digitalWrite(led, 1);
7474
char temp[BUFFER_SIZE];
@@ -125,28 +125,51 @@ void handleNotFound()
125125
digitalWrite(led, 0);
126126
}
127127

128+
#define ORIGINAL_STR_LEN 2048
129+
128130
void drawGraph()
129131
{
130-
String out;
131-
out.reserve(3000);
132+
static String out;
133+
static uint16_t previousStrLen = ORIGINAL_STR_LEN;
134+
135+
if (out.length() == 0)
136+
{
137+
AT_LOGWARN1(F("String Len = 0, extend to"), ORIGINAL_STR_LEN);
138+
out.reserve(ORIGINAL_STR_LEN);
139+
}
140+
141+
out = F( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
142+
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
143+
"<g stroke=\"blue\">\n");
144+
132145
char temp[70];
133-
out += F("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n");
134-
out += F("<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n");
135-
out += F("<g stroke=\"blue\">\n");
136146

137147
int y = rand() % 130;
138148

139149
for (int x = 10; x < 300; x += 10)
140150
{
141151
int y2 = rand() % 130;
142-
sprintf_P(temp, PSTR("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n"), x, 140 - y, x + 10, 140 - y2);
152+
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
143153
out += temp;
144154
y = y2;
145155
}
146156

147157
out += F("</g>\n</svg>\n");
148158

149-
server.send(200, F("image/svg+xml"), out);
159+
AT_LOGDEBUG1(F("String Len = "), out.length());
160+
161+
if (out.length() > previousStrLen)
162+
{
163+
AT_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
164+
165+
previousStrLen = out.length() + 48;
166+
167+
out.reserve(previousStrLen);
168+
}
169+
else
170+
{
171+
server.send(200, "image/svg+xml", out);
172+
}
150173
}
151174

152175
void setup()

0 commit comments

Comments
 (0)