@@ -61,7 +61,7 @@ void handleRoot()
61
61
{
62
62
digitalWrite (led, 1 );
63
63
64
- #define BUFFER_SIZE 400
64
+ #define BUFFER_SIZE 512
65
65
66
66
char temp[BUFFER_SIZE];
67
67
int sec = millis () / 1000 ;
@@ -114,21 +114,25 @@ void handleNotFound()
114
114
digitalWrite (led, 0 );
115
115
}
116
116
117
- #if (defined(ETHERNET_WEBSERVER_STM32_VERSION_INT) && (ETHERNET_WEBSERVER_STM32_VERSION_INT >= 1003000))
118
-
119
- EWString initHeader = " <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " \
120
- " <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 3\" stroke=\" rgb(0, 0, 0)\" />\n " \
121
- " <g stroke=\" blue\" >\n " ;
117
+ #define ORIGINAL_STR_LEN 2048
122
118
123
119
void drawGraph ()
124
120
{
125
- EWString out;
126
-
127
- out.reserve (3000 );
121
+ static String out;
122
+ static uint16_t previousStrLen = ORIGINAL_STR_LEN;
123
+
124
+ if (out.length () == 0 )
125
+ {
126
+ ET_LOGWARN1 (F (" String Len = 0, extend to" ), ORIGINAL_STR_LEN);
127
+ out.reserve (ORIGINAL_STR_LEN);
128
+ }
129
+
130
+ out = F ( " <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " \
131
+ " <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 3\" stroke=\" rgb(0, 0, 0)\" />\n " \
132
+ " <g stroke=\" blue\" >\n " );
133
+
128
134
char temp[70 ];
129
135
130
- out += initHeader;
131
-
132
136
int y = rand () % 130 ;
133
137
134
138
for (int x = 10 ; x < 300 ; x += 10 )
@@ -138,37 +142,25 @@ void drawGraph()
138
142
out += temp;
139
143
y = y2;
140
144
}
141
- out += " </g>\n </svg>\n " ;
142
-
143
- server.send (200 , " image/svg+xml" , fromEWString (out));
144
- }
145
+
146
+ out += F (" </g>\n </svg>\n " );
145
147
146
- # else
148
+ ET_LOGDEBUG1 ( F ( " String Len = " ), out. length ());
147
149
148
- void drawGraph ()
149
- {
150
- String out;
151
- out.reserve (3000 );
152
- char temp[70 ];
153
- out += " <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " ;
154
- out += " <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 1\" stroke=\" rgb(0, 0, 0)\" />\n " ;
155
- out += " <g stroke=\" black\" >\n " ;
156
- int y = rand () % 130 ;
150
+ if (out.length () > previousStrLen)
151
+ {
152
+ ET_LOGERROR3 (F (" String Len > " ), previousStrLen, F (" , extend to" ), out.length () + 48 );
157
153
158
- for (int x = 10 ; x < 300 ; x += 10 )
154
+ previousStrLen = out.length () + 48 ;
155
+
156
+ out.reserve (previousStrLen);
157
+ }
158
+ else
159
159
{
160
- int y2 = rand () % 130 ;
161
- sprintf (temp, " <line x1=\" %d\" y1=\" %d\" x2=\" %d\" y2=\" %d\" stroke-width=\" 1\" />\n " , x, 140 - y, x + 10 , 140 - y2);
162
- out += temp;
163
- y = y2;
160
+ server.send (200 , " image/svg+xml" , out);
164
161
}
165
- out += " </g>\n </svg>\n " ;
166
-
167
- server.send (200 , " image/svg+xml" , out);
168
162
}
169
163
170
- #endif
171
-
172
164
void setup ()
173
165
{
174
166
pinMode (led, OUTPUT);
0 commit comments