Salve a tutti sto provando a creare un semplice webserver con arduino uno + ethernet shield.
Il codice è questo:
#include <SPI.h>
#include <Ethernet.h>
// 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[] = { 10, 0, 0, 151 };
byte gateway[] = { 10, 0, 0, 1 };
byte netmask[] = { 255, 255, 255, 0 };
// 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()
{
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
Serial.println("Client connesso!\n");
//server.write("HTTP/1.1 200 OK");
//server.write("Content-Type: text/html");
//client.println();
//server.write("<center><h1>It Works!</h1></center>
");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<center><h1>It Works!</h1></center>
");
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
}
}
Mi connetto all’indirizzo 10.0.0.151 e l’output è quello dell’immagine allegata, ripetuto per un bel po’.
Inoltre il led L è sempre leggermente acceso
È un problema con il mio ethshield?