Problema login arduino ethernet

Come già detto nella sezione presentazione sono alle prime armi con arduino e quello che lo circonda.
Ieri mi è arrivato arduino uno ethernet, usando IDE 1.0.2 ho copiato il codice al seguente link
Arduino Forum, e corretto
in true == login, cambiato ip, sottorete e i pin che uso sono 3, 5, 6.
Dopo eseguito il login se provo ad accendere uno dei tre led, (anche se premo direttamente su OFF) torno
alla pagina principale, dove appunto ho fatto il login con user e paswd, come se facessi back con il browser.
Però se alla fine del codice commento questa istruzione: readString="";
dopo il login riesco ad accendere i 3 led, ma non riesco a spegnerli.
Mentre se non uso il login riesco ad accendere e spegnere i 3 led senza problemi.
Per favore mi fate capire dove è il problema?

Puoi postare il codice che usi tu. Nel topic indicato ci sono varie versioni.

E' uscito l'IDE 1.0.3 con alcune correzioni rispetto al 1.0.2 --> http://arduino.cc/en/Main/Software

Questo è il codice che uso io:

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 220 }; // ip in lan
byte gateway[] = { 192, 168, 1, 220 }; // ip in lan
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login=false;
 
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600);
}
 
void loop(){
EthernetClient client = server.available();
if (client) {
  boolean currentLineIsBlank = true;
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
        readString.concat(c);
      if (c == '\n' && currentLineIsBlank) {
         Serial.print(readString);
        if(readString.indexOf("Nome=user&Pwd=pass") > 0) {
         login=true;
        } else {
         login=false;
        }
        if(login==true){
        if(readString.indexOf("L=1") > 0) {
          digitalWrite(3, HIGH); // set the LED on
          LED1ON = true;
          }else
          if(readString.indexOf("L=01") > 0) 
          {
          //led has to be turned OFF
          digitalWrite(3, LOW); // set the LED OFF
          LED1ON = false;
        }
        if(readString.indexOf("L=2") > 0) {//lets check if LED should be lighted
          //led has to be turned ON
          digitalWrite(5, HIGH); // set the LED on
          LED2ON = true;
          }else
          if(readString.indexOf("L=02") > 0)  
          {
          //led has to be turned OFF
          digitalWrite(5, LOW); // set the LED OFF
          LED2ON = false;
        }
        if(readString.indexOf("L=3") > 0) {//lets check if LED should be lighted
          //led has to be turned ON
          digitalWrite(6, HIGH); // set the LED on
          LED3ON = true;
          }else
          if(readString.indexOf("L=03") > 0)
          {
          //led has to be turned OFF
          digitalWrite(6, LOW); // set the LED OFF
          LED3ON = false;
        }
        } 
        // INIZIO DICHIARAZIONE PAGINA HTML
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println();
        client.print("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
        // Finestra di login
        client.print("<form action='http://192.168.1.220/'>");
        client.print("Nome");    
        client.print("utente: <input name='Nome' value=''>");
        client.print("Password: <input type='Password' name='Pwd' value=''>");
        client.print("<input type='submit' value=' OK '>");
        client.print("</form>");
       
        if (login==true) {
        //Primo led
        client.println("<hr />");
        client.println("<h1>LED1</h1>");
        client.println("
");
        //printing LED status
        client.print("<span>STATO LED: </span>");
 
          if (LED1ON) {
              client.println("<span style='color:green'>ON</span>");
            }
            else
            {
              client.println("<span style='color:grey'>OFF</span>");
          }
        client.print("<h2><a href='/?L=1'>ON</a> | <a href='/?L=01'>OFF</a></h2>");
        
        client.println("<hr />");
        
        //Secondo led
        client.println("<h1>LED2</h1>");
        client.println("
");
        //printing LED status
        client.print("<span>STATO LED: </span>");
 
          if (LED2ON) {
              client.println("<span style='color:green'>ON</span>");
            }
            else
            {
              client.println("<span style='color:grey'>OFF</span>");
          }
        client.print("<h2><a href='/?L=2'>ON</a> | <a href='/?L=02'>OFF</a></h2>");
        client.println("<hr />");
        
        //terzo led
         client.println("<h1>LED3</h1>");
        client.println("
");
        //printing LED status
        client.print("<span>STATO LED: </span>");
 
          if (LED3ON) {
              client.println("<span style='color:green'>ON</span>");
            }
            else
            {
              client.println("<span style='color:grey'>OFF</span>");
          }
        client.print("<h2><a href='/?L=3'>ON</a> | <a href='/?L=03'>OFF</a></h2>");
        } //chiude if login=true 
        client.println("</body></html>");
 
        //clearing string for next read
        readString="";
        //stopping client
        client.stop();
 
        } 
    } 
  } 
} 
}

grazie per la disponibilità

Per prima cosa è sbagliata l'inizializzazione della Ethernet:
non è Ethernet.begin(mac, ip, gateway, subnet);
ma è:

 Ethernet.begin(mac, ip, gateway, gateway, subnet);

Il primo gatwae in effetti dovrebbe essere il server DNS ma nel 99% delle lan è uguale a gateway.
E' un errore frequentissimo --> Ethernet - Arduino Reference

Syntax
Ethernet.begin(mac);
Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, dns);
Ethernet.begin(mac, ip, dns, gateway);
Ethernet.begin(mac, ip, dns, gateway, subnet);

Riedita il tuo messaggio precedente e inserisci i tag [code ]. Escono premendo il simbolo # sopra le faccine.

Infati non sapevo come si inserisce il codice nei tag...

cmq ho modificato anche in :
Ethernet.begin(mac, ip, gateway, gateway, subnet);
e in:
Ethernet.begin(mac, ip, dns, gateway, subnet);

poi ho provato con solo mac e ip
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 220 }; // ip in lan
Ethernet.begin(mac, ip);

