I have a code that work in the version 22 of the IDE
this code will display a site with options to turn on/off outputs, and show values of analog sernsors =)
//*******************************
#include <SPI.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
**************************************************************
* Edited by Haavard GJ to work in version 0021 *
* Thanks to PaulS for the big help on getting this to work *
**************************************************************
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 2, 110 }; // ip in lan
byte gateway[] = { 192, 168, 2, 1 }; // the IP of the router or acsesspoint
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask (i dont think this is neccesary
Server server(80); // server port (change this if you are having a local webserver else than the arduino)
int ledPin = 4; // LED pin
int heatpin = 5; // Heating *relay* (change this if you want)
int lightpin = 6; // lights
int sensorPin = A0; // analog in 0 for testing
int sensorValue = 0; // integer for the analog sensor
String readString = String(30); // string for fetching data from address
boolean LEDON = false; // LED status flag
boolean HEATON = false; // Heat status flag (add more status flags if you need more outputs)
boolean LIGHTON = false; // lights *test*
void setup()
{
Serial.begin(57600); //enable serial datada print
Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
pinMode(ledPin, OUTPUT); //Set pin 4 to output
pinMode(heatpin, OUTPUT);
Serial.print("Starting server"); //for debugging
sensorValue = analogRead(sensorPin);
}
void loop(){
Client client = server.available(); // Create a client connection
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 30) { //read char by char HTTP request
readString.concat(c); } //store characters to string
Serial.print(c); //output chars to serial port for debugging
if (c == '\n') { //if HTTP request has ended
Serial.println("");
Serial.println(readString); // print for debugging
Serial.println("");
int Le = readString.indexOf("L="); // led here is a key component of where
int He = readString.indexOf("H="); // heat the status is being read by the arduino
int V = readString.indexOf("V"); // light
Serial.print("L= position: ");
Serial.println(Le);
Serial.print("H= position: ");
Serial.println(He);
Serial.print("V= position: ");
Serial.print(V);
//lets check if LED should be lighted
if (Le > 1){
if (readString.substring(Le,(Le+3)) == "L=1") { //led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
Serial.println("ledpin paa"); // debugging
LEDON = true;
}
if (readString.substring(Le,(Le+3))== "L=0") {
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF
Serial.println("ledpin av"); //debugging
LEDON = false;
}}
if (He > 1){
if (readString.substring(He,(He+3)) == "H=1") { //heat has to be turned ON
digitalWrite(heatpin, HIGH); // set the heat on
Serial.println("heatpin paa");//debug
HEATON = true;
}
if (readString.substring(He,(He+3)) == "H=0") {
//heat has to be turned OFF
digitalWrite(heatpin, LOW); // set the heat OFF
Serial.println("heatpin av"); //debug
HEATON = false;
}}
if (V > 1){
if (readString.substring(V,(V+3)) == "V=1") { //light has to be turned ON
digitalWrite(lightpin, HIGH); // set the heat on
Serial.println("lys paa pin 6");//debug
LIGHTON = true;
}
if (readString.substring(V,(V+3)) == "V=0") {
//light has to be turned OFF
digitalWrite(lightpin, LOW); // set the heat OFF
Serial.println("lys av"); //debug
LIGHTON = false;
}}
client.println("HTTP/1.1 200 OK"); //output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print ("<body style=background-color:white>"); //set background to white
// HTML Code
client.println("<font color=’red’><h1>Arduino Remote control</font></h1>");//send first heading
client.println("<font color=’blue’ size=’5′>Analog input 0: "); //print analog in to the browser
sensorValue = analogRead(sensorPin);
client.print(sensorValue);//Analog input.
Serial.print(sensorValue);
client.println("<br />");//some space between lines
//controlling led via checkbox
client.println("<h1>LED control</h1>");
// address will look like http://192.168.1.110/?L=1 when submited
// this line will give the radiobuttons that give the input
client.println("<form method=get name=LED> <input type='checkbox' name='L' value='1'>LED<br><br><input type='checkbox' name='H' value='1'>HEAT<br><br><input type='checkbox' name='V' value='1'>Light <br><input type=submit value=submit></form>");
client.println("<br />");
//printing LED status
client.print("<font size=’4′>LED status: ");
if (LEDON == true) {
client.println("<font color='green' size='4'>ON</font>");
Serial.print("led on pin 4");
}
else {
client.println("<font color='red' size='4'>OFF</font>");
Serial.println("Led off pin 4");
}
client.print("<br />");
//printing LED status
client.print("<font size=’4′>Heatpin status: ");
if (HEATON == true) {
client.println("<font color='green' size='4'>ON</font>");
Serial.print("Heat on pin 5");
}
else {
client.println("<font color='red' size='4'>OFF</font>");
Serial.println("Heat off pin 5");
}
client.print("<br />");
client.print("<font size=’4′>Light status: ");
if (LIGHTON == true) {
client.println("<font color='green' size='4'>ON</font>");
Serial.print("light on pin 6");
}
else {
client.println("<font color='red' size='4'>OFF</font>");
Serial.println("light off pin 6");
}
client.println("</body></html>");
readString=""; //clearing string for next read
client.stop(); //stopping client
Serial.println("stopped client"); // for debugging
}}}}}