Webduino Webserver, saving a variable value from Url.

Hi guys!!
I’m stuck on a really simple webserver using the Webduino library.
Just a few words about it: This server turns ON and OFF a relay, with url commands like “192.168.x.x/R1=ON” or “192.168.x.x/R1=OFF”. and everything works fine. Then i tried to get some variables in the same way,setting up their name and their values in the URL and parsing it to store these variables . For example, i tried to store a variable with the value of a temperature setpoint, with the command “SETCOLD12” ( complete url : 192.168.x.x/SETCOLD12)
To do that, i used strings.By default, the sketch saves a string with the url parameter after the numeric address ( in the first examples url_param is “R1=ON”) , then i tried to ‘split’ this string to get a code (SETCOLD) and a value (12) using string.substring() method to split them, and string.toInt() to save the setpoint value in a variable.
Compilation is OK, but when i upload my sketch to arduino UNO + Ethernet , the servers drops down. 192.168.x.x is no more reachable ( everything was ok before implementing this strings) , and RX pin on ETH shield is continuosly lighted up.
When it works, user and pass to authenticate are : user=ciccio password=pino
Here’s my code:

#include <Ethernet.h>
#include <SPI.h>
#include <WebServer.h> //libreria webduino

//Mac address and IP address
static byte mac_Add[] = {0x05, 0xA3, 0xBB, 0xCC, 0xDE, 0x02 };
//my IP
static byte ip_Add[] = {192, 168, 1, 36 };
//creazione oggetto Webduino
WebServer webserver("", 80);

//relay status
boolean Rele1 = false;
boolean Rele2 = false;
boolean Rele3 = false;
int c1=10;  // just for trying a server.print
int c2=3;
int c3=340;

int coldpoint,hotpoint,lightpoint;