se commento questo: // readString="";

dopo il login accendo i led ma non li spengo

altrimenti se non commento readString="";
dopo il login se clicco su on oppure off torno all'inizio doce c'è il login

Ho separato il listato in modo da capire meglio quello che fa.
Ho inserito la funzione F in tutto il contenuto statico in modo da risparmiare memoria.

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 220 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 220 }; // ip in lan
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login = false;

void setup(){
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        readString.concat(c);
        if (c == '\n' && currentLineIsBlank){
          WebPage(client);  
        }
      } 
    } 
  } 
}

void WebPage (EthernetClient &client){
  Serial.print(readString);

  // Check Login
  if(readString.indexOf("Nome=user&Pwd=pass") > 0) {
    login=true;
  } 
  else {
    login=false;
  }
  
  // Check Led
  if(login==true){
    if(readString.indexOf("L=1") > 0) {
      digitalWrite(3, HIGH); // set the LED on
      LED1ON = true;
    }
    else
      if(readString.indexOf("L=01") > 0) 
      {
        //led has to be turned OFF
        digitalWrite(3, LOW); // set the LED OFF
        LED1ON = false;
      }
    if(readString.indexOf("L=2") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(5, HIGH); // set the LED on
      LED2ON = true;
    }
    else
      if(readString.indexOf("L=02") > 0)  
      {
        //led has to be turned OFF
        digitalWrite(5, LOW); // set the LED OFF
        LED2ON = false;
      }
    if(readString.indexOf("L=3") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(6, HIGH); // set the LED on
      LED3ON = true;
    }
    else
      if(readString.indexOf("L=03") > 0)
      {
        //led has to be turned OFF
        digitalWrite(6, LOW); // set the LED OFF
        LED3ON = false;
      }
  } 

  // INIZIO DICHIARAZIONE PAGINA HTML
  client.println(F("HTTP/1.1 200 OK"));
  client.println(F("Content-Type: text/html"));
  client.println();
  client.print(F("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>"));
  
  // Finestra di login
  client.print(F("<form action='http://192.168.1.220/'>"));
  client.print(F("Nome"));    
  client.print(F("utente: <input name='Nome' value=''>"));
  client.print(F("Password: <input type='Password' name='Pwd' value=''>"));
  client.print(F("<input type='submit' value=' OK '>"));
  client.print(F("</form>"));

  // Login OK
  if (login==true) {
    //Primo led
    client.println(F("<hr />"));
    client.println(F("<h1>LED1</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED1ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=1'>ON</a> | <a href='/?L=01'>OFF</a></h2>"));

    client.println(F("<hr />"));

    //Secondo led
    client.println(F("<h1>LED2</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED2ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=2'>ON</a> | <a href='/?L=02'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //terzo led
    client.println(F("<h1>LED3</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED3ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=3'>ON</a> | <a href='/?L=03'>OFF</a></h2>"));
  } //chiude if login=true 
  client.println(F("</body></html>"));

  //clearing string for next read
  readString="";
  //stopping client
  client.stop();
}

Secondo me c'è un errore nella logica di funzionamento poichè invii la pagina di login anche se è già stato effettuato.
Dovresti mettere un if:

  if (login==false) {
 // Finestra di login
  client.print(F("<form action='http://192.168.1.220/'>"));
  client.print(F("Nome"));    
  client.print(F("utente: <input name='Nome' value=''>"));
  client.print(F("Password: <input type='Password' name='Pwd' value=''>"));
  client.print(F("<input type='submit' value=' OK '>"));
  client.print(F("</form>"));
  }

ho provato il nuovo codice, ma si comporta sempre allo stesso modo...

Si, infatti non ho inserito l'if sul login.
Dovresti modificarlo tu. :wink:

no l' if c'è:
// Finestra di login
if (login==false) {
client.print(F(""));
client.print(F("Nome"));
client.print(F("utente: "));
client.print(F("Password: "));
client.print(F(""));
client.print(F(""));
}

Ci sarebbe anche la lib base64 per le login non che sia una sicurezza, oppure prova una stringa md5 a 32 caratteri.
O ancora .... Scrivi 401 al posto di 200 il client ti apre la maschera di login user e passw
Ciao

Ho messo 401 al posto di 200 ma il login è sempre uguale...
Io ho anche scaricato la libreria WebServerAuth (da come ho capito si basa su Webduino)
ma non ho idea di come si usa.

Ho anche provato a passare la stringa tipo:
http://192.168.1.220/?L=1
dal controllo Web Browser tramite una form che ho fatto con VB.net, alla fine ho lo stesso risultato
riesco a accendere i led ma non li spengo.Se funzionava con il VB .net avevo risolto il login non mi serviva più

Ho tolto gli else dagli if dei led

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 220 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 220 }; // ip in lan
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login = false;

void setup(){
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        readString.concat(c);
        if (c == '\n' && currentLineIsBlank){
          Serial.println(readString);
          WebPage(client);
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();  
        }
      } 
    } 
  } 
}


