Web Bluetooth

2019年11月24日 (日)

CSC sensor Logger

2019/11/24

Web-Bluetooth CSC sensor Logger

CSC(自転車)センサーのロガー

概要

chromeブラウザーでのWeb-Bluetoothを使用してCSC(Cycling Speed and Cadence/自転車)センサーのロガーを作った。(HTML+Javascriptでの実装)
なお、chromeのデフォルトで無効になっている機能なので、 以下のurlを入力して、フラグを有効にする必要がある。
chrome://flags/#enable-experimental-web-platform-features

Application URL

chromeで以下をクリックすると該当のアプリケーションが起動する。

CSC sensor Logger

動作した環境

(1)OS
・windows10
・ubuntu 18.04.1
・Android 9

(2)USB dongle
・PRINCETON PTM-UB17(PCの場合)

(3)CSC-sensor
・Duoband Speed & Cadence Sensor(Topeak)
・Bryton Cadence sensor

操作方法

1. ペアリング(ログ開始)

(1)起動画面の「[Pairing](click here)」をクリックするとペアリング設定画面がポップアップする。
(2)そのポップアップ画面から接続したいセンサー名を選択する。
(3)ペアリング後、データ取得を開始する。

2.画面表示の値の意味

・Cadence(rpm): センサーより取得したペダルの回転数(回転/分)
・Wheel(rpm): センサーより取得した車輪の回転数(回転/分)
・RunSpeed(km/h): ケイデンス・センサーを足首に付けた時のランニング速度(時速)
・Pace(min/km): ランニング速度をペースに変換した値(分/km)  // 止まった時などペースが計算できない場合、「99:99」で表示される。
・BikeSpeed(km/h): 自転車の速度

3.ログ保存(その1)

画面のログ表示領域の下にある[copy text to Paste buffer]を押すと、現在のログ情報がペーストバッファーにコピーされる。他のアプリを起動してペーストすることで、ログ情報を他のアプリに渡すことができる。ログ取得は継続するので、そこまでのスナップショットとなる。その2のやり方よりもファイルサイズの制限が大きい。

4.ログ保存(その2)

画面のログ表示領域の下にある[download]を押すと、現在のログ情報をファイルとして保存できる。。ログ取得は継続するので、そこまでのスナップショットとなる。

5.設定

・入力欄の「Step Length(m):」は、ケイデンス・センサーをランニング・ケイデンス・センサーとして使用する際に速度の計算に使用するための歩幅を設定する。
・入力欄の「Tire Circumference(mm):」 は自転車速度の計算に使用する自転車のタイヤ外周を設定する。

ログの出力例(Duoband Speed & Cadence Sensor の場合)

time,can,whe,runSpeed,bikeSpeed 2019/11/24 14:35:00,0,0,0.0,0.0 2019/11/24 14:35:01,0,0,0.0,0.0 2019/11/24 14:35:02,0,0,0.0,0.0 2019/11/24 14:35:03,0,0,0.0,0.0 2019/11/24 14:35:04,0,0,0.0,0.0 <省略> 2019/11/24 14:37:44,53,100,4.4,12.9 2019/11/24 14:37:45,0,101,0.0,13.0 2019/11/24 14:37:46,53,101,4.4,13.0 2019/11/24 14:37:48,53,103,4.5,13.2 2019/11/24 14:37:48,54,106,4.5,13.6 2019/11/24 14:37:49,55,107,4.6,13.8 2019/11/24 14:37:51,55,106,4.6,13.7 2019/11/24 14:37:51,55,105,4.7,13.5 2019/11/24 14:37:52,55,101,4.7,13.0

ランニング・ケイデンス・センサーとしての応用

加速度センサータイプのCadenceセンサーの場合、くるぶしにセンサーを裾バンドとかで固定して、ランニングすると、取り付けたセンサーからランニング・ケイデンスを取得することができる。

ログの出力例(Bryton Candence の場合)

ランニング・ケイデンスとしての使用例:

ime,can,whe,runSpeed,bikeSpeed 2019/11/24 18:33:59,0,0,0.0,0.0 2019/11/24 18:34:00,0,0,0.0,0.0 2019/11/24 18:34:01,50,0,4.2,0.0 2019/11/24 18:34:02,47,0,3.9,0.0 2019/11/24 18:34:03,42,0,3.6,0.0 2019/11/24 18:34:05,0,0,0.0,0.0 2019/11/24 18:34:05,39,0,3.3,0.0 2019/11/24 18:34:08,39,0,3.3,0.0 2019/11/24 18:34:08,0,0,0.0,0.0 2019/11/24 18:34:08,52,0,4.3,0.0 2019/11/24 18:34:09,38,0,3.2,0.0 2019/11/24 18:34:11,43,0,3.6,0.0 2019/11/24 18:34:11,46,0,3.8,0.0 2019/11/24 18:34:12,0,0,0.0,0.0 2019/11/24 18:34:14,47,0,3.9,0.0 2019/11/24 18:34:14,52,0,4.4,0.0 2019/11/24 18:34:15,52,0,4.3,0.0 2019/11/24 18:34:17,52,0,4.3,0.0 2019/11/24 18:34:18,50,0,4.2,0.0

