FRP: Functional reactive programming
BLEでペリフェラルを操作する
とりあえずAndroid DeveloperにあるBLEのサンプル(BluetoothLeGatt | Android Developers)をいじって、ペリフェラルのスキャン => 接続 => Characteristic の取得 => HRPで心拍数を取得する処理の流れはひととおりわかった(気がする)。
HRPは心拍数が変わったら通知するだけの単純なプロファイルらしく、あんまり応用がない。
というわけで Characteristic で read/writeしたいのだが、下記のサイトが参考になった。
BLEの拡張プロファイルについては下記が参考になりそう。
【BLEを使う】GATT(Generic Attribute Profile)概要 - 叶鋼は午前1時に計算をする
Android と BLESerial をつなげた例。サンプルコードあり。
浅草ギ研 ArduinoとAndroid端末をBLEでつないでみる
任意のcharacteristicのnotificationをenable/disableする疑似コード
BluetoothGattCharacteristic characteristic; // 任意のcharacteristic boolean enable; int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { // このcharacteristicは read に対応している enable = false; mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); mBluetoothGatt.readCharacteristic(characteristic); // このcharacteristicに対してreadのリクエストを送る // 非同期に BluetoothGattCallback#onCharacteristicRead(BluetoothGatt, BluetoothGattCharacteristic, int) がコールバックされる } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { // このcharacteristicは notification に対応している enable = true; mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // characteristicの設定を行うときに指定するUUIDは "00002902-0000-1000-8000-00805f9b34fb" の固定値 // 対向の BLE peripheral の notification 機能を有効化するため、この characteristic の descriptor に対して BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE を設定する mBluetoothGatt.writeDescriptor(descriptor); // 設定した descriptor を書き込む // 非同期に BluetoothGattCallback#onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic) がコールバックされる }
使っているAPI:
- boolean BluetoothGatt#setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable)
- BluetoothGattDescriptor BluetoothGattCharacteristic#getDescriptor(UUID uuid)
- characteristicの設定を行うときに指定するUUIDは "00002902-0000-1000-8000-00805f9b34fb" の固定値
- BluetoothGattDescriptor#setValue(byte[] bytes)
- BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE を設定
- BluetoothGatt#writeDescriptor(BluetoothGattDescriptor descriptor)
BLE peripheral へバイト列を書き込む模擬コード
byte[] bytes = { … }; // 書き込むバイト列 BluetoothGattService myService = mBluetoothGatt.getService(UUID.fromString("<Service UUID>")); BluetoothGattCharacteristic characteristic = myService.getCharacteristic(UUID.fromString("<Characteristic UUID>")); characteristic.setValue(bytes); mBluetoothGatt.writeCharacteristic(characteristic);
使っているAPI:
- BluetoothGattService BluetoothGatt#getService(UUID uuid)
- 引数は対向 BLE peripheral の Service UUID
- BluetoothGattCharacteristic BluetoothGattService#getCharacteristic(UUID uuid)
- 引数は対向 BLE peripheral の Service の Characteristic UUID
- BluetoothGattCharacteristic#setValue(byte[] bytes);
- 引数は書き込むバイト列
- boolean BluetoothGatt#writeCharacteristic(BluetoothGattCharacteristic characteristic)
- 引数は対向 BLE peripheral へ送信する Characteristic
BLEで何かつくる
BLEを使って何かつくれないか考えてみる。
ただBLEといっても漠然としすぎてるので、アイデア出しの下地として以下の構成を考えてみた。
- 各機器の構成
Raspberry Pi ではなく Arduino とBLE通信させる構成だとこんな感じ。
ちなみに、よくあるBeaconの構成はこんな感じで、スマホのアプリになにかアクションを起こさせるトリガとしてBLE(アドバタイズメント・チャネル)を使っている。
Beacon はアドバタイズメント・チャネルでID情報(UUID:会社ID, major:店舗)を一定時間ごとに送信する。スマホはID情報を受信すると、アプリを起動してアクションを起こす。
このアクションは、例えばWebサーバからメッセージを取得すること (いわゆるプッシュ通知) や、アプリ内ダイアログやビルトイン機能を表示することなど。
Beacon 自体は単にID情報をブロードキャストするだけなので、ボタン電池で数年稼動させることができる。
BLE: Bluetooth Low Energy
技術的な特徴はこんな感じ。
- BLE機器を低消費電力でつくれるため、ボタン電池で数年稼動
- 免許不要の2.4GHz帯を利用して、最大1Mbpsの通信が可能
- 通信距離は2.5mから50m
通信は2種類ある。
- 1対1通信
- Central (スマホなど) と Peripheral (BLE機器)の通信
- アドバタイズメント・チャネルによる通信
- Peripheral の発見と接続に使う
- データ・チャネルによる通信
- データ通信に使う
- 暗号化通信可
- N対1通信
- Broadcaster (BLE機器) と Observer (スマホなど) の通信
- アドバタイズメント・チャネルによる通信
- Broadcaster の発見と接続に使う
- 暗号化通信はできない
スマホ/タブレットの対応状況は、Android/iOS端末で下記の通り。
用途は下記がある。
参考
- Bluetooth Low Energy | Android Developers
- Androidとi beacon(ble)
- Bluetooth Low Energy(BLE)/ iBeaconとは - Qiita
- ワイヤレスジャパン2014:O2Oだけじゃない BLEを使った「Beacon」の可能性 - ITmedia Mobile
- ibeaconを試す色々な方法まとめ - Qiita
- いろいろとっ散らかってるBLE関連の情報のまとめ
- やはりお前らのAndroidのBLEが不安定だという認識は間違っている
- youten/ImmPeri · GitHub
- ImmPeri - BLE Immediate Alert Peripheral Example for iOS.
- IoTアプリをつくりたいと思ったあとにまず試すべきBLE開発Kitたち - Qiita
実装例
- 浅草ギ研 ArduinoとAndroid端末をBLEでつないでみる
- Android端末 <= BLE => BLESerial <= シリアル接続 => Auduino という感じでつなげる例
- Raspberry PiをBLE Peripheralとして動作させる
Cloudera Manager / CDH のメモ
Cloudera Manager 4
Cloudera Manager 5
Cloudera Manager 5 を消して 4 を入れ直すときの罠
Cloudera Manager 5 をアンインストールした後、Cloudera Manager 4を入れる場合は /var/cache/yum/x86_64/6/cloudera-manager 配下を消す必要があるみたいだ。
残っていると、Cloudera Manager 4のインストーラが5のパッケージを参照してエラーになるため。
sudo rm -rf /var/cache/yum/x86_64/6/cloudera-manager
また、各Agentホスト(Cloudera Manager Serverホストを除く)の /etc/yum.repos.d/cloudera-manager.repo が Cloudera Manager 5向けのものに変わっているので消す。
sudo rm /etc/yum.repos.d/cloudera-manager.repo sudo rm /etc/yum.repos.d/cloudera-cdh.repo
なんか、ほかにも消さなきゃならんかもしれん。
http://[cloudera manager host]:7180/ へアクセスした後、インストールウィザードの「クラスタインストール」の画面で真っ白になって操作不能になって困っていたが、原因はブラウザのキャッシュだった。
クリアしたら治った。。
罠大杉だろう。