Thanks for the replies lads, I'm gonna post some of my code here and if anybody can see any reasons why I can get this to work in my LAN but not through the internet please let me know. I could really do with the help!
#include <SPI.h>
#include <Ethernet.h>
// Enter MAC address and IP that is assigned to microcontroller
//In this case I used 192.168.1.4
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 4 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internal ip of my router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);
//Declare pins to be used as fixed integers;
int pin2 = 2;
String s = String(30); //string for fetching data from address
String cmd = "/X" ; //X is any variable of the command that will come after the ethernet address in the GET...
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.println(Ethernet.localIP());
Serial.println("Home Lighting Automation V1.0");
Serial.println("Ethernet Ready");
Serial.println("Server Ready");
//Set Arduino pins as outputs
pinMode(pin2, OUTPUT);
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("INCOMING REQUEST FROM CLIENT");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean DoPage=true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// 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
// Serial.write(c); // Remove (//) for debug! (prints incoming client, get, host, connection
//accept, user and all encoding)
if (s.length() < 7) { s.concat(c); } // build up a short string to parse
if(s.substring(0,3) == "GET" & DoPage){ // check for the GET from the web page
cmd=s.substring(4,6); // get the 2 letters in the string out and call this the CMD, /A, or /B or /H etc, these come in after the GET
// Serial.println("CMD="); // Remove (//) for debug!
//Serial.println(cmd); // Remove (//) for debug!
// Recieved a GET command from client,
//compare the received command to the specific command and then execute
if (cmd == "/A" && DoPage) {
Serial.println(F("Relay 1 Activated"));
digitalWrite(pin2, HIGH);
DoPage = false;
}
}
// 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) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connnection: close"));
client.println();
client.println(F("<!DOCTYPE HTML>"));
client.println(F("<html>"));
client.println(F("<head>"));
client.println(F("<meta content='text/html; charset=ISO-8859-1'http-equiv='content-type'>"));
client.println(F("<title>Home Lighting Automation"));
client.println(F("</title>"));
client.println("<font color='black'><h1 align=center>Home Automation V1.2</font></h1>");
client.println(F("</head>"));
// the next line sets the background color to something nice like blue
client.println(F("<body style='background-color:#58ACFA'>"));
// load in a background .jpg for the web page.
client.println(F("<BODY BACKGROUND='#CEECF5' style='width: 481px; height: 690px;'></span><br>"));
// set up some HTML that has buttons with specific actions that link back to the arduino at the
address of the arduino and have a specific string
client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.4/A\r'><INPUT TYPE='submit' VALUE='Light 1 On'></FORM> "));
client.println("</html>");
client.println("<br />");
client.println("<font color='black' size='3'>Copyright© 2012 Cathal Cavanagh, All Rights Reserved.</h1>");
client.println("<br />");
// Clear out the received string
s="";
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
client.stop();
Serial.println("Client finished sending request");
}
} // end