void WebPage (EthernetClient &client){

  // Check Login
  if(readString.indexOf("Nome=user&Pwd=pass") > 0) {
    login=true;
    Serial.println("Login OK ");
  } 
  else {
    login=false;
    Serial.println("Login ERR");
  }

  // Check Led
  if(login==true){
    if(readString.indexOf("L=1") > 0) {
      digitalWrite(3, HIGH); // set the LED on
      LED1ON = true;
    }

    if(readString.indexOf("L=01") > 0) 
    {
      //led has to be turned OFF
      digitalWrite(3, LOW); // set the LED OFF
      LED1ON = false;
    }

    if(readString.indexOf("L=2") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(5, HIGH); // set the LED on
      LED2ON = true;
    }

    if(readString.indexOf("L=02") > 0)  
    {
      //led has to be turned OFF
      digitalWrite(5, LOW); // set the LED OFF
      LED2ON = false;
    }

    if(readString.indexOf("L=3") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(6, HIGH); // set the LED on
      LED3ON = true;
    }

    if(readString.indexOf("L=03") > 0)
    {
      //led has to be turned OFF
      digitalWrite(6, LOW); // set the LED OFF
      LED3ON = false;
    }
  } 

  // INIZIO DICHIARAZIONE PAGINA HTML
  client.println(F("HTTP/1.1 200 OK"));
  client.println(F("Content-Type: text/html"));
  client.println();
  client.print(F("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>"));

  // Finestra di login
  if (login==false) {
    client.print(F("<form action='http://192.168.1.220/'>"));
    client.print(F("Nome"));    
    client.print(F("utente: <input name='Nome' value=''>"));
    client.print(F("Password: <input type='Password' name='Pwd' value=''>"));
    client.print(F("<input type='submit' value=' OK '>"));
    client.print(F("</form>"));
  }

  // Login OK
  if (login==true) {
    //Primo led
    client.println(F("<hr />"));
    client.println(F("<h1>LED1</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED1ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=1'>ON</a> | <a href='/?L=01'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //Secondo led
    client.println(F("<h1>LED2</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED2ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=2'>ON</a> | <a href='/?L=02'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //terzo led
    client.println(F("<h1>LED3</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED3ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=3'>ON</a> | <a href='/?L=03'>OFF</a></h2>"));
  } //chiude if login=true 
  client.println(F("</body></html>"));
}

Niente da fare nemmeno senza gli else

Sul serial monitor cosa visualizza?

dopo il login ho cliccato su ON per accendere il led e mi ritorna alla pagina principale, però c'è un errore sul serial monitor:
GET / HTTP/1.1

Login ERR
GET /?Nome=user&Pwd=pass HTTP/1.1

Login OK
GET /?L=1 HTTP/1.1

Login ERR

Il problema è che ogni volta che si fa una richiesta avviene il controllo dell'user e password e non trovandola viene messa false.
Ecco perché torna alla pagina di login.

Ho messo i parametri della mia rete... dovresti modificarli per la tua.

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 40, 220 }; // ip in lan
byte gateway[] = { 
  192, 168, 40, 254 }; // ip in lan
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login = false;

void setup(){
  delay(2000);

  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
  Serial.print("Serial Start! at ");
  Serial.print(millis());
  Serial.println(" millisecond.");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);  
  delay(1000);

  Serial.println("Ethernet configured");
  Serial.print("Local IP: ");
  Serial.println(Ethernet.localIP());
  Serial.print("SubnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(Ethernet.gatewayIP()); 
  Serial.print("DNS Server: ");
  Serial.println(Ethernet.dnsServerIP());

  Serial.println("Wait client...");
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    Serial.println("Client connect");
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        readString.concat(c);
        // Serial.print("readString: ");
        // Serial.println(readString);
        if (c == '\n' && currentLineIsBlank){
          Serial.print("--> ");
          Serial.println(readString);
          WebPage(client);
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();  
        }
      } 
    }
    Serial.println("Client disconnect");
  } 
}


