====== mbed HRM1017 ====== {{projects:20140618e.jpg?400}} ひょんなことから、発売前にmbed HRM1017を先行利用する機会に。 mbedほぼ初めて。(mbed LPC1114でLチカしたくらい。) Bluetooth初めて。もちろん、Bluetooth LEも初めてからの挑戦です~。 (MLN松岡) [[kb:mbed-ble:memo|日々のメモ]] ===== 注意事項 ===== *Nordic mkit向けのプログラムを流用するときは、クロックの設定を変更する必要があります。[[https://mbed.org/teams/Switch-Science/wiki/mbed-HRM1017をはじめよう#low-frequency-clock|参照]] *Nordic mkit用ライブラリは大きく2種類あります。 *{BLE_API_Native} *{BLE_API+nRF51822} <- こちらが最新 *mbed HRM1017用ライブラリに修正されたものはこちらです。 *{BLE_API_Native}->{BLE_API_Native_IRC} *{BLE_API+nRF51822}->なし(左記ライブラリがそのままmbed HRM1017で動くようになる予定) *{BLE_API_Native}と{BLE_API+nRF51822}はAPI非互換のため、ライブラリを切り替えた場合はプログラムの修正が必要です。 ===== BLE_Health_Thermometer_IRC ===== *{BLE_API_Native_IRC}を使った、Health Thermometerのプログラムです。 ==== デバイス名を設定するには? ==== ペアリング前に表示されるデバイス名は、AdvertiseにSHORTENED_LOCAL_NAMEを追加します。文字コードはUTF-8です。 const char* deviceName = "\xe3\x81\xa4\xe3\x81\xbcmbedHRM1017"; advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME, (uint8_t*)deviceName, strlen(deviceName)); {{wiki:20140618f.png?200}} ペアリング後に表示されるデバイス名は、nrf.init()後にsd_ble_gap_device_name_set()を追加します。 nrf.init(); const char* deviceName = "\xe3\x81\xa4\xe3\x81\xbcmbedHRM1017"; ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); sd_ble_gap_device_name_set(&sec_mode, (const uint8_t*)deviceName, strlen(deviceName)); {{kb:20140624a.png?200}} ==== Windowsとペアリングできるようにするには? ==== AdvertiseのDiscoverableを有効にします。 advData.addFlags((GapAdvertisingData::Flags)(GapAdvertisingData::LE_GENERAL_DISCOVERABLE | GapAdvertisingData::BREDR_NOT_SUPPORTED)); ===== Windowsアプリ ===== *Windowsは8以降でBluetooth LEに対応しています。 *Windows 8以降で、Bluetooth LE用のNative APIがあります。 *Windows 8.1以降で、Bluetooth LE用のWinRT APIがあります。 *[[https://github.com/matsujirushi/mjwinble|mjwinble]]では、開発利便性と知識継続の観点から、WindowsデスクトップアプリからWinRT APIを呼び出す方法を選択しています。 ==== Windows8と接続するには? ==== 1. ハードウェアがBluetooth LEに対応しているか確認します。(デバイス マネージャー で、Microsoft Bluetooth LE Enumeratorが表示されていれば、Bluetooth LEに対応しています。)\\ {{wiki:20140617c.png?200}} 2. mbed HRM1017をペアリングします。\\ チャーム > 設定 > PC設定の変更 > PCとデバイス > Bluetooth\\ > デバイスが表示されない場合は、mbed HRM1017のGapAdvertisingData::LE_GENERAL_DISCOVERABLEフラグがONしているか確認してください。 ==== Windows8でGATTを確認するには? ==== EG Bluetooth Smart Device GATT Profile Checker で確認できます。 1. ストアから、[[http://apps.microsoft.com/windows/ja-jp/app/eg-bluetooth-smart-gatt-profile/87207696-068a-410c-bfdd-a96f44d43b3f|EG Bluetooth Smart Device GATT Profile Checker]]をインストールします。\\ 2. EG Bluetooth Smart Device GATT Profile Checkerを起動します。\\ 3.Bluetooth SMART Devicesに表示されているデバイスを選択します。\\