Created
August 6, 2017 09:11
-
-
Save gishi-yama/8ed6435d79edd1f2409b109994d539fa to your computer and use it in GitHub Desktop.
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"> | |
<script type="text/javascript"> | |
"use strict"; | |
// ミリ秒を取得する | |
const getMilis = function() { | |
return new Date().getTime(); | |
} | |
// 心拍数を計算する(心拍合計/経過秒*60を小数点切り捨て) | |
const getHeartRate = function() { | |
let milis = getMilis() - initTime; | |
let rate = (beat / (milis / 1000.0)) * 60.0; | |
console.log(rate); | |
document.getElementById('rate').innerHTML = Math.floor(rate); | |
}; | |
// 起動時のタイムスタンプ | |
const initTime = getMilis(); | |
// 心拍合計 | |
var beat = 0; | |
// 繰り返し処理 | |
var interval = null; | |
// キー値 | |
const key = '****'; | |
// データをもらうためのWeb接続先 | |
const ws = new WebSocket('wss://us.wio.seeed.io/v1/node/event'); | |
window.onload = function() { | |
// Webに接続するための処理 | |
ws.onopen = function() { | |
ws.send(key); | |
document.getElementById('wait').style.display = 'none'; | |
}; | |
// Webからデータを取得できたときの処理 | |
ws.onmessage = function(evt) { | |
var json = JSON.parse(evt.data); | |
if (json.msg.input_rise) { | |
beat = beat + 1; | |
if (!interval) { | |
interval = setInterval(getHeartRate, 5000); | |
} | |
} | |
}; | |
} | |
</script> | |
</head> | |
<body> | |
<p id="wait"><strong>じゅんびちゅう...</strong></p> | |
<p>心拍数:<span id="rate">?</span></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment