I added an updateLEDS routine to make the code easier to read. I also added the ability to specify an 'x' in your data file on the server to stop the arduino from polling the server.
boolean updateLEDS(char aChar)
{
boolean isDone = false;
switch (aChar) {
case 'a':
digitalWrite(2, HIGH);
break;
case 'b':
digitalWrite(3, HIGH);
break;
case 'c':
digitalWrite(4, HIGH);
break;
case 'd':
digitalWrite(5, HIGH);
break;
case 'e':
digitalWrite(6, HIGH);
break;
case 'x':
isDone = true;
break;
default:
// turn all the LEDs off:
for (int thisPin = 2; thisPin < 7; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
return isDone;
}
Replace the appropriate section of your code with the following. It will poll the data file on the server every 5 seconds. I verified this works and prints the appropriate character out from your server with my setup (atmega168 based).
Client client(server, 80);
Serial.println("connecting...");
boolean sessionDone = false;
boolean serverDone = false;
char c;
while ( !serverDone ) {
if (client.connect()) {
Serial.println("connected");
client.println("GET /~cameron5/test_etherent.html");
client.println();
while(!sessionDone && !serverDone){
if (client.available()) {
c = client.read();
serverDone = updateLEDS(c);
Serial.println("results:");
Serial.println(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
sessionDone = true;
}
} // while(!sessionDone)
} //if(client.connect())
else {
Serial.println("connection failed");
}
sessionDone = false;
delay(5000);
}