mbed HRM1017 で Heart Rate Profile をサポートしてみる(1) [mbed]
mbed HRM1017 のサンプルプログラムはHealth Thermometer Profile (HTM) をサポートしています。
今回はサンプルプログラムを改造して Health Thermometer Profile の代わりに Heart Rate Profile をサポートしてみたいと思います。
その前に、BLEの基本プロトコルであるGATTプロファイルの構造について調べてみました。GATTプロファイルは大きく3つの情報から構成されています。
・デバイスが提供するサービス (Service)
・デバイスの持つ属性値 (Characteristic)
・デバイスの持つ属性 (Characteristic) への付加情報 (Descriptor)
出典: http://yegang.hatenablog.com/entry/2014/08/09/195246
GATTは、サービスとプロファイルが混在しており分かりにくいですが、どうも機器固有機能はプロファイルとサービスが定義され、機器によらない一般的な情報はサービスのみとなっているようです。
https://www.bluetooth.com/specifications/adopted-specifications
参考までに、GATTでサポートしているプロファイルの一覧を列挙しておきます。
出典:https://developer.bluetooth.org/gatt/profiles/Pages/ProfilesHome.aspx
BLEではホスト機能を持つ機器を "Central" と呼びデバイス機能を持つ機器を "Peripheral" と呼びます。(参考: http://yegang.hatenablog.com/entry/2014/07/19/224754 ) これらのプロファイル は Peripheral が持つ機能に相当します。
サンプルプログラムではどのように mbed HRM1017 へ Health Thermometer Profile を設定しているか抜粋し整理してみました。
Advertising は Central (スマホ)が Peripheral を見つけるためのプロトコルです。詳細について知りたい方はこちらのサイトが参考になると思います。
まぁ中身は詳しく分からなくとも、この流儀に従えば Heart Rate Profile の追加ができそうですね。
(^_^)/~
今回はサンプルプログラムを改造して Health Thermometer Profile の代わりに Heart Rate Profile をサポートしてみたいと思います。
その前に、BLEの基本プロトコルであるGATTプロファイルの構造について調べてみました。GATTプロファイルは大きく3つの情報から構成されています。
・デバイスが提供するサービス (Service)
・デバイスの持つ属性値 (Characteristic)
・デバイスの持つ属性 (Characteristic) への付加情報 (Descriptor)
出典: http://yegang.hatenablog.com/entry/2014/08/09/195246
GATTは、サービスとプロファイルが混在しており分かりにくいですが、どうも機器固有機能はプロファイルとサービスが定義され、機器によらない一般的な情報はサービスのみとなっているようです。
https://www.bluetooth.com/specifications/adopted-specifications
参考までに、GATTでサポートしているプロファイルの一覧を列挙しておきます。
Alert Notification | This profile enables a client device to receive different types of alerts and event information, as well as information on the count of new alerts and unread items, which exist in the server device. |
Blood Pressure | This profile enables a device to connect and interact with a Blood Pressure Sensor device for use in consumer and professional health care applications. |
Cycling Power | This profile enables a Collector device to connect and interact with a Cycling Power Sensor for use in sports and fitness applications. |
Cycling Speed and Cadence | This profile enables a Collector device to connect and interact with a Cycling Speed and Cadence Sensor for use in sports and fitness applications. |
Find Me | The Find Me profile defines the behavior when a button is pressed on one device to cause an alerting signal on a peer device. |
Glucose | This profile enables a device to connect and interact with a glucose sensor for use in consumer and professional healthcare applications. |
Health Thermometer | This profile enables a Collector device to connect and interact with a Thermometer sensor for use in healthcare applications. |
Heart Rate | This profile enables a Collector device to connect and interact with a Heart Rate Sensor for use in fitness applications. |
HID OVER GATT | This profile defines how a device with Bluetooth low energy wireless communications can support HID services over the Bluetooth low energy protocol stack using the Generic Attribute Profile. |
Location and Navigation | This profile enables a Collector device to connect and interact with a Location and Navigation Sensor for use in outdoor activity applications. |
Phone Alert Status | This profile enables a PUID device to alert its user about the alert status of a phone connected to the PUID device. |
Proximity | The Proximity profile enables proximity monitoring between two devices. |
Running Speed and Cadence | This profile enables a Collector device to connect and interact with a Runners Speed and Cadence Sensor for use in sports and fitness applications. |
Scan Parameters | This profile defines how a Scan Client device with Bluetooth low energy wireless communications can write its scanning behavior to a Scan Server, and how a Scan Server can request updates of a Scan Client scanning behavior. |
Time | The Time profile enables the device to get the date, time, time zone, and DST information and control the functions related the time. |
出典:https://developer.bluetooth.org/gatt/profiles/Pages/ProfilesHome.aspx
BLEではホスト機能を持つ機器を "Central" と呼びデバイス機能を持つ機器を "Peripheral" と呼びます。(参考: http://yegang.hatenablog.com/entry/2014/07/19/224754 ) これらのプロファイル は Peripheral が持つ機能に相当します。
サンプルプログラムではどのように mbed HRM1017 へ Health Thermometer Profile を設定しているか抜粋し整理してみました。
// Health Thermometer の Characteristics の定義 uint8_t thermTempPayload[5] = { 0, 0, 0, 0, 0 }; GattCharacteristic tempChar (GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, thermTempPayload, 5, 5, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE); GattCharacteristic *htmChars[] = {&tempChar, }; ... // Health Thermometer の Service の定義 GattService htmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, htmChars, sizeof(htmChars) / sizeof(GattCharacteristic *)); ... // サポートするサービス一覧 uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE, GattService::UUID_BATTERY_SERVICE}; ... // Advertising (サービスディスカバリー)のための設定 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ ble.gap().startAdvertising(); ... // サービスの登録 ble.gattServer().addService(htmService); ... //デバイス情報の Central (例えばスマホ)へ通知 ble.gattServer().write(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload));
Advertising は Central (スマホ)が Peripheral を見つけるためのプロトコルです。詳細について知りたい方はこちらのサイトが参考になると思います。
まぁ中身は詳しく分からなくとも、この流儀に従えば Heart Rate Profile の追加ができそうですね。
(^_^)/~
コメント 0