2
votes

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.

2
You'll need to configure your modem/router to pass external traffic from port 80 (or better to use a different port) to 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
welcome. I guess maybe it might be useful to others and could be considered on-topic, so I've posted it as an answer. I'll let others decide if they want to close the question as off-topic, but at least it's working for you :)CupawnTae

2 Answers

0
votes

You'll need to configure your modem/router to pass external traffic from port 80 (or better to use a different port) to 192.168.4.1:80 - how you do this will depend on the modem/router.

Look for "port forwarding" or similar in your modem/router's admin web interface.

0
votes

i have just used the button code above, i only had to get the esp8266 connected to an actual wifi network (internet enabled) and know its IP address (AT + CIFSR). I have a webserver on my PC and i can control the arduino via the esp. (i'm switching appliances)