3636 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3737 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838 ***************************************************************************************************************************************/
39+
3940#include " defines.h"
4041
4142int status = WL_IDLE_STATUS; // the Wifi radio's status
@@ -47,7 +48,7 @@ const int led = 13;
4748
4849void handleRoot ()
4950{
50- #define BUFFER_SIZE 500
51+ #define BUFFER_SIZE 512
5152
5253 digitalWrite (led, 1 );
5354 char temp[BUFFER_SIZE];
@@ -104,61 +105,52 @@ void handleNotFound()
104105 digitalWrite (led, 0 );
105106}
106107
107- #if (defined(WIFI_WEBSERVER_VERSION_INT) && (WIFI_WEBSERVER_VERSION_INT >= 1005000))
108-
109- WWString initHeader = " <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " \
110- " <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 3\" stroke=\" rgb(0, 0, 0)\" />\n " \
111- " <g stroke=\" blue\" >\n " ;
108+ #define ORIGINAL_STR_LEN 2048
112109
113110void drawGraph ()
114111{
115- WWString out;
116-
117- out.reserve (3000 );
118- char temp[70 ];
119-
120- out += initHeader;
121-
122- int y = rand () % 130 ;
112+ static String out;
113+ static uint16_t previousStrLen = ORIGINAL_STR_LEN;
123114
124- for ( int x = 10 ; x < 300 ; x += 10 )
115+ if (out. length () == 0 )
125116 {
126- int y2 = rand () % 130 ;
127- sprintf (temp, " <line x1=\" %d\" y1=\" %d\" x2=\" %d\" y2=\" %d\" stroke-width=\" 2\" />\n " , x, 140 - y, x + 10 , 140 - y2);
128- out += temp;
129- y = y2;
117+ WS_LOGWARN1 (F (" String Len = 0, extend to" ), ORIGINAL_STR_LEN);
118+ out.reserve (ORIGINAL_STR_LEN);
130119 }
131- out += " </g>\n </svg>\n " ;
132-
133- server.send (200 , " image/svg+xml" , fromWWString (out));
134- }
135120
136- #else
121+ out = F ( " <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " \
122+ " <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 3\" stroke=\" rgb(0, 0, 0)\" />\n " \
123+ " <g stroke=\" blue\" >\n " );
137124
138- void drawGraph ()
139- {
140- String out;
141- out.reserve (3000 );
142125 char temp[70 ];
143126
144- out += F (" <svg xmlns=\" http://www.w3.org/2000/svg\" version=\" 1.1\" width=\" 310\" height=\" 150\" >\n " );
145- out += F (" <rect width=\" 310\" height=\" 150\" fill=\" rgb(250, 230, 210)\" stroke-width=\" 3\" stroke=\" rgb(0, 0, 0)\" />\n " );
146- out += F (" <g stroke=\" blue\" >\n " );
147127 int y = rand () % 130 ;
148128
149129 for (int x = 10 ; x < 300 ; x += 10 )
150130 {
151- int y2 = ( rand () ) % 130 ;
131+ int y2 = rand () % 130 ;
152132 sprintf (temp, " <line x1=\" %d\" y1=\" %d\" x2=\" %d\" y2=\" %d\" stroke-width=\" 2\" />\n " , x, 140 - y, x + 10 , 140 - y2);
153133 out += temp;
154134 y = y2;
155135 }
136+
156137 out += F (" </g>\n </svg>\n " );
157138
158- server.send (200 , F (" image/svg+xml" ), out);
159- }
139+ WS_LOGDEBUG1 (F (" String Len = " ), out.length ());
160140
161- #endif
141+ if (out.length () > previousStrLen)
142+ {
143+ WS_LOGERROR3 (F (" String Len > " ), previousStrLen, F (" , extend to" ), out.length () + 48 );
144+
145+ previousStrLen = out.length () + 48 ;
146+
147+ out.reserve (previousStrLen);
148+ }
149+ else
150+ {
151+ server.send (200 , " image/svg+xml" , out);
152+ }
153+ }
162154
163155void setup ()
164156{
0 commit comments