Very strange problem with webserver (home automation)

Hello,

I have done a home automation project in my house, and it has been working very good.

I have develop:

  • Sunblades of my windows automated
  • Light on the front door
  • Heating system

Now, I have implemented two modules more:

  • Open / close a window
  • ON/OFF an air extractor

Ok, all is fine. Easy to implement (only 3 lines more of code), but there is a strange problem that I'm not able to identify:

  • I have dinamic HTML code (some IF senteces, that change the code depending the value of the variables).
  • When I add a few lines of HTML code, suddenly the webserver doesn't give the HTML resulting of the dinamic questions. Example:

client.print("HTML STATIC CODE");
if (var == 1 ) client.print("VALUE is 1");
else client.print("VALUE is not 1");
client.print("HTML STATIC CODE");

If I add some lines more, the IF/ELSE instruction doesn't give anything, and the webpage resulting only have the HTML STATIC CODE lines. It's a very strange problem, and I want to know from you if there is any kind of response time or lag, to show the webpage or something like that, which can produce this strange problem.

If I add more lines when it starts to fail, it show the web but doesn't accept any instructions from the browser.

Here is the small part of the web code that produces the error:

          if (cadena_string.indexOf("$volver")>0)
          {
            pagina_web=0;
          }
          if (cadena_string.indexOf("$vent_dor")>0)
          {
            pagina_web=1;
          }
          if (cadena_string.indexOf("$luz_ent")>0)
          {
            pagina_web=2;
          }
          if (cadena_string.indexOf("$caldera")>0)
          {
            pagina_web=3;
          }
          if (cadena_string.indexOf("$config_hora")>0)
          {
            pagina_web=100;
          }
          if (cadena_string.indexOf("$config_vent_dor")>0)
          {
            pagina_web=101;
          }
          if (millis_ahora - millis_desde_ultima_web > 30000)
          {
            pagina_web=0;
            millis_desde_ultima_web = millis();
          }
          else
          {
            millis_desde_ultima_web = millis();
          }
          
                  
                    
          
          //*********************************************************************************************
          //********************* WWW - WWW - WWW - W E B - WWW - WWW - WWW *****************************
		  //*********************************************************************************************
          // HTML
          //client.println("HTTP/1.1 200 OK");
          //client.println("Content-Type: text/html");
          client.println("<html style=font-family:arial>");
          client.println("<head><title>DOMOTICA ONLINE</title>");
          //client.println("<meta http-equiv=refresh content=3>");
          client.println("<meta name=viewport content=initial-scale=1.3,minimum-scale=1 /></head>");
          client.println("<body  style=background-color:#CED8F6><table style:width 600px><td>");
          
          switch (pagina_web)
          {
            case 0:
            
			//PAGINA RESUMEN 
			
            client.println("<h2 align=center>DOMOTICA</h2>");
            
            //hora del sistema:
            client.print("<table><tr><td><a href=$config_hora><input type=text size=32 align=center value=' Hora del sistema:          ");
            client.print(String(hora));
            Serial.println(hora);
            client.print(":");
            client.print(String(minuto));
            Serial.println(minuto);
            client.print(":");
            client.print(String(segundo));
            Serial.println(segundo);
            client.println("' style=background-color:#B0BBDC readonly></a></td></tr>");
            
            //status luz entrada
            client.print("<tr><td><a href=$luz_ent><input type=text align=center size=32 value=' Luz entrada");
            if (luz_puerta_AUTO==1) client.print("     AUTO");
            client.print("' style=background-color:");
            client.print(aplicar_color(pin_luz_puerta, 0));
            client.println(" readonly></a></td></tr>");
            
            //status caldera
            client.print("<tr><td><a href=$caldera><input type=text align=center size=32 value=' Caldera de Calefaccion");
            if (suelo_salon_AUTO==1 || suelo_dor_AUTO==1) client.print("     AUTO");
            client.print("' style=background-color:");
            client.print(aplicar_color(pin_caldera, caldera_arrancando));
            client.println(" readonly></a></td></tr>");
          
            //status ventana dormitorio
            client.print("<tr><td><a href=$vent_dor><input type=text align=center size=32 value=' Ventana Dormitorio");
            if (vent_dor_status!=0) client.print("     ABIERTA");
            client.print("' style=background-color:");
            if (vent_dor_status==3) client.print(colorear(4));
            else client.print(colorear(3));
            client.println(" readonly></a></td></tr>");
            //client.println("<tr><td><input type=text align=center size=32 value=' Hola mundo' readonly></td></tr>");
  /*
            //status extractor
            client.print("<tr><td><a href=$extractor><input type=text align=center size=32 value=' Extractor Barbacoa");
            if (digitalRead(pin_extractor)==LOW) client.print("     ON");
            client.print("' style=background-color:");
            if (digitalRead(pin_extractor)==LOW) client.print(colorear(4));
            else client.print(colorear(3));
            client.println(" readonly></a></td></tr>");


            //status ventana escalera
            client.print("<tr><td><a href=$vent_escal><input type=text align=center size=32 value=' Ventana Escalera");
            if (digitalRead(pin_vent_escal)==LOW) client.print("     ABIERTA");
            client.print("' style=background-color:");
            if (digitalRead(pin_vent_escal)==LOW) client.print(colorear(4));
            else client.print(colorear(3));
            client.println(" readonly></a></td></tr>");

    */        
            
            client.println("</table>");




            break;          
          case 1: 

}

And the part that give me problems is when I un-comment the following lines:

 /*
            //status extractor
            client.print("<tr><td><a href=$extractor><input type=text align=center size=32 value=' Extractor Barbacoa");
            if (digitalRead(pin_extractor)==LOW) client.print("     ON");
            client.print("' style=background-color:");
            if (digitalRead(pin_extractor)==LOW) client.print(colorear(4));
            else client.print(colorear(3));
            client.println(" readonly></a></td></tr>");


            //status ventana escalera
            client.print("<tr><td><a href=$vent_escal><input type=text align=center size=32 value=' Ventana Escalera");
            if (digitalRead(pin_vent_escal)==LOW) client.print("     ABIERTA");
            client.print("' style=background-color:");
            if (digitalRead(pin_vent_escal)==LOW) client.print(colorear(4));
            else client.print(colorear(3));
            client.println(" readonly></a></td></tr>");

    */

If i uncomment them, then the server doesn't show the numbers of the hour, and doesn't give the colour codes, and all that.
Very very strange.

Any Idea about the problem?

Thanks

You are probably running out of RAM.

Try putting the strings inside the F() macro.

Also, go easy on the String class.

Absolutely brilliant!!!!!!!!!!!!!

thankyuo very much. That was my problem!!!!
thanks mate