【发布时间】:2016-10-06 17:22:55
【问题描述】:
这是我的页面 HTML 代码。我在这里使用了 JQuery。 ESP8266 LED 控制
<!-- 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>
当我将我的 PC 连接到 ESP8266 的 wifi 时,我可以控制连接在其上的 LED。但我想通过互联网控制它。 ESP8266 模块已连接到我调制解调器的 wifi,但我不知道如何在 HTML 页面中的 $.get() 方法中写什么,以便通过网络将请求发送到 arduino。我试图将我的调制解调器的公共 IP 地址而不是 192.168.4.1(这是 ESP8266 的默认值)放入它没有工作。
【问题讨论】:
-
您需要配置调制解调器/路由器以将外部流量从端口 80(或最好使用不同的端口)传递到
192.168.4.1:80- 您如何执行此操作取决于调制解调器/路由器,并且对于堆栈溢出来说确实是题外话。但请在调制解调器/路由器的管理 Web 界面中查找“端口转发”或类似内容。 -
欢迎。我想也许它可能对其他人有用并且可以被认为是主题,所以我将其发布为答案。我会让其他人决定他们是否想把这个问题作为离题结束,但至少它对你有用:)
标签: jquery arduino-uno esp8266