« Polar Ignite 使用メモ | トップページ | HR sensor Logger »

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]

以上

|

« Polar Ignite 使用メモ | トップページ | HR sensor Logger »

脈拍計付き活動量計」カテゴリの記事

Web Bluetooth」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)




« Polar Ignite 使用メモ | トップページ | HR sensor Logger »