Hmmmm well I’m pretty sure there’s a way round this, otherwise the Internet wouldn’t work.
I have a server running with the sketch below, although this phenomenon manifests with other similar sketches. It’s basically zk’s sketch with my network details and a bit of Serial.print-ing.
Browsers open on two laptops… click LED on from LaptopA, which sends the appropriate GET from the URL line and turns led on. Click it off from LaptopB which sends the appropriate GET and it goes off.
BUT… LaptopA leaves its GET in the URL line, so if the browser refreshes for whatever reason, it resends the on-switching GET and we get the LED coming on when it should be off.
//zoomkat 4-1-12
//simple button GET for led on pin 8
//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
#include <SPI.h>
#include <Ethernet.h>
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;
//////////////////////
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //pin selected to control
digitalWrite(ledPin, LOW);
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
Serial.print("Server established at ");
Serial.println(Ethernet.localIP());
//enable serial data print
Serial.println("server pin 8 test 1.1"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
Serial.println();
Serial.println("We have 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("Client request ended... here it is... ");
Serial.println(readString); //print to serial monitor for debuging
Serial.println("That was client request");
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino GET test page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Zoomkat's simple Arduino button ala Jim</H1>");
client.println("<a href=\"/?on8\">ON</a>");
client.println("<a href=\"/?off\">OFF</a>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("on8") >0)//checks for on
{
digitalWrite(ledPin, HIGH);
Serial.println();
Serial.println("Local message: Led On");
}
if(readString.indexOf("off") >0)//checks for off
{
digitalWrite(ledPin, LOW);
Serial.println();
Serial.println("Local message: Led Off");
}
//clearing string for next read
readString="";
}
}
}
}
}