how to avoid mistaken hyperlink execution from the browser ?

Hi ,

I have added a hyperlink on the webpage click which it executes the URL with ?waterPlant1 appended to it, shown below.

http://192.168.1.156:8025/?waterPlant1

but sometimes I might forget and if I reload the above URL along with loading the page it will also turn on the solenoid to water the plant.

is there a way we can remove this mistaken link execution from browser to avoid turning on solenoid ?

one way I can think of is if arduino replies browser with some message and browser shows a prompt saying “Water the plant” but I can’t think of a way how arduino can send reply back to browser. :confused:

I’m not sure if there is a way to stop this because of the way internet browsers work.

When you load your link, I presume your arduino reads the incoming “?waterPlant1” command and turns on the solenoid for a set time. If you reload the page, as far as your script is concerned, you are sending the command because you loaded the link.

Your suggestion of a “send and receive” connection is most likely a good way to fix this error.

I would suggest sending the request, then using a second link as confirmation. Eg, send “?waterPlant1”, then send “?waterPlant2”. This should stop you from accidentally activating it. Plus, by doing this, you won’t need the arduino to respond.

Also, could you please tell us how you have connected the arduino to the internet (Ethernet shield, Bluetooth module, WiFi module, etc). Without this information, it can get a little confusing later on if any other problems arise.

I hope this helps
PS I would advise against putting your IP on the forums.

seaurchin:
is there a way we can remove this mistaken link execution from browser to avoid turning on solenoid ?

After receiving and handling a HTTP GET request for http://192.168.1.156:8025/?waterPlant1
you could respond with a HTTP redirect response code 302 and redirect the browser to http://192.168.1.156:8025/

If you then reload the page, it will reload address http://192.168.1.156:8025/

jurs:
After receiving and handling a HTTP GET request for http://192.168.1.156:8025/?waterPlant1
you could respond with a HTTP redirect response code 302 and redirect the browser to http://192.168.1.156:8025/

If you then reload the page, it will reload address http://192.168.1.156:8025/

that is a good idea, however I have access to this page over the internet, so I guess I would need to put relative URL

if  util::StrContains(HTTP_req, "/?waterPlant1")) {
            client.println(F("Content-Type: text/html"));
            client.println("Access-Control-Allow-Origin: *");
            client.println(F("Connection: close")); 
            client.println();
            client.println(F("<!DOCTYPE HTML>"));
            client.println(F("<html><head><title>"));
            client.println(F("Welcome to Arduino WebServer</title>"));
            client.println("<meta http-equiv='refresh' content='1; url=192.168.1.156:8025/'>");

so if I have to put relative URL in place of this : 192.168.1.156:8025/ what would it be ? I have no index page its just Ethernet object rendering via client.print !

client.println("<meta http-equiv='refresh' content='0; url=../'>");

works perfect (y)