void WebPage (EthernetClient &client){

  // Check Login
  if(readString.indexOf("Nome=user&Pwd=pass") > 0) {
    login=true;
    Serial.println("Login OK ");
  } 
  else {
    login=false;
    Serial.println("No Login");
  }

  // Check Led
  if(login==true){
    if(readString.indexOf("L=1") > 0) {
      digitalWrite(3, HIGH); // set the LED on
      LED1ON = true;
    }

    if(readString.indexOf("L=01") > 0) 
    {
      //led has to be turned OFF
      digitalWrite(3, LOW); // set the LED OFF
      LED1ON = false;
    }

    if(readString.indexOf("L=2") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(5, HIGH); // set the LED on
      LED2ON = true;
    }

    if(readString.indexOf("L=02") > 0)  
    {
      //led has to be turned OFF
      digitalWrite(5, LOW); // set the LED OFF
      LED2ON = false;
    }

    if(readString.indexOf("L=3") > 0) {//lets check if LED should be lighted
      //led has to be turned ON
      digitalWrite(6, HIGH); // set the LED on
      LED3ON = true;
    }

    if(readString.indexOf("L=03") > 0)
    {
      //led has to be turned OFF
      digitalWrite(6, LOW); // set the LED OFF
      LED3ON = false;
    }
  } 

  // INIZIO DICHIARAZIONE PAGINA HTML
  client.println(F("HTTP/1.1 200 OK"));
  client.println(F("Content-Type: text/html"));
  client.println();
  client.print(F("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>"));

  // Finestra di login
  if (login==false) {
    // client.print(F("<form action='http://192.168.40.220/'>"));
    client.print(F("<form>"));
    client.print(F("Nome"));    
    client.print(F("utente: <input name='Nome' value=''>"));
    client.print(F("Password: <input type='Password' name='Pwd' value=''>"));
    client.print(F("<input type='submit' value=' OK '>"));
    client.print(F("</form>"));
  }

  // Login OK
  if (login==true) {
    //Primo led
    client.println(F("<hr />"));
    client.println(F("<h1>LED1</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED1ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=1'>ON</a> | <a href='/?L=01'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //Secondo led
    client.println(F("<h1>LED2</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED2ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=2'>ON</a> | <a href='/?L=02'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //terzo led
    client.println(F("<h1>LED3</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED3ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=3'>ON</a> | <a href='/?L=03'>OFF</a></h2>"));
  } //chiude if login=true 
  client.println(F("</body></html>"));
}

potresti togliere questa parte

  else {
    login=false;
    Serial.println("No Login");
  }

ma in questo modo una volta fatto il login la variabile non diventerebbe mai "false".

a me continua a non funzionare, sempre la stessa cosa dopo il login clicco su ON oppure OFF e torna alla pagina di login

Serial Start! at 1999 millisecond.
Ethernet configured
Local IP: 192.168.1.220
SubnetMask: 255.255.255.0
Gateway: 192.168.1.200
DNS Server: 192.168.1.200
Wait client...
Client connect
--> GET / HTTP/1.1

No Login
Client disconnect
Client connect
--> GET /?Nome=user&Pwd=pass HTTP/1.1

Login OK
Client disconnect
Client connect
--> GET /?L=1 HTTP/1.1

No Login
Client disconnect

Si, lo so che non funziona.... ho tirato fuori il mio Arduino R3 + Ethernet shield e sto provando "con mano" il codice.
Il problema come ti ho detto nel messaggio precedente è che ogni volta che invii un comando all'Arduino lui fa il check della login.
Bisognerebbe aggiungere una variabile firstlogin in modo da discriminare se il login è stato già fatto.
Adesso ci lavoro un po' su. :smiley:

Ho rivisto la logica del login.
Ho aggiunto un timeout impostatile (adesso è 60 secondi) e un pulsante Exit.

#include <String.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 40, 220 }; // ip in lan
byte gateway[] = { 
  192, 168, 40, 254 }; // ip in lan
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login = false;

unsigned int currentmillis = 0;
unsigned int interval = 60*1000;

void setup(){
  delay(2000);

  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
  Serial.print("Serial Start! at ");
  Serial.print(millis());
  Serial.println(" millisecond.");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);  
  delay(1000);

  Serial.println("Ethernet configured");
  Serial.print("Local IP: ");
  Serial.println(Ethernet.localIP());
  Serial.print("SubnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(Ethernet.gatewayIP()); 
  Serial.print("DNS Server: ");
  Serial.println(Ethernet.dnsServerIP());

  Serial.println("Wait client...");
  currentmillis = millis();
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    Serial.println("Client connect");
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        readString.concat(c);
        if (c == '\n' && currentLineIsBlank){
          Serial.print("--> ");
          Serial.println(readString);
          CheckLogin();
          if(login==true) CheckLed();
          WebPage(client);
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();  
        }
      } 
    }
    Serial.println("Client disconnect");
  } 
}


void WebPage (EthernetClient &client){
  // INIZIO DICHIARAZIONE PAGINA HTML
  client.println(F("HTTP/1.1 200 OK"));
  client.println(F("Content-Type: text/html"));
  client.println();
  client.print(F("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>"));

  // Finestra di login
  if (login==false) {
    // client.print(F("<form action='http://192.168.40.220/'>"));
    client.print(F("<form>"));
    client.print(F("Nome"));    
    client.print(F("utente: <input name='Nome' value=''>"));
    client.print(F("Password: <input type='Password' name='Pwd' value=''>"));
    client.print(F("<input type='submit' value=' OK '>"));
    client.print(F("</form>"));
  }

  // Login OK
  if (login==true) {
    //Primo led
    client.println(F("<hr />"));
    client.println(F("<h1>LED1</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED1ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=1'>ON</a> | <a href='/?L=01'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //Secondo led
    client.println(F("<h1>LED2</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED2ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=2'>ON</a> | <a href='/?L=02'>OFF</a></h2>"));
    client.println(F("<hr />"));

    //terzo led
    client.println(F("<h1>LED3</h1>"));
    client.println(F("
"));
    //printing LED status
    client.print(F("<span>STATO LED: </span>"));

    if (LED3ON) {
      client.println(F("<span style='color:green'>ON</span>"));
    }
    else
    {
      client.println(F("<span style='color:grey'>OFF</span>"));
    }
    client.print(F("<h2><a href='/?L=3'>ON</a> | <a href='/?L=03'>OFF</a></h2>"));

    client.println(F("<hr />"));
    //Exit
    //  client.println(F("<h1>Exit</h1>"));
    //  client.println(F("
"));
    client.print(F("<h2><a href='/?L=Exit'>Exit</a>"));

  } //chiude if login=true 
  client.println(F("</body></html>"));
}


void CheckLogin() {
  // Check Login
  if ((millis() - currentmillis) > interval){
    login = false;
    currentmillis = millis();
    Serial.println("Login Timeout");
  }
  if (readString.indexOf("Nome=user&Pwd=pass") > 0) {
    login=true;
    currentmillis = millis();
    Serial.println("Login OK ");
  } 
  if (readString.indexOf("L=Exit") > 0) {
    login=false;
    Serial.println("No Login");
  }
}


void CheckLed() {
  // Check Led

    if(readString.indexOf("L=1") > 0) {
    digitalWrite(3, HIGH); // set the LED on
    LED1ON = true;
  }

  if(readString.indexOf("L=01") > 0) 
  {
    //led has to be turned OFF
    digitalWrite(3, LOW); // set the LED OFF
    LED1ON = false;
  }

  if(readString.indexOf("L=2") > 0) {//lets check if LED should be lighted
    //led has to be turned ON
    digitalWrite(5, HIGH); // set the LED on
    LED2ON = true;
  }

  if(readString.indexOf("L=02") > 0)  
  {
    //led has to be turned OFF
    digitalWrite(5, LOW); // set the LED OFF
    LED2ON = false;
  }

  if(readString.indexOf("L=3") > 0) {//lets check if LED should be lighted
    //led has to be turned ON
    digitalWrite(6, HIGH); // set the LED on
    LED3ON = true;
  }

  if(readString.indexOf("L=03") > 0)
  {
    //led has to be turned OFF
    digitalWrite(6, LOW); // set the LED OFF
    LED3ON = false;
  }
}

Senti non ho parole...funziona alla grande
ma tu di professione fai il programmatore?

Ora nella mia ignoranza totale cerco almeno di capire la logica del tuo codice con la speranza di imparare

Grazie infinite per la tua disponibilità gentilezza e soprattutto per la tua professionalità.

Cmq poi aprirò sicuramente un'altro post per avere delle delucidazioni in merito alle uscite disponibili dell' Arduino Ethernet
tipo l'uscita 0 e 1, che ho capito che servono per la programmazione via seriale, ma poi staccato la seriale
si possono usare?