Ciao, ho un problema con la mia Ethernet Shield W5100 compatibile.
Infatti non funziona, quando tento di connettermi il mio browser mi da il seguente errore:
La pagina web non è disponibile
ERR_CONNECTION_TIMED_OUT
Il codice che ho usato è questo:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define maxLength 25
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5A, 0x82 };
byte ip[] = { 192, 168, 1, 89 };
File htmlFile;
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
if (!SD.begin(4)) {
Serial.println("Scheda SD non inserita correttamente, mi spengo...");
return;
}
pinMode(8, OUTPUT);
Serial.print("Server avviato su: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
char* file_to_load = "home.htm";
String inString = String(maxLength);
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
String richiesta;
if (client.available()) {
char c = client.read();
richiesta.concat(c);
Serial.println(richiesta);
if (inString.length() < maxLength) {
inString += c;
}
if (richiesta.indexOf("?led=on") > 0)
{
digitalWrite(8, HIGH);
}
if (richiesta.indexOf("?led=off") > 0)
{
digitalWrite(8, LOW);
}
if (c == '\n' && currentLineIsBlank) {
if (inString.indexOf(".htm") > -1) {
String new_file_load;
int rootIndex = inString.indexOf("/");
new_file_load = inString.substring((rootIndex+1), (rootIndex+13));
int endIndex = new_file_load.indexOf(" ");
if (endIndex > -1) {
new_file_load = new_file_load.substring(0, endIndex);
}
if (new_file_load != "") {
new_file_load.toCharArray(file_to_load,12);
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
read_file("home.htm", client);
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
void read_file( char* page_html, EthernetClient client )
{
htmlFile = SD.open( page_html );
if (htmlFile) {
while (htmlFile.available()) {
client.write(htmlFile.read());
}
// close the file:
htmlFile.close();
}
}
Quando tento di collegarmi i led RX e TX dello shield lampeggiano, quindi il segnale ci dovrebbe essere.