with this sketch I can connect into the html site on arduino
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xAC, 0x68 };
File htmlFile;
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
if(!Ethernet.begin(mac)) Serial.println("dhcp failed");
else {
Serial.print("IP is ");
Serial.println(Ethernet.localIP());
}
server.begin();
if (!SD.begin(4)) {
Serial.println("Errore nella inizializzazione della SD");
return; // init failed
}
}
void loop()
{
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
htmlFile = SD.open("home.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
client.print(c);
Serial.print(c);
}
// close the file:
htmlFile.close();
}else Serial.print(" Errore nella lettura file ");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}else Serial.print(" Client non accessibile ");
}
delay(1);
client.stop();
}
}
but with this i can't.
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xAC, 0x68 };
File htmlFile;
//creao un oggetto server che rimane in ascolto sulla porta
//specificata
EthernetServer server(80);
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9; // LED pin
String readString;
void setup()
{
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
Serial.begin(9600);
if(!Ethernet.begin(mac)) Serial.println("dhcp failed");
else {
Serial.print("IP is ");
Serial.println(Ethernet.localIP());
}
server.begin();
if (!SD.begin(4)) {
Serial.println("Errore nella inizializzazione della SD");
return; // init failed
}
}
void loop()
{
readString = "";
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100)
{
readString += c; //CONCATENA I CARATTERI
}
if (c == '\n') {
if(readString.indexOf("Luci") > 0){
//variabile per pagina html
String pagina = "";
//INIZIO pagina HTML
pagina = "<html><head><title> Luci Stanze </title></head><body>";
if(readString.indexOf("Luci1=1") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_cucina_on.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin6, HIGH);
}
else if (readString.indexOf("Luci2=1") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_salotto_on.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin7, HIGH);
}
else if (readString.indexOf("Luci3=1") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_bagno_on.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin8, HIGH);
}
else if (readString.indexOf("Luci4=1") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_letto_on.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin9, HIGH);
}
else if(readString.indexOf("Luci1=0") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_cucina_off.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin6, LOW);
}
else if (readString.indexOf("Luci2=0") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_salotto_off.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin7, LOW);
}
else if (readString.indexOf("Luci3=0") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_bagno_off.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin8, LOW);
}
else if (readString.indexOf("Luci4=0") > 0){
//PAGINA LUCI
htmlFile = SD.open("Luci_letto_off.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
pagina = pagina + c;
Serial.print(c);
}
// close the file:
htmlFile.close();
}
digitalWrite(ledPin9, LOW);
}
//FINE pagina HTML
pagina = pagina + "</body></html>";
Serial.print(pagina);
}
else{
//HOME PAGE
htmlFile = SD.open("home.htm",FILE_READ);
if (htmlFile) {
while (htmlFile.available()) {
char c = htmlFile.read();
client.print(c);
Serial.print(c);
}
// close the file:
htmlFile.close();
}else Serial.print(" Errore nella lettura file ");
break;
}
}
}else Serial.print(" Client non accessibile ");
}
delay(1);
client.stop();
}else Serial.print(" client ");
}
why?