I’m adding my code also …:
/*
Arduino Ethernet Shield Prototyping,V2.0.
SPI.h, Ethernet2.h Library from Aruduino.cc
*/
#include <SPI.h>
#include <Ethernet.h>
EthernetServer server(80);// Server port
const byte auxPin = 8;// Select pin for Auxillary Power Gate
byte mac = { 0x90, 0xA2, 0xDA, 0x10, 0x65, 0xAE };// Physical MAC address
byte ip = { 192, 168, 6, 25 };// Fixed IP address
byte gateway = { 192, 168, 6, 254 };// Router Gateway Internet access
byte subnet = { 255, 255, 255, 0 };// Subnet mask */
String readString;
void setup()
{
delay(300);// Delay for Ethernet shield initialization (Arduino has 65mS Power Up delay and W5100 reset logic has 280mS)
pinMode(auxPin, OUTPUT);// Define pin for Auxillary Power as Output
Serial.begin(9600);// Initialize serial communications at 9600 bps
Serial.println(F(“Arduino UNO R3 with Ethernet Shiled W5100 - VU3GAO, for xxx”));// Display Arduino title
Ethernet.begin(mac,ip,gateway,subnet);// Start Ethernet
server.begin();
Serial.print(F("Ethernet Shield initialized. Local IP address is: "));
Serial.println(Ethernet.localIP());// Print Server IP address
}
void loop()
{
EthernetClient client = server.available();// Create a client connection
if (client)
{
while (client.connected())
{
if (client.available())
{
char c = client.read();// Read char by char HTTP request
if (readString.length() < 100)
{
readString = readString + c;// Store characters to string
}
if (c == ‘\n’)
{
Serial.println(readString);
client.println(F(“http/1.1 200 ok”));// Send standard http headers
client.println(F(“content-type: text/html”));
client.println();
client.println(F("<!doctype html>"));
client.println(F(""));
client.println(F(“Home Web Control”));
client.println(F(“
xxx Gate Control
”));
client.println(F(“
xxx
”));
client.println(F("
Click the Buttons to test the gate opening.
“));
client.print(F(”<input type=button value=‘Open Gate’ onmousedown=location.href=’/?AP_on’>"));
client.println(F("<input type=button value=‘Close Gate’ onmousedown=location.href=’/?AP_off’>
"));
client.println(F(""));
delay(1);// Page loading delay
client.stop();// Stopping client
if(readString.indexOf("/?AP_on") > 0) digitalWrite(auxPin, HIGH);// Switch on Auxillary Power
if(readString.indexOf("/?AP_off") > 0) digitalWrite(auxPin, LOW);// Switch off Auxillary Power
readString = “”;// Clearing string for next read
}// End of line reached
}// End of client available
}// End of client connected
}// End of client connection
}// End of loop