I have below function using which I can water the pot over the internet, however when I am at home I can use http://192.168.1.156:8025/?waterPlant1
instead of http://www.example.com:8025/?waterPlant1
. Secondly going by second link it takes time sometimes to turn on valve. So is there any way I can auto detect if I have success with http://192.168.1.156:8025/?waterPlant1
I continue use that URL else use http://www.example.com:8025/?waterPlant1
. which would mean like I am not on same network or I am not at home.
function waterPlant1() {
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://www.example.com:8025/?waterPlant1");
ifrm.setAttribute("id", "iframe");
ifrm.style.visibility = "false";
ifrm.style.display = "none";
document.body.appendChild(ifrm);
}
<button onclick="waterPlant1()">Water the Plant</button>