void privateCmd(WebServer &server, WebServer::ConnectionType type, char *url_param, bool param_complete)  
{ //da web_Authentication
  
  if (server.checkCredentials("Y2ljY2lvOnBpbm8="))  //da web_Authentication su base64 scrivere admin:admin
                            // e la traduzione sarà YWRtaW46YWRtaW4=   http://www.motobit.com/util/base64-decoder-encoder.asp
    {    //da web_Authentication
    server.httpSuccess();   //da web_Authentication
    if (type != WebServer::HEAD)   //da web_Authentication
    {   //da web_Authentication
    
    String s="";
    String code="";
    String setpoint="";
     if (param_complete == true)
    {
      s = url_param;
      code=s.substring(0,7);
      setpoint=s.substring(7,9);
      
      if ( s == "R1=ON")
      {
        Rele1 = true;
        digitalWrite(2, HIGH);
      }
      else if ( s == "R1=OFF")
      {
        Rele1 = false;
        digitalWrite(2, LOW);
      }
      else if (code != "");
          if(code=="SETCOLD"){
          int coldpoint=setpoint.toInt();
        }
          else if(code=="SETHOTT"){
          int hotpoint=setpoint.toInt();
        }
          else if(code=="SETLITE"){
          int lightpoint=setpoint.toInt();
        }
      
         }
    }

    //gestisco la pagina html in base allo stato delle uscite di Arduino
    P(htmlHead) =
    "<html>"
    "<head>"
    "<title> DomotiControl </title>"
    "</head>"
    "<body>";

    server.printP(htmlHead);
    server.print("<div style='width: 360px; height: 640px;'>");
    server.print("<big style='color: rgb(0, 0, 102);'><big><big><span style='font-family: Segoe UI;'>Casa Domotica Arduino.</span></big></big></big>
");
    server.print("<table border=\"1\">");
    server.print("<tr><td>Sensore</td><td>Valore</td><td>SetPoint attuale</td><td>Stato Relè</td><td>Comandi</td></tr>
");
    server.print("<tr><td>Luminosita</td><td>");
    server.print(c1);
    server.print("</td><td>");
    server.print(lightpoint);
    server.print("</td>");
    if(Rele1 == true)
      server.print("<td style=\"color: red;\">RELE 1 ON</td><td>");
    else
      server.print("<td style=\"color: black;\">RELE 1 OFF</td><td>");
 
    if(Rele1 == false)
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R1=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R1=OFF'\">");
    server.print("</td></tr>");
    
   
    server.print("<tr><td>Freddo</td><td>");
    server.print(c2);
     server.print("</td><td>");
    server.print(coldpoint);
    server.print("</td>");
    if(Rele2 == true)
      server.print("<td style=\"color: red;\">RELE 2 ON</td><td>");
    else
      server.print("<td style=\"color: black;\">RELE 2 OFF</td><td>");
 
    if(Rele2 == false)
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R2=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R2=OFF'\">");
  server.print("</td></tr>");
 
 server.print("<tr><td>Caldo</td><td>");
    server.print(c3);
    server.print("</td><td>");
    server.print(hotpoint);
    server.print("</td>");
    if(Rele3 == true)
      server.print("<td style=\"color: red;\">RELE 3 ON</td><td>");
    else
      server.print("<td style=\"color: black;\">RELE 3 OFF</td><td>");
 
    if(Rele3 == false)
      server.print("<input type=\"button\" value=\"clicca qui\" onclick=\"location.href='index.htm?R3=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R3=OFF'\">");
 
    server.print("</td></tr>");
 
    server.print("</table></body></html>");

  }
  }
  else
  {
    /* send a 401 error back causing the web browser to prompt the user for credentials */
    server.httpUnauthorized();
  }
}

void setup()
{
  //inizializzo l'ethernet shield con il mac e il address
  Ethernet.begin(mac_Add, ip_Add);

  //definisci l'azione di default che verrà eseguita quando l'utente
  //naviga nella root del sito
  webserver.setDefaultCommand(&privateCmd);
  webserver.addCommand("index.htm", &privateCmd);

  //avvia il web server
  webserver.begin();

  delay(100);

  //definisci i pin 2 3 4 in uscita
  pinMode(2, OUTPUT);
 
  //inizializza i le uscite
  digitalWrite(2, LOW);
 
}

void loop()
{
  //elabora costantemente tutte le richieste provenienti dal browser
  webserver.processConnection();
}

Can someone help me getting reed of this problem?

Can someone help me getting reed of this problem?

You need to tell us which lines you added to cause the problem.

I’m going to go put on a limb, though, and suggest that you are out of memory. You have a LOT of string literal that get copied, unnecessarily, into SRAM at run time. Keep that from happening with the F() macro:
server.print(F("

"));

    {    //da web_Authentication
    server.httpSuccess();   //da web_Authentication
    if (type != WebServer::HEAD)   //da web_Authentication
    {   //da web_Authentication

How does that comment relate to all 4 lines? If if doesn’t, get rid of it.

Hi PaulS, i solved the "crash down" problem modifying the the first lines of privateCmd to

if (server.checkCredentials("Y2ljY2lvOnBpbm8="))  //da web_Authentication su base64 scrivere admin:admin
                            // e la traduzione sarà YWRtaW46YWRtaW4=   http://www.motobit.com/util/base64-decoder-encoder.asp
  {    
    server.httpSuccess();   
    if (type != WebServer::HEAD)   
    {   
    
    String s="";
   
     if (param_complete == true)
    {
      s = url_param;
      String code="";
      code=s.substring(0,7);
      String setpoint=s.substring(7,9);
    
      server.print(code);
      //server.print("
");
      server.print(setpoint);

The lines that caused the crash were

 String s="";
    String code="";
    String setpoint="";

Cannot say why, but that's it!

About your suggestions:
1.It's the first time i generate a webpage directly inside the arduino code , so i'm not really practical with those macros. Should i use them with (F) or (P) for every "template" line? ( like static tables rows, static messages , etc)

2.About the comments: yeah, i'm gonna get rid of them , that was a result of a copy&paste from another sketch :slight_smile: