Salve a tutti, sono nuovo di Arduino.
Ecco quello che è successo con Arduino uno e ethernet shield.
Ho fatto l' upload dello sketch web server leggermente modificato e tutto andava come doveva andare.
Ho rifatto l' upload e il web server non mi ritornava nulla.
Per analizzare il tutto mi sono aiutato facendo delle stampe sul Serial Monitor e con un programma java. Il browser invia al web server Arduino una richiesta GET HTTP e questo dovrebbe leggere tutto il pacchetto, ma così non è...Riporto una parte di ciò che legge il web server (perchè legge infiniti caratteri strani, che io non gli invio):
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 177 };
byte gate[] = { 192, 168, 0, 1 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gate);
server.begin();
Serial.begin(9600);
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
client.print(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
I caratteri che ho riportato nel post precedente sono stati letti con un programma java che legge client.print(c); (infiniti caratteri). Strano no ?
Quando tutto funzionava, dalla seriale leggevo carattere per carattere ciò che il web server arduino riceveva dal client (browser). Il risultato era:
GET /path/file.html HTTP/1.0
From: *****
Adesso, dopo un upload del sw, quello che legge sono quei caratteri strani che ho postato. Ripeto ancora una volta che quei caratteri vengono letti in loop e non so proprio come sia possibile perche il browser fa una richiesta http (ed in quanto tale è finita). Mi sono spiegato bene ?
Dal programma java leggo i dati che il web server arduino mi invia tramite client.print(c); e non tramite la seriale. Ai pin 0 e 1 digitali non è collegato nulla. Il problema è che leggendo quegli strani caratteri (all'interno del metodo loop) il carattere letto c non arriva mai ad essere uguale a '\n' e quindi il server non invia risposta al browser... Potrebbe essere un malfunzionamento dell' ethernet shield ?
Documentandomi in rete ho scoperto che la versione 0022 dell' IDE Arduino ha dei bug nella libreria ehternet e credo anche uno nel compilatore. Passando su Windows tutto funziona Grazie del supporto