参考URL

https://webbluetoothcg.github.io/demos/heart-rate-sensor/
https://googlechrome.github.io/samples/web-bluetooth/
Web-BluetoothでHRセンサーを接続する

以上

続きを読む "CSC sensor Logger"

| | コメント (0)

HR sensor Logger

2019/11/24

Web-Bluetooth HR sensor Logger

HR(心拍)センサーのロガー

概要

chromeブラウザーでのWeb-Bluetoothを使用してHRセンサーのロガーを作った。(HTML+Javascriptでの実装)
なお、chromeのデフォルトで無効になっている機能なので、 以下のurlを入力して、フラッグを有効にする必要がある。
chrome://flags/#enable-experimental-web-platform-features

Application URL

chromeで以下をクリックすると該当のアプリケーションが起動する。

HR sensor Logger

動作した環境

(1)OS
・windows10
・ubuntu 18.04.1
・Android 9

(2)USB dongle
・PRINCETON PTM-UB17(PCの場合)

(3)HR-sensor
・Polar H10
・Polar OH1
・Polar A370(HRセンサーモード)

操作方法

1. ペアリング(ログ開始)

(1)起動画面の「[Pairing](click here)」をクリックするとペアリング設定画面がポップアップする。
(2)そのポップアップ画面から接続したいセンサー名を選択する。
(3)ペアリング後、データ取得を開始する。

2.画面表示の値の意味

・HR(bpm): 心拍数(拍/分))
・R-R Interval(ms): RR間隔(ミリ秒)
・RRi Avg: RR間隔の平均値(設定されているサンプル数での平均)
・HRV(ms): RR間隔の平均値と現在のRR間隔の差分(絶対値)
「Polor H10」のようなチェストタイプでないと、「R-R Interval」は、取得できないので、 その場合、無意味の値が表示される、

3.ログ保存(その1)

画面のログ表示領域の下にある[copy text to Paste buffer]を押すと、現在のログ情報がペーストバッファーにコピーされる。他のアプリを起動してペーストすることで、ログ情報を他のアプリに渡すことができる。ログ取得は継続するので、そこまでのスナップショットとなる。その2のやり方よりもファイルサイズの制限が大きい。

4.ログ保存(その2)

画面のログ表示領域の下にある[download]を押すと、現在のログ情報をファイルとして保存できる。。ログ取得は継続するので、そこまでのスナップショットとなる。

5.設定

