zoomkat. Thanks for your help but I'm getting nowhere. I've tried putting in just the code to turn the LED ON/OFF but it doesn't work and the serial monitor chucks out tons of stuff. I've been on this since 7am and it's now 10:45pm so here's my code:
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x11, 0xAC };
byte ip[] = { 192, 168, 1, 19 };
byte server[] = { 192,168,1,20 };
Client client(server, 80);
String readString = String(30); //string for fetching data from address
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
//pin mode
pinMode(7,OUTPUT); digitalWrite(7,LOW); // I use this pin as GND for the LED.
pinMode(8,OUTPUT); // Sample output, unable to use built-in LED at pin 13 because Ethernet Shield uses pins 10,11,12,13.
Serial.println("starting simple arduino client test");
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
//###########################################################
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString.concat(c);
Serial.println(readString);
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//Turn on LED
Serial.println(readString.substring(6,9));//for test to allow readString to be viewed
if(readString.substring(6,9)=="7=1") {//read the last 3 information characters from URL
// Serial.println(readString);
//set digital 7 HIGH
Serial.println("HIGH");
digitalWrite(7, HIGH); // set the LED on
readString="";//clear readString
}
if(readString.substring(6,9)=="7=0") {
//set digital 7 LOW
Serial.println("LOW");
digitalWrite(7, LOW); // set the LED OFF
readString="";//clear readString
}
}
//###########################################################
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================================");
Serial.println("");
client.stop();
// for(;;);
}
}
}
I'll have another go tomorrow perhaps!