Salve a tutti,
piacere Mi chiamo Saverio e sono un appassionato di arduino. Sto cercando di domotizzare casa grazie ad arduino uno r3. Ho inserito anche un Ethernet Shild.
Ho creato un interfaccia html,css,js da inserire nel web server di arduino. I file saranno caricati su sd.
Non riesco a trovare il mio arduino inserendo l IP nel browser.
Vi indico il mio codice :
""`<#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0x32, 0x67, 0x48, 0x3c, 0xf7, 0xb1 };
IPAddress ip(192, 168, 1, 238);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(70);
void setup() {
Serial.begin(9600);
// Avvia l'Ethernet con IP statico
if (Ethernet.begin(mac) == 0) {
Serial.println("Errore nella configurazione Ethernet.");
while (true); // Blocca il codice qui
}
// Imposta manualmente l'indirizzo IP
Ethernet.begin(mac, ip, gateway, subnet);
// Inizializza il server
server.begin();
Serial.print("Server avviato. IP assegnato: ");
Serial.println(Ethernet.localIP());
// Inizializza la SD
if (!SD.begin(4)) {
Serial.println("Errore nella lettura della SD");
return;
}
Serial.println("SD inizializzata con successo");
}
void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("Nuovo client");
String request = "";
while (client.available()) {
char c = client.read();
request += c;
}
Serial.println(request);
// Carica e invia il file HTML
if (request.indexOf("GET / ") >= 0) {
File file = SD.open("index.html");
if (file) {
sendFile(file, "text/html");
file.close();
} else {
send404();
}
}
// Carica e invia il file CSS
else if (request.indexOf("GET /style.css") >= 0) {
File file = SD.open("style.css");
if (file) {
sendFile(file, "text/css");
file.close();
} else {
send404();
}
}
// Carica e invia il file JS
else if (request.indexOf("GET /script.js") >= 0) {
File file = SD.open("script.js");
if (file) {
sendFile(file, "application/javascript");
file.close();
} else {
send404();
}
}
else {
send404();
}
delay(1);
client.stop();
Serial.println("Client disconnesso");
}
}
void sendFile(File file, String contentType) {
EthernetClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: " + contentType);
client.println("Connection: close");
client.println();
while (file.available()) {
client.write(file.read());
}
}
void send404() {
EthernetClient client = server.available();
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("
404 Not Found
");}/>""
`
Il mio modem è un Hub di wind