Here is my HTML code for the page. I have used JQuery here. ESP8266 LED Control
<!-- in the <button> tags below the ID attribute is the value sent to the arduino -->
<button id="11" class="led">Toggle Pin 11</button> <!-- button for pin 11 -->
<button id="12" class="led">Toggle Pin 12</button> <!-- button for pin 12 -->
<button id="13" class="led">Toggle Pin 13</button> <!-- button for pin 13 -->
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".led").click(function(){
var p = $(this).attr('id'); // get id value (i.e. pin13, pin12, or pin11)
// send HTTP GET request to the IP address with the parameter "pin" and value "p", then execute the function
alert("Sending Get Request");
$.get("http://192.168.4.1:80/", {pin:p}); // execute get request
});
});
</script>
</body>
</html>
When I connect my PC to the wifi of ESP8266, I am able to control the LED connected on it. But I want to control it via Internet. ESP8266 module is connected to my modem's wifi, but I don't know what how to write in $.get()
method in HTML page so that request is sent to arduino through web. I tried to put public IP address of my modem instead of 192.168.4.1(which is default for ESP8266) it didn't work.
192.168.4.1:80
- how you do this will depend on the modem/router, and is really off-topic for stack overflow. But look for "port forwarding" or similar in your modem/router's admin web interface. – CupawnTae