【问题标题】:How to send data from web page to Arduino UNO via ESP8266 module?如何通过 ESP8266 模块将数据从网页发送到 Arduino UNO?
【发布时间】: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


【解决方案1】:

您需要将调制解调器/路由器配置为将外部流量从端口 80(或更好地使用不同的端口)传递到 192.168.4.1:80 - 具体操作方式取决于调制解调器/路由器。

在调制解调器/路由器的管理网络界面中查找“端口转发”或类似内容。

【讨论】:

    【解决方案2】:

    我刚刚使用了上面的按钮代码,我只需要将 esp8266 连接到实际的 wifi 网络(启用互联网)并知道它的 IP 地址(AT + CIFSR)。我的电脑上有一个网络服务器,我可以通过 esp 控制 arduino。 (我在换电器)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2021-11-26
      • 1970-01-01
      相关资源
      最近更新 更多