これがページの 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()
て、要求が web 経由で arduino に送信されるかわかりません。192.168.4.1 (ESP8266 のデフォルト) の代わりにモデムのパブリック IP アドレスを入力しようとしましたが、うまくいきませんでした。