入力欄の「RRi Buffer Size(# of samples):」は、RR-Intervalの平均を取る際のサンプル数を定義する。(デフォルト値:60)

ログの出力例(Polar H10 の場合)

time,hr,HRV,RRi0,RRi1 2019/11/23 13:47:37,81,--,756,762 2019/11/23 13:47:38,81,--,774 2019/11/23 13:47:39,81,--,766 2019/11/23 13:47:40,81,--,759,737 2019/11/23 13:47:41,81,--,728 2019/11/23 13:47:42,82,--,713,696 2019/11/23 13:47:43,82,--,681 2019/11/23 13:47:44,84,--,692,675 <省略> 2019/11/23 13:48:35,77,--,823 2019/11/23 13:48:36,77,--,430 2019/11/23 13:48:37,77,466,1205 2019/11/23 13:48:38,76,62,803 2019/11/23 13:48:39,76,52,798,771 2019/11/23 13:48:40,77,22,770 2019/11/23 13:48:41,77,20,770 2019/11/23 13:48:43,78,19,773,778 2019/11/23 13:48:43,78,40,797 2019/11/23 13:48:44,78,37,796 2019/11/23 13:48:45,78,42,804 2019/11/23 13:48:46,78,52,818,808

概説:
最初にある「--」はRR-Intervalの平均値が確定するまでHRVが求まらないので、「--」が出力されている。その後に続くのは、センサーから読み取ったRR-Intaervalの値(ms)になる。通常1個であるが、場合によっては複数になsるようだ。

参考URL

https://webbluetoothcg.github.io/demos/heart-rate-sensor/
https://googlechrome.github.io/samples/web-bluetooth/
Web-BluetoothでHRセンサーを接続する
Heart rate variability
心拍変動と自律神経

以上

続きを読む "HR sensor Logger"

| | コメント (0)

2019年11月10日 (日)

Web-BluetoothでHRセンサーを接続する

2019/11/10p

Web-Bluetooth HR sensor

Web-BluetoothでHRセンサーを接続する

概要

いまさらだが、chromeブラウザーでWeb-Bluetoothを使用してHRセンサーを接続した。 使ってわかったことなどを記する。なお、chromeのデフォルトで無効になっている機能なので、 以下のurlを入力して、フラッグを有効にする必要がある。
chrome://flags/#enable-experimental-web-platform-features

動作した環境

(1)OS
windows10
ubuntu 18.04.1
Android 9

(2)USB dongle
PRINCETON PTM-UB17

(3)access URL
以下のURLにchormeでアクセスしてweb-bluetoothの機能を使用する。

https://github.com/WebBluetoothCG/demos/tree/gh-pages/heart-rate-sensor
画面の「GET」をクリックするとペアリング設定がポップアップして、そこでで希望のセンサーを選ぶ

https://googlechrome.github.io/samples/web-bluetooth/
画面に表示されている機能のリンクをクリックする

(4)download URL
https://github.com/WebBluetoothCG/demos/archive/gh-pages.zip
これを解凍してheart-sensorのディレクトリが該当する。

https://github.com/GoogleChrome/samples/archive/gh-pages.zip
これを解凍してweb-bluetoothのディレクトリが該当する。ただし、ローカルファイルで動作させるには修正が必要なようだ。

(5)備考#1
ネット情報をみると、セキュリティの考慮からhttps:通信とhttp://localhost通信での動作に限定されているとあるが、chromeの仕様が変更されたようで、最新版のchromeではローカルファイルのhtmlでも動作する。(ただし、PCのローカルファイルのみのようだ)

(6)備考#2
急に動作不正になることがある。この場合、PC電源をいったんオフにしてから起動すると復旧することがある。

(7)動作したHRセンサー
Polar H10
Polar OH1  (ただし、以下で記載したパッチが必要)
Polar A370(HRセンサーモード)  (以下で記載したパッチが必要)

パッチ(光学式センサーを使用できるようにする)

ダウンロードしたheart-sensorのなかにあるheartRateSensor.jsにパッチをあてる。(コメントアウトする) このパッチがあってもH10のようなチェストタイプのセンサーの動作に影響を与えない。

heartRateSensor.jsの21行目:

修正前: this._cacheCharacteristic(service, 'body_sensor_location'), 修正後: //this._cacheCharacteristic(service, 'body_sensor_location'),

R-R Intervalを表示するパッチ(H10のようなチェストタイプ限定)

ダウンロードしたheart-sensorのなかにあるapp.jsにパッチをあてる。
簡単なパッチなので、データが来ていない時は、'undefined'などが出る。

app.jsの21行目:

修正前: statusText.innerHTML = heartRateMeasurement.heartRate + ' &#x2764;' ; 修正後: statusText.innerHTML = heartRateMeasurement.heartRate + ' &#x2764;' + '<br>R-R Interval: ' + heartRateMeasurement.rrIntervals+'<br>';

仕様

ネット情報を見るとデータの第1番目のビットの意味が分かりにくいが、以下のソースにある仕様が分かりやすい。

https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/custom-hrm で公開しているソースから仕様部分を以下に抜粋した:

// b0は、LSB(最下位ビット)になる。 // Configure the Heart Rate Monitor service // See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.heart_rate.xml // Supported Characteristics: // Name UUID Requirement Properties // ---------------------------- ------ ----------- ---------- // Heart Rate Measurement 0x2A37 Mandatory Notify // Body Sensor Location 0x2A38 Optional Read // Heart Rate Control Point 0x2A39 Conditional Write <-- Not used here // Configure the Heart Rate Measurement characteristic // See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml // Permission = Notify // Min Len = 1 // Max Len = 8 // B0 = UINT8 - Flag (MANDATORY) // b5:7 = Reserved // b4 = RR-Internal (0 = Not present, 1 = Present) // b3 = Energy expended status (0 = Not present, 1 = Present) // b1:2 = Sensor contact status (0+1 = Not supported, 2 = Supported but contact not detected, 3 = Supported and detected) // b0 = Value format (0 = UINT8, 1 = UINT16) // B1 = UINT8 - 8-bit heart rate measurement value in BPM // B2:3 = UINT16 - 16-bit heart rate measurement value in BPM // B4:5 = UINT16 - Energy expended in joules # Energy expend は、運動のエネルギー消費量 になる // B6:7 = UINT16 - RR Internal (1/1024 second resolution) // Configure the Body Sensor Location characteristic // See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml // Permission = Read // Min Len = 1 // Max Len = 1 // B0 = UINT8 - Body Sensor Location // 0 = Other // 1 = Chest // 2 = Wrist // 3 = Finger // 4 = Hand // 5 = Ear Lobe // 6 = Foot // 7:255 = Reserved

OH1の動作例

https://googlechrome.github.io/samples/web-bluetooth/のアクセスした際の動作例を以下に表示する:

OH1の接続例: Web Bluetooth / Notifications Sample heart_rate|heart_rate_measurement|Start notifications|Stop notifications Live Output Requesting Bluetooth Device... Connecting to GATT Server... Getting Service... Getting Characteristic... > Notifications started > 0x00 0x3d > 0x00 0x3d > 0x00 0x3d > 0x00 0x3f > 0x00 0x3f > Notifications stopped
OH1の接続例: Web Bluetooth / Discover Services & Characteristics Sample heart_rate|Discover services & characteristics Live Output Requesting any Bluetooth Device... Connecting to GATT Server... Getting Services... Getting Characteristics... > Service: 0000180d-0000-1000-8000-00805f9b34fb >> Characteristic: 00002a37-0000-1000-8000-00805f9b34fb [NOTIFY] > Service: 0000180a-0000-1000-8000-00805f9b34fb >> Characteristic: 00002a29-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a24-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a27-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a26-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a28-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a23-0000-1000-8000-00805f9b34fb [READ]
OH1の接続例: Web Bluetooth / Device Information Characteristics Sample Get Bluetooth Device Information Characteristics Live Output Requesting any Bluetooth Device... Connecting to GATT Server... Getting Device Information Service... Getting Device Information Characteristics... > Manufacturer Name String: Polar Electro Oy > Model Number String: OH1 > Hardware Revision String: 00764348.03 > Firmware Revision String: 1.3.9 > Software Revision String: 2.0.11 > System ID: > Manufacturer Identifier: FFFE175E60 > Organizationally Unique Identifier: A09E1A

H10の動作例

https://googlechrome.github.io/samples/web-bluetooth/のアクセスした際の動作例を以下に表示する:

H10の接続例: Web Bluetooth / Notifications Sample heart_rate|heart_rate_measurement|Start notifications|Stop notifications Live Output Requesting Bluetooth Device... Connecting to GATT Server... Getting Service... Getting Characteristic... > Notifications started > 0x10 0x42 0x91 0x03 > 0x10 0x42 0xa5 0x03 > 0x10 0x42 0x8e 0x03 0x99 0x03 > 0x10 0x42 0xb0 0x03 > 0x10 0x42 0xa6 0x03 > 0x10 0x42 0xb4 0x03 > 0x10 0x42 0xc1 0x03 > 0x10 0x42 0xa8 0x03 > 0x10 0x42 0xa8 0x03 > 0x10 0x42 0xab 0x03 > 0x10 0x42 0x97 0x03 > 0x10 0x42 0x87 0x03 0x92 0x03 > 0x10 0x42 0x69 0x03 > 0x10 0x42 0x60 0x03 > 0x10 0x43 0x51 0x03 > 0x10 0x44 0x47 0x03 0x41 0x03 > 0x10 0x44 0x33 0x03 > 0x10 0x45 0x21 0x03 > 0x10 0x46 0x1e 0x03 > 0x10 0x47 0x1e 0x03 0x3a 0x03 > 0x10 0x48 0x46 0x03 > 0x10 0x48 0x42 0x03 > Notifications stopped # この場合、第3番目以降のデータは、R-R Intervalになる。
H10の接続例: Web Bluetooth / Device Information Characteristics Sample Get Bluetooth Device Information Characteristics Live Output Requesting any Bluetooth Device... Connecting to GATT Server... Getting Device Information Service... Getting Device Information Characteristics... > Manufacturer Name String: Polar Electro Oy > Model Number String: H10 > Hardware Revision String: 00760690.03 > Firmware Revision String: 5.0.0 > Software Revision String: 3.0.56 > System ID: > Manufacturer Identifier: FFFE31BFD7 > Organizationally Unique Identifier: A09E1A
H10の接続例: Web Bluetooth / Discover Services & Characteristics Sample heart_rate|Discover services & characteristics Live Output Requesting any Bluetooth Device... Connecting to GATT Server... Getting Services... Getting Characteristics... > Service: 0000180a-0000-1000-8000-00805f9b34fb >> Characteristic: 00002a29-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a24-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a27-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a26-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a28-0000-1000-8000-00805f9b34fb [READ] >> Characteristic: 00002a23-0000-1000-8000-00805f9b34fb [READ] > Service: 0000180d-0000-1000-8000-00805f9b34fb >> Characteristic: 00002a37-0000-1000-8000-00805f9b34fb [NOTIFY] >> Characteristic: 00002a38-0000-1000-8000-00805f9b34fb [READ]

以上

続きを読む "Web-BluetoothでHRセンサーを接続する"

| | コメント (0)