Slow page reload with WiFi


I have some problems with de Wifi server that I made up.

The server works fine, but is verry slow. It takes up to 1 minute to load the page on my browser, and when I click on a button it again takes a lot of time to reload the page. The functions that are connected with the buttons reacts quick.

The problem of the big delay is because I need to place all the lines of code, who print the html on my browser, in my flash memory by using server.print(F("")) for example.

Now my question can I solve this otherwise? I can’t put it in my SRAM because it is to small. It’s quite a large program with a lot of variables. I can’t erase any more of them. They are at there minimum.

See the code below. It is just the WiFi part


void print_header(WiFiClient &client){
   client.println(F("HTTP/1.1 200 OK"));
   client.println(F("Content_Type: text/html"));
 void print_form(WiFiClient &client){
  client.print(F("<body bgcolor='#818181'>"));
   client.print("<B>OPGELET, INDRINGER. 
Bekijk de live beelden voor verdere info</B>"); 
client.print(F("<form action='/' method='GET'>"));   
client.print(F("<table cellspacing='0'><tr><td>")); //Rij1 kolom1
client.print(F("<input type='submit' name='MOVE' onclick='this.form.submit()' style='width:100%' value='RANDOM'></input>"));//Ga naar een willekeurig coördinaat
client.print(F("<input type='submit' name='MOVE' onclick='this.form.submit()' style='width:100%' value='VOORUIT'></input>"));
client.print(F("<input type='submit' name='MOVE' onclick='this.form.submit()' style='width:100%' value='BEVEILIG'></input>"));//start de beveiliging op door de robot continue te laten patrouilleren
client.print(F("</td></tr><tr><td>")); //Rij2 kolom1
client.print(F("<input type='submit' name='MOVE' onclick='this.form.submit()' style='width:100%' value='LINKS'></input>"));
client.print(F("</td><td>")); //kolom2
client.print(F("<input type='TEXT' name='CO' style='width:100%' value=''></input>")); 
client.print(F("<input type='submit' onclick='this.form.submit()' style='width:100%' value='verzenden'></input>"));
client.print(F("</td><td>"));// kolom3
client.print(F("<input type='submit' name='MOVE' onclick='this.form.submit()' style='width:100%' value='RECHTS'></input>"));  
client.print(F("</td></tr><tr><td>")); //Rij3 kolom1
client.print(F("<input type='submit' name='SMOVE' onclick='this.form.submit()' style='width:100%' value='SERVO LINKS'></input>"));
client.print(F("</td><td>")); //kolom2
client.print(F("</td><td>")); //kolom3
client.print(F("<input type='submit' name='SMOVE' onclick='this.form.submit()' style='width:100%' value='SERVO RECHTS'></input>"));   
 void end_page(WiFiClient &client){
  client.print(F("<B>ServoDirection =</B>"));
<B>CurrentCoordinate =</B>"));
<B>CurrentDirection =</B>"));

Use the F() macro to have all the text in flash. That is how it is done, and it is not that much slower than text in sram. When a page takes 1 minute, something else is going on. Do you use the Arduino Uno and are running out of sram ? Is there some delay in your sketch ? Can you make a test sketch with only the webserver part and all those client.println(F("...")) ? That should be fast. Do you have a bad connection ? Can you measure the time it takes to show the page ? It is the same every time ?

You might put all the static text in a large F() macro like below to limit the number of print commands and gain some packet efficiency.

//double quote " in html replaced with a single quote' to prevent compile error
//html lines consolidated and put inside F() macro to save memory space

client.print(F("<html><head><meta http-equiv='Content-Language' content='pt-br'>"
"<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>"
"<title>Unirp - Centro Universitário de Rio Preto</title></head><body>"
"<div align='center'><h1>Centro Universitario de Rio Preto</h1>"
"<h2>Gerenciamento de Volume e Temperatura da Banheira</h2></div>"
"<div align='center'><h4> Pressione o Botão para encher na temperatura desejada</h4>"
"<table border='0' width='50%' cellpadding='2'><tr></tr><tr><td>"
"<!--Botão Temperatura Fria--><form method='POST' action='arduino.php'>"
"<p align='center'><input type='hidden' value='fria' name='tempD' >"
"<input type='submit' value='Água Fria' name='fria'></p></form>"
"<!--Botão Temperatura Morna--><form method='POST' action='arduino.php'>"
"<p align='center'><input type='hidden' value='morna' name='tempD' >"
"<input type='submit' value='Água Morna' name='morna'></p></form>"
"<!--Botão Temperatura Quente--><form method='POST' action='arduino.php'>"
"<p align='center'><input type='hidden' value='quente' name='tempD' >"
"<input type='submit' value='Água Quente' name='quente'></p></form></form>"
"<div align='center'></div></tr></table></div></body></html>"));


sorry for the delay.

When I print with the F function it takes about 50 secondes. Sometimes it takes longer then the other time.

I put the Wifi part in an other sketch and there are no delay's in it. just the one in the setup of 10 seconds.

without the F function it takes about 30 seconds.

Perhaps the setup of 10 seconds is normal (okay, it might be a little longer than normal). Let's assume the hardware is okay, since it is working in an other sketch.

However, the F() macro can not cause it to slow down. There is something else going on. Perhaps buffers clogs, timeouts going wrong, or something in the sketch. I don't have a wifi shield, so I can't test your sketch, and I don't know what to do next. Sorry.

I don't use any buffers or timeouts. So that can't be the problem. It's just the client.print.

In the libraries, in the chips, your Arduino is filled with buffers and timeouts.