Docs said "Note that because the W5100 and SD card share the SPI bus, only one can be active at a time. If you are using both peripherals in your program, this should be taken care of by the corresponding libraries. If you're not using one of the peripherals in your program, however, you'll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a high output."
As soon as EthernetClient client = server.available(); hits it does not work
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <DHT.h> // RHT03 Temperature Sensor
#define DHTPIN 2 // RHT03 data pin
#define DHTTYPE DHT22 // RHT03 acts like the DHT22
DHT dht(DHTPIN, DHTTYPE);
const int chipSelect = 4;
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xD9, 0x24 }; // MAC address
IPAddress ip(172,16,0, 65); // IP address
EthernetServer server(80);
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD Card...");
//pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
Serial.print("Initializing Temperature Sensor...");
dht.begin();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *F");
}
Serial.print("Initializing Ethernet Interface...");
Ethernet.begin(mac, ip);
server.begin();
Serial.print("IP:");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
String strClient; //Buffer to hold the string of text from the browser
String strClientCMDLine; //Holds the first line of text from the browser
String strClientCMD; //Holds the command sent from the browser
String strClientURI; //Holds the URI the browser sent
String strClientxx; //Just a temp buffer
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
strClient.concat(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) {
// Gets the first line of text from the browser (We don't need the rest at this time
strClientCMDLine = strClient.substring(0,strClient.indexOf('\r'));
strClientCMD = strClientCMDLine.substring(0,strClientCMDLine.indexOf(0x20)-1);
// send a standard http response to the browser and let it know you got the request.
client.println("HTTP/1.1 200 OK");
Serial.println(strClientCMD);
if (strClientCMD = "GET") {
strClientxx = strClientCMDLine.substring(strClientCMDLine.indexOf(0x20)+1);
strClientURI = strClientCMDLine.substring(strClientxx.charAt(0x20),strClientxx.charAt(0x20)-1);
Serial.println(strClientURI);
if (strClientURI = "/") {
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<html xmlns="http://www.w3.org/1999/xhtml\">");
client.println("");
client.println("");
client.println("Some Title");
client.println("");
client.println("");
client.println("<div id="container" style="width:1000px">");
client.println("xxx");
client.println("");
client.println("");
client.println("");
};
};
if (strClientCMD = "POST") {
};
if (strClientCMD = "HEAD") {
};
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;
}
}
}
}