今回は、123D Circuits上に作成したArduino+ESP8266(WIFIモジュール)の仮想IoTデバイスを、ネットワーク経由で制御してみます。IoTプラットフォームには、dweet.ioを使います。
以下のHTMLを「led_dweet.htm」と名前を付けて保存してください。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>dweet test</title> | |
<script src="http://dweet.io/client/dweet.io.min.js"></script> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script> | |
$(function(){ | |
var thingName = "arduino-led-onoff"; //thing nameの設定 | |
// データの送信 | |
function publish(action) { | |
dweetio.dweet_for( | |
thingName, | |
{'action' : action}, | |
function(err, dweet){ | |
console.log(dweet.content); | |
} | |
); | |
} | |
// [ON]ボタンのクリックで文字列「on」を送信 | |
$('#on-button').click(function(){ | |
publish('on'); | |
}); | |
// [OFF]ボタンのクリックで文字列「off」を送信 | |
$('#off-button').click(function(){ | |
publish('off'); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<button id="on-button">ON</button> | |
<button id="off-button">OFF</button> | |
</body> | |
</html> |
「led_dweet.htm」をブラウザで開いて、[ON]ボタンを押すと、青LEDが点灯し、[OFF]ボタンをクリックすると、消灯します。
※LEDが点灯、消灯するまで、時間がかかる場合があります。
0 件のコメント:
コメントを投稿