@@ -61,7 +61,7 @@ void handleRoot()
6161{
6262 digitalWrite (led, 1 );
6363
64- #define BUFFER_SIZE 400
64+ #define BUFFER_SIZE 512
6565
6666 char temp[BUFFER_SIZE];
6767 int sec = millis () / 1000 ;
@@ -114,21 +114,25 @@ void handleNotFound()
114114 digitalWrite (led, 0 );
115115}
116116
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
122118
123119void drawGraph ()
124120{
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+
128134 char temp[70 ];
129135
130- out += initHeader;
131-
132136 int y = rand () % 130 ;
133137
134138 for (int x = 10 ; x < 300 ; x += 10 )
@@ -138,37 +142,25 @@ void drawGraph()
138142 out += temp;
139143 y = y2;
140144 }
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 " );
145147
146- # else
148+ ET_LOGDEBUG1 ( F ( " String Len = " ), out. length ());
147149
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 );
157153
158- for (int x = 10 ; x < 300 ; x += 10 )
154+ previousStrLen = out.length () + 48 ;
155+
156+ out.reserve (previousStrLen);
157+ }
158+ else
159159 {
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);
164161 }
165- out += " </g>\n </svg>\n " ;
166-
167- server.send (200 , " image/svg+xml" , out);
168162}
169163
170- #endif
171-
172164void setup ()
173165{
174166 pinMode (led, OUTPUT);
0 commit comments