Created
September 7, 2017 03:42
-
-
Save gishi-yama/f2369363de772fe2b355817accacd394 to your computer and use it in GitHub Desktop.
WioNode実習の手本コード
This file contains 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"> | |
<script type="text/javascript"> | |
'use strict'; | |
window.onload = function() { | |
//URLとキー値(センサによって異なる) | |
var url = 'https://us.wio.seeed.io/v1/node/GroveUltraRangerD1/range_in_cm?access_token=xxxxx'; | |
// Webに接続するための処理 | |
var ok = function(response) { | |
return response.json(); | |
} | |
// Webから情報を取得できたときの処理 | |
var change = function(json) { | |
var kyori = json.range_cm; | |
document.getElementById('range').innerHTML = kyori; | |
} | |
// コンピュータからのデータ取得の依頼 | |
var fetching = function() { | |
fetch(url).then(ok).then(change); | |
} | |
// 最初に1回、データ取得の依頼 | |
fetching(); | |
// 以後、10秒ごとに、データ取得の依頼を繰り返す | |
setInterval(fetching, 10000); | |
} | |
</script> | |
</head> | |
<body> | |
<p>障害物までの距離は <span id="range">?</span> cmです。</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment