Problem with easy webserver for control of one digital port

I have project with easy digital output control via button :

client.println("");

client.println("");

IP adress is : IPAddress ip(10,20,90,66);

So when in Internet explorer I will insert 10.20.90.66 I can see two buttons for switching on and off.

My problem is, when I press button on, adress in internet explorer will change to http://10.20.90.66/?3=ON

and is readed by :

{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new 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 = readString + c;
// very simple but it works...
}
//Serial.write(c);
if (c == '\n') {
Serial.println(readString);
if(readString.indexOf("3=ON") > -1) {
digitalWrite(Pin3, HIGH);
.
.
.

Complete program is working, but what I do no like, that adress will remain http://10.20.90.66/?3=ON and button isn't pressed.

What I want to switch adress back to http://10.20.90.66/ when button isn't pressed or use other system how to share information between webserver and arduino without usage of internet explorer adress.

Sorry for my English and thanks for help

Alda

The easiest to implement is to just send an HTTP redirect if some command was received. This way you always have your "nice" URL in the browsers address line.

A bit more work would be to change your whole code to send the control messages not by reloading the page with GET parameters but by sending AJAX requests by using JavaScript. For this solution you probably have to read a lot about JavaScript and especially about the ways of sending background requests to the server (XmlHttpRequest is a keyword for that area).

Ok, thanks. As a first step I will do HTTP redirect. Do you know which instruction I must send ?

Thanks

Alda

Wikipedia has your answer:

I tried this :

if(readString.indexOf("3=ON") > -1) {
digitalWrite(Pin3, HIGH);
Serial.println("Pin 3 is ON");
Pin3ON = true;
client.println("");
client.println("");
client.println("");
}

but it's not the right way how to send send redirect instruction.

Alda

Have you read the article I linked? There is a description which HTTP headers your have to send. You're currently not even sending a header, so you don't do HTTP but HTML 1.0 over telnet.