Hardware Reference
In-Depth Information
In setup() , replace the call to
sendFile() with this code to get an
IP address and start the server. New
lines are shown in blue.
8
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the relay output:
pinMode(relayPin, OUTPUT);
//see if the SD card is there:
Serial.print(F("Initializing SD card..."));
if (!SD.begin(sdChipSelect)) {
// if you can't read the SD card, print the error and go on:
Serial.println(F("initialization failed!"));
}
else {
Serial.println(F("initialization done."));
}
// give the Ethernet controller time to start:
delay(1000);
Serial.println(F("attempting to get address"));
// Attempt to start via DHCP. If not, do it manually:
if (!Ethernet.begin(mac)) {
Ethernet.begin(mac, ip, gateway, subnet);
}
// print IP address and start the server:
Serial.println(Ethernet.localIP());
server.begin();
}
The loop() will change quite a bit.
Starting at the beginning, add the
following local variables. The final one
listens for new clients to connect. If you
get a client, make an instance of the
TextFinder library to look for text in the
incoming stream from the client.
8
void loop() {
String fileName = ""; // filename the client requests
char inChar = 0; // incoming character from client
int requestType = 0; // what type of request (GET or POST);
int requestedFileLength = 0; // length of the filename they asked for
// listen for incoming clients:
Client client = server.available();
if (client) {
// make an instance of TextFinder to look for stuff from the client:
TextFinder finder(client );
 
Search WWH ::




Custom Search