Oh I see thanks Peter, I was wondering where that was coming from but now understand!
I'm pretty sure I corrected it and changed to using if, else instead of if, else if
Just tried something else to see if it was something to do with the link - added another button that simply shows up to identify the state, both buttons exhibit the same behavior
//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//for use with W5100 based ethernet shields//note that the below bug fix may be required
//http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/step2/Connected/
// Google Code Archive - Long-term storage for Google Code Project Hosting.
//http://www.instructables.com/id/Arduino-Control-via-a-Web-Service-with-Teleduino/?ALLSTEPS
//http://www.christophercommunications.org/Web_page_based_control.html
//Define light output pins
int LightA = 6;
int LightB = 2;
int LightC = 3;
int LightD = 4;
//For holding pin state data
int LightAState = 0;
int LightBState = 0;
#include <SPI.h>
#include <Ethernet.h>
//#include <Servo.h>
//Servo myservo; // create servo object to control a servo
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 0, 177 }; // ip in lan
byte gateway[] = {
192, 168, 0, 1 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
void setup(){
//Set up outputs
pinMode(LightA, OUTPUT);
pinMode(LightB, OUTPUT);
pinMode(LightC, OUTPUT);
pinMode(LightD, OUTPUT);
//Start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
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
client.println(F("HTTP/1.1 200 OK")); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
//Write head data
client.println("");
client.println(" body { background-color:#303030; }"); //CSS style data
client.println("Home Automation"); //Page title
client.println("");
//Write body data
client.println("");
Home Automation
");//client.println("
");
client.println("
");
//Light A
//client.println("Light A: ");
//client.println("<a href="/?lightAon"">
");
//client.println("<a href="/?lightAoff"">
");
client.println("
");
if(LightAState == HIGH)
{
client.println("<a href="/?lightAoff"">
");
}
else
{
client.println("<a href="/?lightAon"">
");
}
if(LightAState == HIGH)
{
client.println("
");
}
else
{
client.println("
");
}
//Light B
//client.println("<a href="/?lightBon"">Turn On Light B");
//client.println("<a href="/?lightBoff"">Turn Off Light B
");
client.println("");
client.println("");
delay(1);
//stopping client
client.stop();
///////////////////// control Light A
if(readString.indexOf("?lightAon") >0)//checks for on
{
LightAState = HIGH;
digitalWrite(LightA, HIGH);
Serial.println("Light A On");
}
else if(readString.indexOf("?lightAoff") >0)//checks for off
{
LightAState = LOW;
digitalWrite(LightA, LOW);
Serial.println("Light A Off");
}
///////////////////// control Light B
if(readString.indexOf("?lightBon") >0)//checks for on
{
LightBState = HIGH;
digitalWrite(LightB, HIGH);
Serial.println("Light B On");
}
else if(readString.indexOf("?lightBoff") >0)//checks for off
{
LightBState = LOW;
digitalWrite(LightB, LOW);
Serial.println("Light B Off");
}
//clearing string for next read
readString="";
}
}
}
}
}