Hallo
I am trying to make a simple webserver to my automatic curtain.
i got the webserver running, but i dont know how to make a button there stay at the same page..
Now i got a href
client.println("<a href="/?1on" target="inlineframe">ON");
that work okey, but look stubit.. So i want a button there do the same. I have try this
client.println("<input type="button" value="ON" onmousedown="location.href ('/?on');"/>");
When i click on the button i got redirectet to the page ( http://192.168.1.177/?on ), but when i click on the first href, i stay at the start page (http://192.168.1.177).
How do i get the botton to stay at the startpage and give me the "output" /?on like the href..
here is my code
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 177 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
void setup(){
pinMode(4, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("servertest1"); // 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
//now output HTML data header
if(readString.indexOf('?') >=0) { //don't send new page
client.println("HTTP/1.1 204 Zoomkat");
client.println();
client.println();
}
else {
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>Gardiner</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<input type=\"button\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"/>");
client.println("<H1>Hennings Gardiner</H1>");
client.println("<input type=\"button\" value=\"ON\" onmousedown=\"location.href ('/?on');\"/>");
client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>");
// client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
client.println("<IFRAME name=inlineframe style=\"display:none\" >");
client.println("</IFRAME>");
client.println("</BODY>");
client.println("</HTML>");
}
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("1on") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led On");
}
if(readString.indexOf("1off") >0)//checks for off
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println("Led Off");
}
if(readString.indexOf("2on") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led2 On");
}
if(readString.indexOf("2off") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led2 Off");
}
//clearing string for next read
readString="";
}
}
}
}
}