guarda scrivendo un banale codice che credo sia simile alla base del tuo lo pinga tranquillamente(provalo) :
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ 60
byte mac[] = { 0xDE, 0xAD, 0xBE, 0x0F, 0x87, 0x62 };
IPAddress ip(10, 50, 70, 40);
EthernetServer server(80); // crea un server alla porta 80(di default per HTTP)
File webFile; // index.htm sulla SD
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
int LED_state = 0; // stores the states of the LEDs
boolean acceso ;
int tmp_int=A2 ;
void setup()
{
// indica al convertitore AD la tensione presente su AREF come tensione di riferimento
analogReference(EXTERNAL);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH); //dedicato alla scheda Ethernet
Serial.begin(9600) ;
Ethernet.begin(mac, ip);
server.begin(); // Arduino si mette in ascolto
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// limit the size of the stored received HTTP request
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
// stampa l'header standard in base al fatto che sia richiesta la stringa JSON o la pagina Web
//se è richiesta la stringa JSON la manda
if (StrContains(HTTP_req, "ajax_inputs")) {
// send rest of HTTP header
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
}
else { // web page request
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
}
// display received HTTP request on serial port
Serial.println(HTTP_req);
// reset buffer index and all buffer elements to 0
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // dà al browser il tempo di ricevere di ricevere i dati
client.stop(); //chiude la connessione
} // end if (client)
}
// pulisce str settando tutti i suoi caratteri a 0
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str = 0;
-
}*
}
//Cerca sfind in str e dà come risultato 1 se la trova, 0 se non la trova
char StrContains(char *str, char *sfind)
{
-
char found = 0;*
-
char index = 0;*
-
char len;*
-
len = strlen(str);*
-
if (strlen(sfind) > len) {*
-
return 0;*
-
}*
-
while (index < len) {*
-
if (str[index] == sfind[found]) {*
-
found++;*
-
if (strlen(sfind) == found) {*
-
return 1;*
-
}*
-
}*
-
else {*
-
found = 0;*
-
}*
-
index++;*
-
}*
-
return 0;*
}