okok, mea culpa, vuol dire che SEMPRE quando va a capo manda i segnale \n\r
#include <Ethernet.h>
byte mac[] = { 0x37, 0xA8, 0xD5, 0x00, 0x00, 0x53 };
byte ip[] = { 192, 168, 1, 145 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
}
void loop()
{
Client client = server.available();
if (client) {
// an http request ends with \n\r so:
boolean nWasLastCar = false;
int numeroDiACapo = 0;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
// if we've have a \n followed by a \r the request has ended
if (c == '\r' && nWasLastCar) {
numeroDiACapo++;
}
if (c != '\n') {
nWasLastCar = true;
}else{
nWasLastCar = false;
}
}else{
if (numeroDiACapo>1){
// send a standard http response header
client.println("HTTP/1.0 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><head><title>Prova ethernet</title>");
client.println("</head><body>");
client.println("<form name=\"input\" method=\"POST\">");
client.println("Testo di input: <input type=\"text\" name=\"variabile\" />");
client.println("<input type=\"submit\" value=\"Invia\" />");
client.println("</form></body></html> ");
break;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
ti avviso subito che la struttura del codice deve essere rivista, se il client appena finito di inviare si disconnette da solo c'è il rischio che non elabori parte dei dati via serial...