Have a look at the code below, which is basically zoomkat's, to whom i am indebted. My page is publicly accessible here
The lines marked //<<<<<<<<<<<<<<<<<<<<<<<<<, put a hyperlink on the page. When you click, the href gets appended to the url. Then a bit further down, the incoming text (called readString) gets check for the incoming text, and then activates the Arduino pins accordingly.
Tip: don't have an href called just "on", since if your browser sends a GET for a favicon, the "on" in "favicon" will get found. That's why mine is "on8"
//zoomkat 4-1-12
//simple button GET
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//jim 7 dec with my details- ip address etc
// and added the lm35 rtc crap
#include <SPI.h>
#include <Ethernet.h>
#include <DS1302.h> //rtc henning karlsen
#define useLED
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
10, 0, 0, 200}; // ip in lan
byte gateway[] = {
10, 0, 0, 2 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(8085); //server port
String readString;
int ledPin = 8; //<<<<<<<<<<<<<< new
const int chipSelect = 4;
long rawVal;
long temp;
// Init the DS1302
DS1302 rtc(2, 3, 5); //was on 2 3 4 but 4 is for sd card
//////////////////////
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //pin selected to control
digitalWrite(ledPin, LOW); //<<<<<<<<<<<< new
// Set the clock to run-mode, and enable the write protection
rtc.halt(false);
rtc.writeProtect(true);
// to be safe, disabling SD explicitly
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
Serial.println("Server pin 8 test 1.1"); // so I can keep track of what is loaded
Serial.print("Server is at lan ip ");
Serial.println(Ethernet.localIP());
Serial.print("Local time ");
Serial.println(rtc.getTimeStr(FORMAT_LONG));
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
Serial.println(rtc.getTimeStr(FORMAT_LONG));
// read and calc the temp
rawVal=analogRead(5);//Connect LM35 on Analog 5
temp=(500 * rawVal) /1024;
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 600"); // refresh the page automatically every 10 mins
client.println();
client.println("<HTML>");
client.println("<HEAD>");
//client.println("<TITLE>ArduinoMation test page</TITLE>");
//display temp in browser tab
client.print("<title>");
client.print(rtc.getTimeStr(FORMAT_SHORT));
client.print(" ");
client.print(temp);
client.print("C");
client.println("</title>");
//client.println("<link href=\"jimza.ico\" rel=\"icon\" type=\"image/x-icon\" />");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Testing automation via web</H1>");
client.println("<H3>Thanks to Arduino forum guys for help</H1>");
#ifdef useLED
client.println("Click to <a href=\"/?on8\">turn led ON</a>"); // <<<<<<<<<<<<<<<<, hyperlink
client.println("
");
client.println("Click to <a href=\"/?off\">turn led OFF</a>"); //<<<<<<<<<<<<<<<, hyperlink
#endif
//client.println("
");
client.print("<H3>More development to follow once I learn more HTML, Javascript etc</H3>");
client.println("
");
client.print("Refreshes every 10 mins, or hit browser's refresh to update temp and time");
client.println("
");
client.println("
");
client.print("Temp, degrees C ");
client.print(temp);
client.println("
");
//client.print("Day ");
client.print(rtc.getDOWStr());
//client.println("
");
client.print(" ");
client.print(rtc.getTimeStr(FORMAT_LONG));
client.print(" SAST (UTC+2)");
client.println("
");
client.println("
");
client.println("
");
client.println("<H4>Hardware:</H4>");
//client.println("
");
//client.print("<a href=\"http://arduino.cc/en/Main/ArduinoBoardUnoArduino\">Arduino UNO</a>");
client.println("Arduino UNO");
client.println("
");
client.println("Ethernet shield (includes SD card slot)");
client.println("
");
client.print("LM35 analog temp sensor and DS1302 RTC with Henning Karlsen's library");
client.println("
");
client.println("<a href=\"http://www.w3schools.com/\">Visit W3Schools</a>");
//client.println("<a href=\"/http://www.w3schools.com/\">Visit W3Schools</a>");
#ifdef useFAV
//jim added this to try open favicon
if(readString.indexOf("jimza") >=0) {
File myFile = SD.open("jimza.ico");
if (myFile) {
while (myFile.available()) {
client.write(myFile.read());
}
myFile.close();
}
}
#endif
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
#ifdef useLED
///////////////////// control arduino pin
if(readString.indexOf("on8") >0)//<<<<<<<<<<<<<<<checks for on
{
digitalWrite(ledPin, HIGH); // set pin high
Serial.println("Led On");
}
if(readString.indexOf("off") >0)//<<<<<<<<<<<<<<<<<<<<checks for off
{
digitalWrite(ledPin, LOW); // set pin 5 low
Serial.println("Led Off");
}
//clearing string for next read
readString="";
#endif
}
}
}
}
}
EDIT.... huge electric storm here, so unplugging router, sorry! We live on top of a hill and the lightening here is quite fierce. So my site will be down....
AAAAAANDDDDD we're back